action.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. name: 'Build Kernel'
  2. description: 'Builds kernel using legacy build.sh or Bazel (kleaf)'
  3. runs:
  4. using: composite
  5. steps:
  6. - shell: bash
  7. working-directory: ${{ github.workspace }}/kernel
  8. run: |
  9. set -euo pipefail
  10. # Install ccache with ECS by cctv18
  11. echo "Install ccache with ECS"
  12. 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; }
  13. sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
  14. sudo chmod +x /usr/bin/ccache
  15. rm -f ./ccache
  16. # Verify ccache is actually installed and works
  17. if ! /usr/bin/ccache --version > /dev/null 2>&1; then
  18. echo "❌ ccache installation failed or binary is corrupted"
  19. exit 1
  20. fi
  21. echo "✅ ccache binary verified: $(/usr/bin/ccache --version | head -1)"
  22. # Replace compiler binaries with ccache to force usage regardless of how build system invokes them
  23. # Rename real compilers first
  24. sudo mv /usr/bin/clang /usr/bin/clang.real
  25. sudo mv /usr/bin/clang++ /usr/bin/clang++.real
  26. sudo mv /usr/bin/gcc /usr/bin/gcc.real
  27. sudo mv /usr/bin/g++ /usr/bin/g++.real
  28. # Create ccache wrapper scripts that call the real compiler through ccache
  29. for compiler in clang clang++ gcc g++; do
  30. sudo tee /usr/bin/$compiler > /dev/null <<'EOF'
  31. #!/bin/bash
  32. exec /usr/bin/ccache /usr/bin/${0##*/}.real "$@"
  33. EOF
  34. sudo chmod +x /usr/bin/$compiler
  35. done
  36. echo "✅ Compilers replaced with ccache wrappers"
  37. export CCACHE_DIR="$GITHUB_WORKSPACE/kernel/.ccache"
  38. export LDCACHE_DIR="$GITHUB_WORKSPACE/kernel/.ld_cache"
  39. export CC="clang"
  40. export CXX="clang++"
  41. export HOSTCC="clang"
  42. export HOSTCXX="clang++"
  43. export CCACHE_MAXSIZE=10G
  44. export CCACHE_COMPILERCHECK=content
  45. export CCACHE_BASEDIR="$GITHUB_WORKSPACE/kernel"
  46. export CCACHE_NOHASHDIR=true
  47. export CCACHE_COMPRESSION=true
  48. export CCACHE_COMPRESSION_LEVEL=3
  49. export CCACHE_DIRECT=true
  50. export CCACHE_FILE_CLONE=true
  51. export CCACHE_INODE_CACHE=true
  52. export CCACHE_IS_KERNEL_COMPILING=true
  53. export CCACHE_UMASK=002
  54. export CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
  55. if /usr/bin/ccache --help 2>&1 | grep -q 'depend_mode'; then
  56. export CCACHE_DEPEND=true
  57. fi
  58. echo "✅ ccache environment variables set"
  59. echo " CC: $CC"
  60. echo " CXX: $CXX"
  61. echo "📁 Cache directories:"
  62. echo " CCACHE_DIR: $CCACHE_DIR"
  63. echo " LDCACHE_DIR: $LDCACHE_DIR"
  64. mkdir -p "$CCACHE_DIR" "$LDCACHE_DIR"
  65. /usr/bin/ccache -p
  66. echo "Testing ccache invocation..."
  67. if ! command -v clang > /dev/null; then
  68. echo "❌ clang not found in PATH"
  69. exit 1
  70. fi
  71. echo "✅ clang resolves to: $(command -v clang)"
  72. echo " Verified as: $(file $(command -v clang))"
  73. if [ -f "build/build.sh" ]; then
  74. echo "🔨 Building with legacy build.sh (LTO caching to $LDCACHE_DIR)"
  75. mkdir -p "$LDCACHE_DIR"
  76. # Monitor ccache during build
  77. /usr/bin/ccache -z # Reset stats
  78. 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
  79. echo "📊 ccache stats after build:"
  80. /usr/bin/ccache -s || true
  81. else
  82. echo "🔨 Building with Bazel/kleaf (LTO caching to $LDCACHE_DIR)"
  83. mkdir -p "$LDCACHE_DIR"
  84. cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
  85. /usr/bin/ccache -z # Reset stats
  86. 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
  87. echo "📊 ccache stats after build:"
  88. /usr/bin/ccache -s || true
  89. fi
  90. echo "📊 Cache sizes after build:"
  91. echo " CCACHE usage:"
  92. du -sh "$CCACHE_DIR" || echo " (no ccache directory)"
  93. echo " LDCACHE usage:"
  94. du -sh "$LDCACHE_DIR" || echo " (no ldcache directory)"
  95. echo "Perform cache eviction!"
  96. # 3h = 10800s using seconds to support older ccache
  97. ccache --evict-older-than 10800s