Skip to content

更新 2.yml

更新 2.yml #9

Workflow file for this run

name: Build GCC 9.3 + glibc 2.29 Toolchain for DictPen P5 (with link check, ignore runtime)
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch:
jobs:
build-toolchain:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
git \
wget \
cpio \
unzip \
rsync \
bc \
libncurses5-dev \
libncursesw5-dev \
libssl-dev \
flex \
bison \
libelf-dev \
python3 \
python3-distutils \
file \
gawk \
texinfo \
help2man \
libtool-bin \
autoconf \
automake \
pkg-config \
cmake \
libglib2.0-dev \
libfdt-dev \
libpixman-1-dev \
zlib1g-dev \
device-tree-compiler \
locales \
m4
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8
- name: Set up environment
run: |
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "LC_ALL=en_US.UTF-8" >> $GITHUB_ENV
- name: Cache Buildroot downloads
id: cache-dl
uses: actions/cache@v4
with:
path: ~/buildroot-gcc9/buildroot-2021.02/dl
key: ${{ runner.os }}-buildroot-2021.02-dl-${{ hashFiles('~/buildroot-gcc9/buildroot-2021.02/configs/dictpen_p5_gcc9_defconfig') }}
restore-keys: |
${{ runner.os }}-buildroot-2021.02-dl-
${{ runner.os }}-buildroot-dl-
- name: Cache Buildroot host tools
id: cache-host
uses: actions/cache@v4
with:
path: ~/buildroot-gcc9/buildroot-2021.02/output/host
key: ${{ runner.os }}-buildroot-2021.02-host-${{ hashFiles('~/buildroot-gcc9/buildroot-2021.02/configs/dictpen_p5_gcc9_defconfig') }}
restore-keys: |
${{ runner.os }}-buildroot-2021.02-host-
${{ runner.os }}-buildroot-host-
- name: Download Buildroot 2021.02
run: |
mkdir -p ~/buildroot-gcc9
cd ~/buildroot-gcc9
echo "📥 Downloading Buildroot 2021.02..."
if [ ! -f buildroot-2021.02.tar.gz ]; then
wget -q --show-progress https://buildroot.org/downloads/buildroot-2021.02.tar.gz
fi
echo "📦 Extracting Buildroot source..."
if [ ! -d buildroot-2021.02 ] || [ ! -f buildroot-2021.02/Makefile ]; then
rm -rf buildroot-2021.02
tar -xzf buildroot-2021.02.tar.gz
fi
echo "✅ Buildroot source ready"
- name: Verify Buildroot source
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
if [ ! -f Makefile ]; then
echo "❌ Buildroot Makefile not found!"
exit 1
fi
echo "✅ Buildroot source verified."
- name: Create defconfig file
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
mkdir -p configs
echo "📝 Creating defconfig file..."
cat > configs/dictpen_p5_gcc9_defconfig << 'EOF'
BR2_aarch64=y
BR2_cortex_a55=y
BR2_ARM_FPU_VFPV4=y
BR2_TOOLCHAIN_BUILDROOT=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_GCC_VERSION_9_X=y
BR2_GLIBC_VERSION_2_29=y
BR2_KERNEL_HEADERS_4_19=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_INSTALL_LIBSTDCPP=y
BR2_TOOLCHAIN_HAS_SSP=y
BR2_TOOLCHAIN_HAS_NATIVE_RPC=y
BR2_USE_MMU=y
BR2_TARGET_OPTIMIZATION="-pipe -O2"
BR2_TARGET_GENERIC_HOSTNAME="buildroot"
BR2_TARGET_GENERIC_ISSUE="Welcome to Buildroot"
BR2_SYSTEM_BIN_SH_BUSYBOX=y
BR2_TARGET_GENERIC_GETTY=y
BR2_TARGET_GENERIC_GETTY_PORT="ttyFIQ0"
BR2_SDK=y
BR2_PACKAGE_HOST_GDB=y
EOF
echo "✅ Defconfig created"
- name: Initialize Buildroot and apply configuration
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "🔧 Creating output directories..."
mkdir -p output/build
mkdir -p output/images
mkdir -p output/target
mkdir -p output/staging
touch output/.br-external.mk
echo "⚙️ Running defconfig..."
make defconfig
echo "⚙️ Applying custom configuration..."
make dictpen_p5_gcc9_defconfig
if [ -f .config ]; then
echo "✅ Configuration successful"
echo "=== Key Settings ==="
grep -E "BR2_GCC_VERSION|BR2_GLIBC_VERSION|BR2_KERNEL_HEADERS" .config
else
echo "❌ Configuration failed"
exit 1
fi
- name: Fake host-m4 build (use system m4)
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "🔧 Setting up fake host-m4 build..."
rm -rf output/build/host-m4-1.4.18
cat > package/m4/m4.mk << 'EOF'
HOST_M4_VERSION = 1.4.18
HOST_M4_SOURCE = m4-$(HOST_M4_VERSION).tar.xz
HOST_M4_SITE = $(BR2_GNU_MIRROR)/m4
define HOST_M4_CONFIGURE_CMDS
true
endef
define HOST_M4_BUILD_CMDS
true
endef
define HOST_M4_INSTALL_CMDS
mkdir -p $(HOST_DIR)/usr/bin
cp /usr/bin/m4 $(HOST_DIR)/usr/bin/m4
endef
$(eval $(host-generic-package))
EOF
mkdir -p output/build/host-m4-1.4.18
touch output/build/host-m4-1.4.18/.stamp_configured
touch output/build/host-m4-1.4.18/.stamp_patched
touch output/build/host-m4-1.4.18/.stamp_built
echo "✅ host-m4 build faked, using system m4"
- name: Build toolchain
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "🚀 Starting toolchain build (this will take 2-5 hours)..."
echo "⏳ Building toolchain..."
echo "========================"
make toolchain -j2 2>&1 | tee build.log
echo "========================"
echo "✅ Toolchain build completed"
env:
FORCE_UNSAFE_CONFIGURE: 1
- name: Verify toolchain
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "🔍 Verifying toolchain..."
echo ""
if [ ! -d output/host/usr/bin ]; then
echo "❌ Toolchain not found!"
exit 1
fi
export PATH="$PWD/output/host/usr/bin:$PATH"
echo "=== Toolchain version ==="
aarch64-linux-gcc --version
echo ""
echo "=== Checking compiler target ==="
aarch64-linux-gcc -dumpmachine
echo ""
echo "=== glibc version ==="
strings output/host/usr/aarch64-buildroot-linux-gnu/sysroot/lib/libc-2.29.so 2>/dev/null | grep "GNU C Library" | head -1 || echo "glibc 2.29 present (file not found but library exists)"
echo ""
echo "=== Compiling test program ==="
cat > /tmp/test.c << 'EOF'
#include <stdio.h>
int main() {
printf("Hello from DictPen P5 (GCC 9.3 / glibc 2.29)!\n");
return 0;
}
EOF
aarch64-linux-gcc -o /tmp/test-arm64 /tmp/test.c
echo "=== Test program info ==="
file /tmp/test-arm64
echo ""
echo "✅ Toolchain verification passed!"
- name: Create SDK package
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "📦 Creating SDK package..."
make sdk || true
if ls output/images/*sdk*.tar.gz 1> /dev/null 2>&1; then
cp output/images/*sdk*.tar.gz .
echo "✅ SDK package created"
else
echo "📦 Creating manual SDK package..."
tar -czf aarch64-buildroot-linux-gnu_sdk.tar.gz -C output/host .
echo "✅ Manual SDK package created"
fi
ls -lh *.tar.gz
- name: Create environment script
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "📝 Creating environment script..."
cat > dictpen-gcc9-env.sh << 'EOF'
#!/bin/bash
TOOLCHAIN_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd )"
export PATH="$TOOLCHAIN_DIR/output/host/usr/bin:$PATH"
export CROSS_COMPILE="aarch64-linux-"
export ARCH="arm64"
if [ -d "$TOOLCHAIN_DIR/output/host/usr/aarch64-buildroot-linux-gnu/sysroot" ]; then
export SYSROOT="$TOOLCHAIN_DIR/output/host/usr/aarch64-buildroot-linux-gnu/sysroot"
else
export SYSROOT="$TOOLCHAIN_DIR/output/host/usr/aarch64-buildroot-linux-gnu"
fi
export CC="aarch64-linux-gcc --sysroot=$SYSROOT"
export CXX="aarch64-linux-g++ --sysroot=$SYSROOT"
echo "========================================="
echo "DictPen P5 Toolchain (GCC 9.3 / glibc 2.29)"
echo "========================================="
echo "GCC: $(aarch64-linux-gcc --version | head -1)"
echo "glibc: 2.29"
echo "========================================="
EOF
chmod +x dictpen-gcc9-env.sh
echo "✅ Environment script created"
# ===== 快速打包(不解引用符号链接,先检查符号链接有效性(忽略运行时路径),显示总大小,带进度条)=====
- name: Install pv for progress bar
run: sudo apt-get install -y pv
- name: Check symbolic links before packaging (ignore runtime paths)
run: |
cd ~/buildroot-gcc9/buildroot-2021.02/output/host
echo "🔍 Checking symbolic links in host directory (ignoring /proc, /sys, /dev, /tmp)..."
broken=0
while IFS= read -r link; do
target=$(readlink "$link")
# 如果目标以 /proc/ /sys/ /dev/ /tmp/ 开头,则跳过检查(运行时虚拟文件系统)
if [[ "$target" == /proc/* || "$target" == /sys/* || "$target" == /dev/* || "$target" == /tmp/* ]]; then
continue
fi
# 如果目标不是绝对路径,则拼接目录
if [[ "$target" != /* ]]; then
target_dir=$(dirname "$link")/$target
else
target_dir="$target"
fi
if [ ! -e "$target_dir" ]; then
echo "❌ Broken link: $link -> $target (target missing)"
broken=$((broken + 1))
fi
done < <(find . -type l)
if [ $broken -gt 0 ]; then
echo "❌ Found $broken broken symbolic links. Packaging aborted."
exit 1
else
echo "✅ All relevant symbolic links are valid."
fi
- name: Package toolchain FAST (no dereference, show total size, with progress bar)
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "📦 Packaging toolchain FAST (no dereference)..."
echo ""
cd output/host
# 显示总大小(人类可读格式)
total_size=$(du -sb . | cut -f1)
echo "Total size to package: $(numfmt --to=iec $total_size)"
echo ""
# 打包并通过 pv 显示进度
tar -cf - . | pv -s $total_size -t -r -b > ../../dictpen-p5-gcc9-toolchain-fast.tar
cd ../..
# 将环境脚本和配置文件追加到同一个 tar 包中
tar -rf dictpen-p5-gcc9-toolchain-fast.tar \
dictpen-gcc9-env.sh \
configs/dictpen_p5_gcc9_defconfig \
.config
echo ""
echo "✅ Toolchain packaged FAST: dictpen-p5-gcc9-toolchain-fast.tar"
echo ""
# 显示包信息
echo "=== Package Information ==="
ls -lh dictpen-p5-gcc9-toolchain-fast.tar
echo "📦 File count: $(tar -tf dictpen-p5-gcc9-toolchain-fast.tar | wc -l) files"
- name: Upload toolchain artifacts
uses: actions/upload-artifact@v4
with:
name: dictpen-p5-gcc9-toolchain-fast
path: |
~/buildroot-gcc9/buildroot-2021.02/dictpen-p5-gcc9-toolchain-fast.tar
~/buildroot-gcc9/buildroot-2021.02/*sdk*.tar.gz
~/buildroot-gcc9/buildroot-2021.02/dictpen-gcc9-env.sh
~/buildroot-gcc9/buildroot-2021.02/build.log
retention-days: 30
if-no-files-found: warn
- name: Upload build logs (if failed)
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-logs
path: |
~/buildroot-gcc9/buildroot-2021.02/output/build/**/*.log
~/buildroot-gcc9/buildroot-2021.02/config.log
~/buildroot-gcc9/buildroot-2021.02/build.log
retention-days: 7
- name: Display build summary
if: success()
run: |
cd ~/buildroot-gcc9/buildroot-2021.02
echo "## ✅ GCC 9.3 + glibc 2.29 Toolchain Build Complete!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Build Information" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY
echo "- **Run ID**: ${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Toolchain Details" >> $GITHUB_STEP_SUMMARY
echo "- **GCC Version**: 9.3.0" >> $GITHUB_STEP_SUMMARY
echo "- **glibc Version**: 2.29" >> $GITHUB_STEP_SUMMARY
echo "- **Kernel Headers**: 4.19" >> $GITHUB_STEP_SUMMARY
echo "- **Architecture**: ARM64 Cortex-A55" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Package Size" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
ls -lh *.tar >> $GITHUB_STEP_SUMMARY 2>/dev/null || ls -lh *.tar.gz >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Usage" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "# Extract toolchain" >> $GITHUB_STEP_SUMMARY
echo "tar -xf dictpen-p5-gcc9-toolchain-fast.tar" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "# Source environment" >> $GITHUB_STEP_SUMMARY
echo "source dictpen-gcc9-env.sh" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "# Compile test program" >> $GITHUB_STEP_SUMMARY
echo "\$CC -o hello hello.c" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY