action.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. name: 'Build Kernel'
  2. description: 'Builds kernel using legacy build.sh or Bazel (kleaf)'
  3. runs:
  4. using: composite
  5. steps:
  6. - name: 'Setup ccache and Build Environment'
  7. shell: bash
  8. working-directory: ${{ github.workspace }}
  9. run: |
  10. set -euo pipefail
  11. # Download and install ccache
  12. echo "Installing ccache..."
  13. 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; }
  14. sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
  15. sudo chmod +x /usr/bin/ccache
  16. rm -f ./ccache
  17. # Verify ccache
  18. if ! /usr/bin/ccache --version > /dev/null 2>&1; then
  19. echo "❌ ccache installation failed or binary is corrupted"
  20. exit 1
  21. fi
  22. echo "✅ ccache binary verified: $(/usr/bin/ccache --version | head -1)"
  23. # Setup cache directories
  24. export CCACHE_DIR="$GITHUB_WORKSPACE/kernel/common/.ccache"
  25. export LDCACHE_DIR="$GITHUB_WORKSPACE/kernel/common/.ld_cache"
  26. mkdir -p "$CCACHE_DIR" "$LDCACHE_DIR"
  27. # Create LD wrapper for thin-LTO caching
  28. cat > "$GITHUB_WORKSPACE/kernel/common/ld-wrapper" << 'EOF'
  29. #!/bin/bash
  30. ld.lld "$@" --thinlto-cache-dir="$LDCACHE_DIR" --thinlto-jobs="$(nproc --all)"
  31. EOF
  32. chmod +x "$GITHUB_WORKSPACE/kernel/common/ld-wrapper"
  33. # Setup ccache compiler wrappers in PATH (masquerade method)
  34. # This intercepts compiler invocations regardless of how the build system calls them
  35. mkdir -p "$GITHUB_WORKSPACE/ccache-bin"
  36. cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/clang"
  37. cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/clang++"
  38. cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/gcc"
  39. cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/g++"
  40. cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/ld.lld"
  41. chmod +x "$GITHUB_WORKSPACE/ccache-bin"/*
  42. # Export environment variables for subsequent steps
  43. echo "CCACHE_DIR=$CCACHE_DIR" >> $GITHUB_ENV
  44. echo "LDCACHE_DIR=$LDCACHE_DIR" >> $GITHUB_ENV
  45. echo "PATH=$GITHUB_WORKSPACE/ccache-bin:$PATH" >> $GITHUB_ENV
  46. echo "CC=clang" >> $GITHUB_ENV
  47. echo "CXX=clang++" >> $GITHUB_ENV
  48. echo "HOSTCC=clang" >> $GITHUB_ENV
  49. echo "HOSTCXX=clang++" >> $GITHUB_ENV
  50. echo "LD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> $GITHUB_ENV
  51. echo "HOSTLD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> $GITHUB_ENV
  52. echo "CLANG_PREBUILT_BIN=$GITHUB_WORKSPACE/ccache-bin" >> $GITHUB_ENV
  53. # Initialize ccache
  54. ccache -M 100G
  55. ccache -p
  56. ccache -s
  57. ccache -z
  58. echo "✅ Build environment ready"
  59. echo " CCACHE_DIR: $CCACHE_DIR"
  60. echo " LDCACHE_DIR: $LDCACHE_DIR"
  61. echo " Compiler wrappers: $GITHUB_WORKSPACE/ccache-bin"
  62. - name: 'Build Kernel'
  63. shell: bash
  64. working-directory: ${{ github.workspace }}/kernel
  65. run: |
  66. set -euo pipefail
  67. echo "🔍 Debug: Current environment"
  68. echo " PATH: $PATH"
  69. echo " CC: ${CC:-unset}"
  70. echo " CXX: ${CXX:-unset}"
  71. echo " CLANG_PREBUILT_BIN: ${CLANG_PREBUILT_BIN:-unset}"
  72. echo " CCACHE_DIR: ${CCACHE_DIR:-unset}"
  73. echo " ccache-bin exists: $([ -d $GITHUB_WORKSPACE/ccache-bin ] && echo 'YES' || echo 'NO')"
  74. echo " ccache-bin/clang: $([ -f $GITHUB_WORKSPACE/ccache-bin/clang ] && echo 'YES' || echo 'NO')"
  75. echo " which clang: $(which clang || echo 'NOT IN PATH')"
  76. echo ""
  77. # Source the build config to see what values it uses
  78. echo "🔍 Debug: Checking build.config values (before build)..."
  79. if [ -f "common/build.config.gki.aarch64" ]; then
  80. echo " Found build.config.gki.aarch64:"
  81. grep -i "CLANG_PREBUILT_BIN\|CC\|CXX" common/build.config.gki.aarch64 | head -20 || echo " (no compiler config found)"
  82. fi
  83. echo ""
  84. if [ -f "build/build.sh" ]; then
  85. SKIP_MRPROPER=1 \
  86. LTO=thin \
  87. SKIP_VENDOR_BOOT=1 \
  88. SKIP_EXT_MODULES=1 \
  89. SKIP_CP_KERNEL_HDR=1 \
  90. GKI_DEFCONFIG_FRAGMENT="$GITHUB_WORKSPACE/wild_gki.fragment" \
  91. BUILD_CONFIG=common/build.config.gki.aarch64 \
  92. build/build.sh -j"$(nproc)"
  93. else
  94. cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
  95. 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
  96. fi
  97. - name: 'Report Cache Sizes'
  98. shell: bash
  99. working-directory: ${{ github.workspace }}/kernel/common
  100. run: |
  101. set -euo pipefail
  102. echo "📊 Cache sizes after build:"
  103. echo " CCACHE usage:"
  104. du -sh "$CCACHE_DIR" || echo " (no ccache directory)"
  105. echo " LDCACHE usage:"
  106. du -sh "$LDCACHE_DIR" || echo " (no ldcache directory)"
  107. echo "Perform cache eviction!"
  108. # 3h = 10800s using seconds to support older ccache
  109. ccache --evict-older-than 10800s