build.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. name: Kernel Build Process
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. kernel_version:
  9. required: true
  10. type: string
  11. variant:
  12. required: false
  13. type: string
  14. feature_set:
  15. required: true
  16. type: string
  17. use_repo:
  18. required: false
  19. type: boolean
  20. jobs:
  21. build-gki:
  22. name: "${{ inputs.kernel_version }} (${{ inputs.variant }})"
  23. runs-on: ubuntu-latest
  24. timeout-minutes: 60
  25. steps:
  26. - name: Checkout Repository
  27. uses: actions/checkout@v5
  28. - name: Parse kernel version
  29. id: parse
  30. uses: ./.github/actions/parse-kernel-version
  31. with:
  32. kernel_version: ${{ inputs.kernel_version }}
  33. - name: Free Disk Space
  34. if: true
  35. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  36. with:
  37. remove_android: true
  38. remove_dotnet: true
  39. remove_haskell: true
  40. remove_tool_cache: true
  41. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  42. remove_packages_one_command: true
  43. remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle"
  44. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  45. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  46. testing: false
  47. - name: Setup more Swap (for LTO)
  48. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  49. with:
  50. swap-size-gb: 10 # 10-24 GB is common for heavy LTO
  51. # swap-space-path: /mnt/swapfile # optional
  52. - name: Setup Build Environment
  53. uses: ./.github/actions/setup-build-environment
  54. env:
  55. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  56. - name: Download Kernel Repository
  57. uses: ./.github/actions/download-kernel
  58. with:
  59. android_version: ${{ steps.parse.outputs.android_version }}
  60. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  61. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  62. use_repo: ${{ inputs.use_repo }}
  63. - name: Extract Sublevel and Set File Name
  64. id: extract
  65. uses: ./.github/actions/extract-sublevel-file-name
  66. with:
  67. variant: ${{ inputs.variant }}
  68. - name: Kernel Fixes
  69. uses: ./.github/actions/kernel-fixes
  70. with:
  71. android_version: ${{ steps.parse.outputs.android_version }}
  72. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  73. sublevel: ${{ steps.extract.outputs.sublevel }}
  74. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  75. - name: Setup KernelSU-Next
  76. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  77. uses: ./.github/actions/kernelsu
  78. - name: SUSFS
  79. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  80. uses: ./.github/actions/susfs
  81. with:
  82. android_version: ${{ steps.parse.outputs.android_version }}
  83. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  84. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  85. sublevel: ${{ steps.extract.outputs.sublevel }}
  86. - name: Baseband Guard
  87. if: contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL'
  88. uses: ./.github/actions/bbg
  89. - name: Setup Networking
  90. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  91. uses: ./.github/actions/networking
  92. with:
  93. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  94. android_version: ${{ steps.parse.outputs.android_version }}
  95. - name: DroidSpaces-OSS Patches
  96. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  97. uses: ./.github/actions/droidspaces
  98. with:
  99. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  100. - name: Setup Misc Configs
  101. uses: ./.github/actions/misc
  102. with:
  103. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  104. android_version: ${{ steps.parse.outputs.android_version }}
  105. - name: Apply Module Check Bypass
  106. if: ${{ inputs.variant == 'Bypass' }}
  107. uses: ./.github/actions/module-check-bypass
  108. with:
  109. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  110. - name: Apply Device-Specific Patches
  111. uses: ./.github/actions/apply-device-patches
  112. with:
  113. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  114. - name: Apply ABI Compare Bypass
  115. if: false
  116. working-directory: ${{ github.workspace }}/kernel
  117. run: |
  118. # ABI compare bypass per kernel/android version
  119. # Edit each block as needed per version
  120. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  121. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  122. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  123. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  124. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  125. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  126. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  127. perl -i -pe 's/^(\s*)return 1$/$1print("Who Cares? Bypassing Now!")\n$1return 0/g if /if missing_symbols:/../return 1/' build/kernel/abi/check_buildtime_symbol_protection.py
  128. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  129. perl -i -pe 's/^(\s*)return 1$/$1print("Who Cares? Bypassing Now!")\n$1return 0/g if /if missing_symbols:/../return 1/' build/kernel/abi/check_buildtime_symbol_protection.py
  130. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  131. perl -i -pe 's/^(\s*)return 1$/$1print("Who Cares? Bypassing Now!")\n$1return 0/g if /if missing_symbols:/../return 1/' build/kernel/abi/check_buildtime_symbol_protection.py
  132. fi
  133. - name: Apply Kernel Branding
  134. uses: ./.github/actions/apply-kernel-branding
  135. with:
  136. variant: ${{ inputs.variant }}
  137. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  138. android_version: ${{ steps.parse.outputs.android_version }}
  139. sublevel: ${{ steps.extract.outputs.sublevel }}
  140. - name: Remove Protected Exports
  141. uses: ./.github/actions/remove-protected-exports
  142. - name: Clean Kernel Flags
  143. uses: ./.github/actions/clean-kernel-flags
  144. - name: Scan and collect patch rejects
  145. id: scan
  146. if: ${{ always() && inputs.variant == 'Normal' }}
  147. uses: ./.github/actions/scan-patch-rejects
  148. - name: Upload Rejects
  149. if: ${{ always() && inputs.variant == 'Normal' }}
  150. uses: actions/upload-artifact@v7
  151. with:
  152. name: ${{ steps.extract.outputs.file_name }}-Rejects
  153. path: patch-rejects/
  154. if-no-files-found: ignore
  155. compression-level: 9
  156. - name: Restore build caches (ccache)
  157. id: restore-ccache
  158. uses: ./.github/actions/restore-cache
  159. with:
  160. cache_path: /home/runner/.ccache
  161. cache_key: buildcache-${{ inputs.kernel_version }}
  162. cache_bucket: "ccache-cache"
  163. compression_level: 9
  164. restore_keys: |
  165. buildcache-
  166. - name: Check ccache hit
  167. run: |
  168. if [ "${{ steps.restore-ccache.outputs.cache-hit }}" = "true" ]; then
  169. echo "✅ ccache HIT - Key: ${{ steps.restore-ccache.outputs.cache-key }} - Size: ${{ steps.restore-ccache.outputs.cache-size }}"
  170. else
  171. echo "❌ ccache MISS - Fresh build"
  172. fi
  173. - name: Restore build caches (LTO/ld_cache)
  174. id: restore-ldcache
  175. uses: ./.github/actions/restore-cache
  176. with:
  177. cache_path: /home/runner/.ld_cache
  178. cache_key: buildcache-${{ inputs.kernel_version }}
  179. cache_bucket: "lto-cache"
  180. compression_level: 9
  181. restore_keys: |
  182. buildcache-
  183. - name: Check ld_cache hit
  184. run: |
  185. if [ "${{ steps.restore-ldcache.outputs.cache-hit }}" = "true" ]; then
  186. echo "✅ ld_cache HIT - Key: ${{ steps.restore-ldcache.outputs.cache-key }} - Size: ${{ steps.restore-ldcache.outputs.cache-size }}"
  187. else
  188. echo "❌ ld_cache MISS - Fresh build"
  189. fi
  190. - name: Pre-build cache stats
  191. id: pre-cache-stats
  192. run: |
  193. set -euo pipefail
  194. stats=$(ccache -s || true)
  195. pre_hits=$(echo "$stats" | awk '/cache hit/ {h+=$NF} END{print (h+0)}')
  196. pre_misses=$(echo "$stats" | awk '/cache miss/ {m+=$NF} END{print (m+0)}')
  197. echo "pre_hits=$pre_hits" >> $GITHUB_OUTPUT
  198. echo "pre_misses=$pre_misses" >> $GITHUB_OUTPUT
  199. pre_ld_size=$(du -sh "/home/runner/.ld_cache" 2>/dev/null | awk '{print $1}' || echo "0B")
  200. pre_ld_files=$(find "/home/runner/.ld_cache" -type f 2>/dev/null | wc -l || true)
  201. echo "pre_ld_size=$pre_ld_size" >> $GITHUB_OUTPUT
  202. echo "pre_ld_files=$pre_ld_files" >> $GITHUB_OUTPUT
  203. - name: 'Setup ccache and Build Environment'
  204. shell: bash
  205. working-directory: ${{ github.workspace }}
  206. run: |
  207. set -euo pipefail
  208. # Download and install ccache
  209. echo "Installing ccache..."
  210. 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; }
  211. sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
  212. sudo chmod +x /usr/bin/ccache
  213. rm -f ./ccache
  214. # Verify ccache
  215. if ! /usr/bin/ccache --version > /dev/null 2>&1; then
  216. echo "❌ ccache installation failed or binary is corrupted"
  217. exit 1
  218. fi
  219. echo "✅ ccache binary verified: $(/usr/bin/ccache --version | head -1)"
  220. # Setup cache directories
  221. export CCACHE_DIR="/home/runner/.ccache"
  222. echo "CCACHE_DIR=$CCACHE_DIR" >> $GITHUB_ENV
  223. #export LDCACHE_DIR="/home/runner/.ld_cache"
  224. #echo "LDCACHE_DIR=$LDCACHE_DIR" >> $GITHUB_ENV
  225. mkdir -p "$CCACHE_DIR"
  226. #"$LDCACHE_DIR"
  227. ## Create LD wrapper for thin-LTO caching
  228. #cat > "$GITHUB_WORKSPACE/kernel/common/ld-wrapper" << 'EOF'
  229. ##!/bin/bash
  230. #ld.lld "$@" --thinlto-cache-dir="$LDCACHE_DIR" --thinlto-jobs="$(nproc --all)"
  231. #EOF
  232. #chmod +x "$GITHUB_WORKSPACE/kernel/common/ld-wrapper"
  233. # Setup ccache compiler wrappers in PATH (masquerade method)
  234. # This intercepts compiler invocations regardless of how the build system calls them
  235. #mkdir -p "$GITHUB_WORKSPACE/ccache-bin"
  236. #cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/clang"
  237. #cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/clang++"
  238. #cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/gcc"
  239. #cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/g++"
  240. #cp /usr/bin/ccache "$GITHUB_WORKSPACE/ccache-bin/ld.lld"
  241. #chmod +x "$GITHUB_WORKSPACE/ccache-bin"/*
  242. # Export environment variables for subsequent steps
  243. #echo "PATH=$GITHUB_WORKSPACE/ccache-bin:$PATH" >> $GITHUB_ENV
  244. export CC="/usr/bin/ccache clang"
  245. echo "CC=$CC" >> $GITHUB_ENV
  246. export CXX="/usr/bin/ccache clang++"
  247. echo "CXX=$CXX" >> $GITHUB_ENV
  248. export HOSTCC="/usr/bin/ccache clang"
  249. echo "HOSTCC=$HOSTCC" >> $GITHUB_ENV
  250. export HOSTCXX="/usr/bin/ccache clang++"
  251. echo "HOSTCXX=$HOSTCXX" >> $GITHUB_ENV
  252. #export LD="$GITHUB_WORKSPACE/kernel/common/ld-wrapper"
  253. #echo "LD=$LD" >> $GITHUB_ENV
  254. #export HOSTLD="$GITHUB_WORKSPACE/kernel/common/ld-wrapper"
  255. #echo "HOSTLD=$HOSTLD" >> $GITHUB_ENV
  256. #echo "CLANG_PREBUILT_BIN=$GITHUB_WORKSPACE/ccache-bin" >> $GITHUB_ENV
  257. export CCACHE_MAXSIZE="12G"
  258. echo CCACHE_MAXSIZE="12G" >> $GITHUB_ENV
  259. export CCACHE_COMPILERCHECK="content"
  260. echo CCACHE_COMPILERCHECK="content" >> $GITHUB_ENV
  261. export CCACHE_BASEDIR="${GITHUB_WORKSPACE}"
  262. echo CCACHE_BASEDIR="${GITHUB_WORKSPACE}" >> $GITHUB_ENV
  263. export CCACHE_NOHASHDIR="true"
  264. echo CCACHE_NOHASHDIR="true" >> $GITHUB_ENV
  265. export CCACHE_IGNOREOPTIONS="--sysroot*"
  266. echo CCACHE_IGNOREOPTIONS="--sysroot*" >> $GITHUB_ENV
  267. export CCACHE_COMPRESSION="true"
  268. echo CCACHE_COMPRESSION="true" >> $GITHUB_ENV
  269. export CCACHE_COMPRESSLEVEL="3"
  270. echo CCACHE_COMPRESSION_LEVEL="3" >> $GITHUB_ENV
  271. export CCACHE_DIRECT="true"
  272. echo CCACHE_DIRECT="true" >> $GITHUB_ENV
  273. export CCACHE_FILE_CLONE="true"
  274. echo CCACHE_FILE_CLONE="true" >> $GITHUB_ENV
  275. export CCACHE_INODE_CACHE="true"
  276. echo CCACHE_INODE_CACHE="true" >> $GITHUB_ENV
  277. export CCACHE_IS_KERNEL_COMPILING="true"
  278. echo CCACHE_IS_KERNEL_COMPILING="true" >> $GITHUB_ENV
  279. export CCACHE_UMASK="002"
  280. echo CCACHE_UMASK="002" >> $GITHUB_ENV
  281. export CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
  282. echo CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale" >> $GITHUB_ENV
  283. if ccache --help 2>&1 | grep -q 'depend_mode'; then
  284. export CCACHE_DEPEND=true
  285. echo "CCACHE_DEPEND=true" >> "$GITHUB_ENV"
  286. fi
  287. # Initialize ccache
  288. #ccache -M 100G
  289. ccache -p
  290. ccache -s
  291. ccache -z
  292. echo "✅ Build environment ready"
  293. echo " CCACHE_DIR: $CCACHE_DIR"
  294. #echo " LDCACHE_DIR: $LDCACHE_DIR"
  295. #echo " Compiler wrappers: $GITHUB_WORKSPACE/ccache-bin"
  296. - name: Build Kernel
  297. env:
  298. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  299. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  300. uses: ./.github/actions/build-kernel
  301. - name: 'Report Cache Sizes'
  302. shell: bash
  303. working-directory: ${{ github.workspace }}/kernel/common
  304. run: |
  305. set -euo pipefail
  306. echo "📊 Cache sizes after build:"
  307. echo " CCACHE usage:"
  308. du -sh "$CCACHE_DIR" || echo " (no ccache directory)"
  309. #echo " LDCACHE usage:"
  310. #du -sh "$LDCACHE_DIR" || echo " (no ldcache directory)"
  311. echo "Perform cache eviction!"
  312. # 3h = 10800s using seconds to support older ccache
  313. ccache --evict-older-than 10800s
  314. - name: Post-build cache stats
  315. id: post-cache-stats
  316. run: |
  317. set -euo pipefail
  318. stats=$(ccache -s || true)
  319. post_hits=$(echo "$stats" | awk '/cache hit/ {h+=$NF} END{print (h+0)}')
  320. post_misses=$(echo "$stats" | awk '/cache miss/ {m+=$NF} END{print (m+0)}')
  321. pre_hits=${{ steps.pre-cache-stats.outputs.pre_hits }}
  322. pre_misses=${{ steps.pre-cache-stats.outputs.pre_misses }}
  323. delta_hits=$((post_hits - pre_hits)) || true
  324. delta_misses=$((post_misses - pre_misses)) || true
  325. delta_total=$((delta_hits + delta_misses))
  326. if [ "$delta_total" -gt 0 ]; then
  327. percent=$(( delta_hits * 100 / delta_total ))
  328. echo "ccache hit during build: ${percent}% (${delta_hits} hits / ${delta_total} accesses)"
  329. else
  330. echo "No compiler activity detected (no ccache accesses)."
  331. fi
  332. post_ld_size=$(du -sh "/home/runner/.ld_cache" 2>/dev/null | awk '{print $1}' || echo "0B")
  333. post_ld_files=$(find "/home/runner/.ld_cache" -type f 2>/dev/null | wc -l || true)
  334. echo "ld_cache size before: ${{ steps.pre-cache-stats.outputs.pre_ld_size }}, after: $post_ld_size"
  335. echo "ld_cache files before: ${{ steps.pre-cache-stats.outputs.pre_ld_files }}, after: $post_ld_files"
  336. - name: List cache contents
  337. working-directory: ${{ github.workspace }}
  338. run: |
  339. echo "=== .ccache ==="
  340. du -sh /home/runner/.ccache || true
  341. ls -l /home/runner/.ccache || true
  342. echo "=== .cache/bazel ==="
  343. du -sh /home/runner/.cache/bazel || true
  344. ls -l /home/runner/.cache/bazel || true
  345. - name: Save ccache cache
  346. uses: ./.github/actions/save-cache
  347. with:
  348. cache_path: /home/runner/.ccache
  349. cache_key: buildcache-${{ inputs.kernel_version }}
  350. cache_bucket: "ccache-cache"
  351. compression_level: 9
  352. github_token: ${{ secrets.GITHUB_TOKEN }}
  353. - name: Save LTO LD cache
  354. uses: ./.github/actions/save-cache
  355. with:
  356. cache_path: /home/runner/.ld_cache
  357. cache_key: buildcache-${{ inputs.kernel_version }}
  358. cache_bucket: "lto-cache"
  359. compression_level: 9
  360. github_token: ${{ secrets.GITHUB_TOKEN }}
  361. - name: Create Bootimgs Folder and Build Boot Images
  362. uses: ./.github/actions/build-boot-images
  363. - name: Upload Boot Image (boot.img)
  364. uses: actions/upload-artifact@v7
  365. with:
  366. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  367. if-no-files-found: error
  368. archive: false
  369. - name: Upload Boot Image (boot-gz.img)
  370. uses: actions/upload-artifact@v7
  371. with:
  372. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  373. if-no-files-found: error
  374. archive: false
  375. - name: Upload Boot Image (boot-lz4.img)
  376. uses: actions/upload-artifact@v7
  377. with:
  378. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  379. if-no-files-found: error
  380. archive: false
  381. - name: Prepare AnyKernel3 Zip
  382. uses: ./.github/actions/prepare-anykernel3
  383. - name: Upload Artifacts
  384. uses: actions/upload-artifact@v7
  385. with:
  386. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  387. path: ${{ github.workspace }}/AnyKernel3/**
  388. if-no-files-found: ignore
  389. compression-level: 9