| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- name: 'Build Kernel'
- description: 'Builds kernel using legacy build.sh or Bazel (kleaf)'
- runs:
- using: composite
- steps:
- - shell: bash
- working-directory: ${{ github.workspace }}/kernel
- run: |
- set -euo pipefail
- # Install ccache with ECS by cctv18
- echo "Install ccache with ECS"
- 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 is actually installed and works
- 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)"
-
- # Replace compiler binaries with ccache to force usage regardless of how build system invokes them
- # Rename real compilers first
- sudo mv /usr/bin/clang /usr/bin/clang.real
- sudo mv /usr/bin/clang++ /usr/bin/clang++.real
- sudo mv /usr/bin/gcc /usr/bin/gcc.real
- sudo mv /usr/bin/g++ /usr/bin/g++.real
-
- # Create ccache wrapper scripts that call the real compiler through ccache
- for compiler in clang clang++ gcc g++; do
- sudo tee /usr/bin/$compiler > /dev/null <<'EOF'
- #!/bin/bash
- exec /usr/bin/ccache /usr/bin/${0##*/}.real "$@"
- EOF
- sudo chmod +x /usr/bin/$compiler
- done
- echo "✅ Compilers replaced with ccache wrappers"
-
- export CCACHE_DIR="$GITHUB_WORKSPACE/kernel/.ccache"
- export LDCACHE_DIR="$GITHUB_WORKSPACE/kernel/.ld_cache"
- export CC="clang"
- export CXX="clang++"
- export HOSTCC="clang"
- export HOSTCXX="clang++"
- export CCACHE_MAXSIZE=10G
- export CCACHE_COMPILERCHECK=content
- export CCACHE_BASEDIR="$GITHUB_WORKSPACE/kernel"
- export CCACHE_NOHASHDIR=true
- export CCACHE_COMPRESSION=true
- export CCACHE_COMPRESSION_LEVEL=3
- export CCACHE_DIRECT=true
- export CCACHE_FILE_CLONE=true
- export CCACHE_INODE_CACHE=true
- export CCACHE_IS_KERNEL_COMPILING=true
- export CCACHE_UMASK=002
- export CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
- if /usr/bin/ccache --help 2>&1 | grep -q 'depend_mode'; then
- export CCACHE_DEPEND=true
- fi
- echo "✅ ccache environment variables set"
- echo " CC: $CC"
- echo " CXX: $CXX"
- echo "📁 Cache directories:"
- echo " CCACHE_DIR: $CCACHE_DIR"
- echo " LDCACHE_DIR: $LDCACHE_DIR"
- mkdir -p "$CCACHE_DIR" "$LDCACHE_DIR"
- /usr/bin/ccache -p
- echo "Testing ccache invocation..."
- if ! command -v clang > /dev/null; then
- echo "❌ clang not found in PATH"
- exit 1
- fi
- echo "✅ clang resolves to: $(command -v clang)"
- echo " Verified as: $(file $(command -v clang))"
- if [ -f "build/build.sh" ]; then
- echo "🔨 Building with legacy build.sh (LTO caching to $LDCACHE_DIR)"
- mkdir -p "$LDCACHE_DIR"
- # Monitor ccache during build
- /usr/bin/ccache -z # Reset stats
- 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 CC="$CC" CXX="$CXX" LDCACHE_DIR="$LDCACHE_DIR" build/build.sh
- echo "📊 ccache stats after build:"
- /usr/bin/ccache -s || true
- else
- echo "🔨 Building with Bazel/kleaf (LTO caching to $LDCACHE_DIR)"
- mkdir -p "$LDCACHE_DIR"
- cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
- /usr/bin/ccache -z # Reset stats
- 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
- echo "📊 ccache stats after build:"
- /usr/bin/ccache -s || true
- fi
-
- 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
|