| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- name: 'Build Kernel'
- description: 'Builds kernel using legacy build.sh or Bazel (kleaf)'
- runs:
- using: composite
- steps:
- - name: 'Setup ccache and Build Environment'
- shell: bash
- working-directory: ${{ github.workspace }}
- run: |
- set -euo pipefail
-
- # Download and install ccache
- echo "Installing ccache..."
- curl -LfsS --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 30 --tcp-fastopen -H "User-Agent: Mozilla/5.0" "https://github.com/WildKernels/kernel_patches/raw/refs/heads/main/ccache/ccache-x86-64" -o ccache || { echo "❌ Failed to download ccache"; exit 1; }
- sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
- sudo chmod +x /usr/bin/ccache
- rm -f ./ccache
-
- # Verify ccache
- if ! /usr/bin/ccache --version > /dev/null 2>&1; then
- echo "❌ ccache installation failed or binary is corrupted"
- exit 1
- fi
- echo "✅ ccache binary verified: $(/usr/bin/ccache --version | head -1)"
-
- # Setup cache directories
- export CCACHE_DIR="$GITHUB_WORKSPACE/kernel/common/.ccache"
- export LDCACHE_DIR="$GITHUB_WORKSPACE/kernel/common/.ld_cache"
- mkdir -p "$CCACHE_DIR" "$LDCACHE_DIR"
-
- # Create LD wrapper for thin-LTO caching
- cat > "$GITHUB_WORKSPACE/kernel/common/ld-wrapper" << 'EOF'
- #!/bin/bash
- ld.lld "$@" --thinlto-cache-dir="$LDCACHE_DIR" --thinlto-jobs="$(nproc --all)"
- EOF
- chmod +x "$GITHUB_WORKSPACE/kernel/common/ld-wrapper"
- # Setup ccache compiler wrappers in PATH (masquerade method)
- # This intercepts compiler invocations regardless of how the build system calls them
- mkdir -p "$GITHUB_WORKSPACE/ccache-bin"
- cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/clang"
- cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/clang++"
- cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/gcc"
- cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/g++"
- cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/ld.lld"
- chmod +x "$GITHUB_WORKSPACE/ccache-bin"/*
-
- # Export environment variables for subsequent steps
- echo "CCACHE_DIR=$CCACHE_DIR" >> $GITHUB_ENV
- echo "LDCACHE_DIR=$LDCACHE_DIR" >> $GITHUB_ENV
- echo "PATH=$GITHUB_WORKSPACE/ccache-bin:$PATH" >> $GITHUB_ENV
- echo "CC=clang" >> $GITHUB_ENV
- echo "CXX=clang++" >> $GITHUB_ENV
- echo "HOSTCC=clang" >> $GITHUB_ENV
- echo "HOSTCXX=clang++" >> $GITHUB_ENV
- echo "LD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> $GITHUB_ENV
- echo "HOSTLD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> $GITHUB_ENV
- echo "CLANG_PREBUILT_BIN=$GITHUB_WORKSPACE/ccache-bin" >> $GITHUB_ENV
-
- # Initialize ccache
- ccache -M 100G
- ccache -p
- ccache -s
- ccache -z
-
- echo "✅ Build environment ready"
- echo " CCACHE_DIR: $CCACHE_DIR"
- echo " LDCACHE_DIR: $LDCACHE_DIR"
- echo " Compiler wrappers: $GITHUB_WORKSPACE/ccache-bin"
- - name: 'Build Kernel'
- shell: bash
- working-directory: ${{ github.workspace }}/kernel
- run: |
- set -euo pipefail
- echo "🔍 Debug: Current environment"
- echo " PATH: $PATH"
- echo " CC: ${CC:-unset}"
- echo " CXX: ${CXX:-unset}"
- echo " CLANG_PREBUILT_BIN: ${CLANG_PREBUILT_BIN:-unset}"
- echo " CCACHE_DIR: ${CCACHE_DIR:-unset}"
- echo " ccache-bin exists: $([ -d $GITHUB_WORKSPACE/ccache-bin ] && echo 'YES' || echo 'NO')"
- echo " ccache-bin/clang: $([ -f $GITHUB_WORKSPACE/ccache-bin/clang ] && echo 'YES' || echo 'NO')"
- echo " which clang: $(which clang || echo 'NOT IN PATH')"
- echo ""
-
- # Source the build config to see what values it uses
- echo "🔍 Debug: Checking build.config values (before build)..."
- if [ -f "common/build.config.gki.aarch64" ]; then
- echo " Found build.config.gki.aarch64:"
- grep -i "CLANG_PREBUILT_BIN\|CC\|CXX" common/build.config.gki.aarch64 | head -20 || echo " (no compiler config found)"
- fi
- echo ""
-
- if [ -f "build/build.sh" ]; then
- SKIP_MRPROPER=1 \
- LTO=thin \
- SKIP_VENDOR_BOOT=1 \
- SKIP_EXT_MODULES=1 \
- SKIP_CP_KERNEL_HDR=1 \
- GKI_DEFCONFIG_FRAGMENT="$GITHUB_WORKSPACE/wild_gki.fragment" \
- BUILD_CONFIG=common/build.config.gki.aarch64 \
- build/build.sh -j"$(nproc)"
- else
- cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
- tools/bazel build --config=release --notrim --defconfig_fragment=//common:arch/arm64/configs/wild_gki.fragment --disk_cache=$LDCACHE_DIR --cache_dir=$GITHUB_WORKSPACE/kernel/.cache/bazel //common:kernel_aarch64
- fi
-
- - name: 'Report Cache Sizes'
- shell: bash
- working-directory: ${{ github.workspace }}/kernel/common
- run: |
- set -euo pipefail
- echo "📊 Cache sizes after build:"
- echo " CCACHE usage:"
- du -sh "$CCACHE_DIR" || echo " (no ccache directory)"
- echo " LDCACHE usage:"
- du -sh "$LDCACHE_DIR" || echo " (no ldcache directory)"
-
- echo "Perform cache eviction!"
- # 3h = 10800s using seconds to support older ccache
- ccache --evict-older-than 10800s
|