build.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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: Display system disk usage
  27. run: |
  28. echo "=== Disk usage summary ==="
  29. df -h
  30. echo ""
  31. - name: Checkout Repository
  32. uses: actions/checkout@v5
  33. - name: Parse kernel version
  34. id: parse
  35. uses: ./.github/actions/parse-kernel-version
  36. with:
  37. kernel_version: ${{ inputs.kernel_version }}
  38. - name: Free Disk Space
  39. if: true
  40. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  41. with:
  42. remove_android: true
  43. remove_dotnet: true
  44. remove_haskell: true
  45. remove_tool_cache: true
  46. #remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  47. #remove_packages_one_command: true
  48. 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"
  49. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  50. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  51. testing: false
  52. - name: Display system disk usage
  53. run: |
  54. echo "=== Disk usage summary ==="
  55. df -h
  56. echo ""
  57. - name: Setup more Swap (for LTO)
  58. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  59. with:
  60. swap-size-gb: 10 # 10-24 GB is common for heavy LTO
  61. # swap-space-path: /mnt/swapfile # optional
  62. - name: Display system disk usage
  63. run: |
  64. echo "=== Disk usage summary ==="
  65. df -h
  66. echo ""
  67. - name: Setup Build Environment
  68. uses: ./.github/actions/setup-build-environment
  69. env:
  70. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  71. - name: Display system disk usage
  72. run: |
  73. echo "=== Disk usage summary ==="
  74. df -h
  75. echo ""
  76. - name: Download Kernel Repository
  77. uses: ./.github/actions/download-kernel
  78. with:
  79. android_version: ${{ steps.parse.outputs.android_version }}
  80. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  81. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  82. use_repo: ${{ inputs.use_repo }}
  83. - name: Display system disk usage
  84. run: |
  85. echo "=== Disk usage summary ==="
  86. df -h
  87. echo ""
  88. - name: Extract Sublevel and Set File Name
  89. id: extract
  90. uses: ./.github/actions/extract-sublevel-file-name
  91. with:
  92. variant: ${{ inputs.variant }}
  93. - name: Kernel Fixes
  94. uses: ./.github/actions/kernel-fixes
  95. with:
  96. android_version: ${{ steps.parse.outputs.android_version }}
  97. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  98. sublevel: ${{ steps.extract.outputs.sublevel }}
  99. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  100. - name: Setup KernelSU-Next
  101. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  102. uses: ./.github/actions/kernelsu
  103. - name: SUSFS
  104. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  105. uses: ./.github/actions/susfs
  106. with:
  107. android_version: ${{ steps.parse.outputs.android_version }}
  108. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  109. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  110. sublevel: ${{ steps.extract.outputs.sublevel }}
  111. - name: Baseband Guard
  112. if: contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL'
  113. uses: ./.github/actions/bbg
  114. - name: Setup Networking
  115. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  116. uses: ./.github/actions/networking
  117. with:
  118. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  119. android_version: ${{ steps.parse.outputs.android_version }}
  120. - name: DroidSpaces-OSS Patches
  121. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  122. uses: ./.github/actions/droidspaces
  123. with:
  124. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  125. - name: Setup Misc Configs
  126. uses: ./.github/actions/misc
  127. with:
  128. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  129. android_version: ${{ steps.parse.outputs.android_version }}
  130. - name: Apply Module Check Bypass
  131. if: ${{ inputs.variant == 'Bypass' }}
  132. uses: ./.github/actions/module-check-bypass
  133. with:
  134. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  135. - name: Apply Device-Specific Patches
  136. uses: ./.github/actions/apply-device-patches
  137. with:
  138. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  139. - name: Apply ABI Compare Bypass
  140. if: false
  141. working-directory: ${{ github.workspace }}/kernel
  142. run: |
  143. # ABI compare bypass per kernel/android version
  144. # Edit each block as needed per version
  145. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  146. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  147. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  148. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  149. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  150. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  151. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  152. 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
  153. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  154. 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
  155. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  156. 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
  157. fi
  158. - name: Apply Kernel Branding
  159. uses: ./.github/actions/apply-kernel-branding
  160. with:
  161. variant: ${{ inputs.variant }}
  162. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  163. android_version: ${{ steps.parse.outputs.android_version }}
  164. sublevel: ${{ steps.extract.outputs.sublevel }}
  165. - name: Remove Protected Exports
  166. uses: ./.github/actions/remove-protected-exports
  167. - name: Clean Kernel Flags
  168. uses: ./.github/actions/clean-kernel-flags
  169. - name: Scan and collect patch rejects
  170. id: scan
  171. if: ${{ always() && inputs.variant == 'Normal' }}
  172. uses: ./.github/actions/scan-patch-rejects
  173. - name: Upload Rejects
  174. if: ${{ always() && inputs.variant == 'Normal' }}
  175. uses: actions/upload-artifact@v7
  176. with:
  177. name: ${{ steps.extract.outputs.file_name }}-Rejects
  178. path: patch-rejects/
  179. if-no-files-found: ignore
  180. compression-level: 9
  181. - name: Display system disk usage
  182. run: |
  183. echo "=== Disk usage summary ==="
  184. df -h
  185. echo ""
  186. - name: 'Setup ccache and Build Environment'
  187. shell: bash
  188. if: true
  189. working-directory: ${{ github.workspace }}
  190. run: |
  191. set -euo pipefail
  192. # Download and install ccache
  193. echo "Installing ccache..."
  194. 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; }
  195. sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
  196. sudo chmod +x /usr/bin/ccache
  197. rm -f ./ccache
  198. # Verify ccache
  199. if ! /usr/bin/ccache --version > /dev/null 2>&1; then
  200. echo "❌ ccache installation failed or binary is corrupted"
  201. exit 1
  202. fi
  203. echo "✅ ccache binary verified: $(/usr/bin/ccache --version | head -1)"
  204. # Setup cache directories
  205. export CCACHE_DIR="/home/runner/.ccache"
  206. echo "CCACHE_DIR=$CCACHE_DIR" >> $GITHUB_ENV
  207. export LDCACHE_DIR="/home/runner/.ld_cache"
  208. echo "LDCACHE_DIR=$LDCACHE_DIR" >> $GITHUB_ENV
  209. mkdir -p "$CCACHE_DIR" "$LDCACHE_DIR"
  210. # Create LD wrapper for thin-LTO caching
  211. cat > "$GITHUB_WORKSPACE/kernel/common/ld-wrapper" << 'EOF'
  212. #!/bin/bash
  213. ld.lld "$@" --thinlto-cache-dir="$LDCACHE_DIR" --thinlto-jobs="$(nproc --all)"
  214. EOF
  215. chmod +x "$GITHUB_WORKSPACE/kernel/common/ld-wrapper"
  216. echo "CC=/usr/bin/ccache clang" >> "$GITHUB_ENV"
  217. echo "CXX=/usr/bin/ccache clang++" >> "$GITHUB_ENV"
  218. echo "HOSTCC=/usr/bin/ccache clang" >> "$GITHUB_ENV"
  219. echo "HOSTCXX=/usr/bin/ccache clang++" >> "$GITHUB_ENV"
  220. echo "LD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> "$GITHUB_ENV"
  221. echo "HOSTLD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> "$GITHUB_ENV"
  222. export CCACHE_MAXSIZE="12G"
  223. echo CCACHE_MAXSIZE="$CCACHE_MAXSIZE" >> $GITHUB_ENV
  224. export CCACHE_COMPILERCHECK="%compiler% -dumpmachine; %compiler% -dumpversion"
  225. echo CCACHE_COMPILERCHECK="$CCACHE_COMPILERCHECK" >> $GITHUB_ENV
  226. export CCACHE_BASEDIR="${GITHUB_WORKSPACE}"
  227. echo CCACHE_BASEDIR="${GITHUB_WORKSPACE}" >> $GITHUB_ENV
  228. export CCACHE_NOHASHDIR="true"
  229. echo CCACHE_NOHASHDIR="true" >> $GITHUB_ENV
  230. export CCACHE_IGNOREOPTIONS="--sysroot*"
  231. echo CCACHE_IGNOREOPTIONS="--sysroot*" >> $GITHUB_ENV
  232. export CCACHE_COMPRESSION="true"
  233. echo CCACHE_COMPRESSION="true" >> $GITHUB_ENV
  234. export CCACHE_COMPRESSLEVEL="9"
  235. echo CCACHE_COMPRESSION_LEVEL="9" >> $GITHUB_ENV
  236. # Temporarily disabled for cache hit testing
  237. # export CCACHE_DIRECT="true"
  238. # echo CCACHE_DIRECT="true" >> "$GITHUB_ENV"
  239. # Temporarily disabled for cache hit testing
  240. # export CCACHE_FILE_CLONE="true"
  241. # echo CCACHE_FILE_CLONE="true" >> "$GITHUB_ENV"
  242. # Temporarily disabled for cache hit testing
  243. # export CCACHE_INODE_CACHE="true"
  244. # echo CCACHE_INODE_CACHE="true" >> "$GITHUB_ENV"
  245. export CCACHE_IS_KERNEL_COMPILING="true"
  246. echo CCACHE_IS_KERNEL_COMPILING="true" >> $GITHUB_ENV
  247. export CCACHE_UMASK="002"
  248. echo CCACHE_UMASK="002" >> $GITHUB_ENV
  249. export CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
  250. echo CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale" >> $GITHUB_ENV
  251. #export CCACHE_HARDLINK="true"
  252. #echo CCACHE_HARDLINK="$CCACHE_HARDLINK" >> $GITHUB_ENV
  253. if ccache --help 2>&1 | grep -q 'depend_mode'; then
  254. export CCACHE_DEPEND=true
  255. echo "CCACHE_DEPEND=true" >> "$GITHUB_ENV"
  256. fi
  257. # Initialize ccache
  258. #ccache -M 100G
  259. ccache -p
  260. ccache -s
  261. ccache -z
  262. echo "✅ Build environment ready"
  263. echo " CCACHE_DIR: $CCACHE_DIR"
  264. echo " LDCACHE_DIR: $LDCACHE_DIR"
  265. - name: Restore build caches (ccache)
  266. id: restore-ccache
  267. uses: ./.github/actions/restore-cache
  268. with:
  269. cache_path: /home/runner/.ccache
  270. cache_key: buildcache-${{ inputs.kernel_version }}
  271. cache_bucket: "ccache-cache"
  272. compression_level: 9
  273. restore_keys: |
  274. buildcache-
  275. - name: Restore build caches (bazel)
  276. id: restore-bazel-cache
  277. uses: ./.github/actions/restore-cache
  278. with:
  279. cache_path: /home/runner/.cache/bazel
  280. cache_key: buildcache-${{ inputs.kernel_version }}
  281. cache_bucket: "bazel-cache"
  282. compression_level: 9
  283. restore_keys: |
  284. buildcache-
  285. - name: Restore build caches (LTO/ld_cache)
  286. id: restore-ldcache
  287. uses: ./.github/actions/restore-cache
  288. with:
  289. cache_path: /home/runner/.ld_cache
  290. cache_key: buildcache-${{ inputs.kernel_version }}
  291. cache_bucket: "lto-cache"
  292. compression_level: 9
  293. restore_keys: |
  294. buildcache-
  295. - name: Check cache hit
  296. run: |
  297. if [ "${{ steps.restore-ccache.outputs.cache-hit }}" = "true" ]; then
  298. echo "✅ ccache HIT - Key: ${{ steps.restore-ccache.outputs.cache-key }} - Size: ${{ steps.restore-ccache.outputs.cache-size }}"
  299. else
  300. echo "❌ ccache MISS - Fresh build"
  301. fi
  302. if [ "${{ steps.restore-bazel-cache.outputs.cache-hit }}" = "true" ]; then
  303. echo "✅ bazel cache HIT - Key: ${{ steps.restore-bazel-cache.outputs.cache-key }} - Size: ${{ steps.restore-bazel-cache.outputs.cache-size }}"
  304. else
  305. echo "❌ bazel cache MISS - Fresh build"
  306. fi
  307. if [ "${{ steps.restore-ldcache.outputs.cache-hit }}" = "true" ]; then
  308. echo "✅ ld_cache HIT - Key: ${{ steps.restore-ldcache.outputs.cache-key }} - Size: ${{ steps.restore-ldcache.outputs.cache-size }}"
  309. else
  310. echo "❌ ld_cache MISS - Fresh build"
  311. fi
  312. ccache -p
  313. ccache -s
  314. ccache -z
  315. - name: List cache contents
  316. working-directory: ${{ github.workspace }}
  317. run: |
  318. echo "=== .ccache ==="
  319. du -sh /home/runner/.ccache || true
  320. ls -l /home/runner/.ccache || true
  321. echo "=== .cache/bazel ==="
  322. du -sh /home/runner/.cache/bazel || true
  323. ls -l /home/runner/.cache/bazel || true
  324. echo "=== .ld_cache ==="
  325. du -sh /home/runner/.ld_cache || true
  326. ls -l /home/runner/.ld_cache || true
  327. - name: Display system disk usage
  328. run: |
  329. echo "=== Disk usage summary ==="
  330. df -h
  331. echo ""
  332. - name: Build Kernel
  333. env:
  334. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  335. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  336. uses: ./.github/actions/build-kernel
  337. - name: Display system disk usage
  338. run: |
  339. echo "=== Disk usage summary ==="
  340. df -h
  341. echo ""
  342. - name: Post-build cache stats
  343. id: post-cache-stats
  344. run: |
  345. set -euo pipefail
  346. STATS="$(ccache -s)"
  347. CACHEABLE=$(echo "$STATS" | awk '/Cacheable calls:/ {
  348. match($0, /[0-9]+/);
  349. print substr($0, RSTART, RLENGTH)
  350. }' | head -n1)
  351. HITS=$(echo "$STATS" | awk '/^[[:space:]]*Hits:/ {
  352. match($0, /[0-9]+/);
  353. print substr($0, RSTART, RLENGTH)
  354. }' | head -n1)
  355. DIRECT=$(echo "$STATS" | awk '/Direct:/ {
  356. match($0, /[0-9]+/);
  357. print substr($0, RSTART, RLENGTH)
  358. }' | head -n1)
  359. if [ "${CACHEABLE:-0}" -gt 0 ]; then
  360. HIT_RATE=$(awk -v h="${HITS:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (h/c)*100}')
  361. DIRECT_RATE=$(awk -v d="${DIRECT:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (d/c)*100}')
  362. else
  363. HIT_RATE="0.0"
  364. DIRECT_RATE="0.0"
  365. fi
  366. echo "hit_rate=${HIT_RATE}%"
  367. echo "direct_rate=${DIRECT_RATE}%"
  368. - name: List cache contents
  369. working-directory: ${{ github.workspace }}
  370. run: |
  371. echo "=== .ccache ==="
  372. du -sh /home/runner/.ccache || true
  373. ls -l /home/runner/.ccache || true
  374. echo "=== .cache/bazel ==="
  375. du -sh /home/runner/.cache/bazel || true
  376. ls -l /home/runner/.cache/bazel || true
  377. echo "=== .ld_cache ==="
  378. du -sh /home/runner/.ld_cache || true
  379. ls -l /home/runner/.ld_cache || true
  380. - name: Save ccache cache
  381. uses: ./.github/actions/save-cache
  382. with:
  383. cache_path: /home/runner/.ccache
  384. cache_key: buildcache-${{ inputs.kernel_version }}
  385. cache_bucket: "ccache-cache"
  386. compression_level: 9
  387. github_token: ${{ secrets.GITHUB_TOKEN }}
  388. - name: Save bazel cache
  389. uses: ./.github/actions/save-cache
  390. with:
  391. cache_path: /home/runner/.cache/bazel
  392. cache_key: buildcache-${{ inputs.kernel_version }}
  393. cache_bucket: "bazel-cache"
  394. compression_level: 9
  395. github_token: ${{ secrets.GITHUB_TOKEN }}
  396. - name: Save LTO LD cache
  397. uses: ./.github/actions/save-cache
  398. with:
  399. cache_path: /home/runner/.ld_cache
  400. cache_key: buildcache-${{ inputs.kernel_version }}
  401. cache_bucket: "lto-cache"
  402. compression_level: 9
  403. github_token: ${{ secrets.GITHUB_TOKEN }}
  404. - name: Create Bootimgs Folder and Build Boot Images
  405. uses: ./.github/actions/build-boot-images
  406. - name: Upload Boot Image (boot.img)
  407. uses: actions/upload-artifact@v7
  408. with:
  409. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  410. if-no-files-found: error
  411. archive: false
  412. - name: Upload Boot Image (boot-gz.img)
  413. uses: actions/upload-artifact@v7
  414. with:
  415. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  416. if-no-files-found: error
  417. archive: false
  418. - name: Upload Boot Image (boot-lz4.img)
  419. uses: actions/upload-artifact@v7
  420. with:
  421. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  422. if-no-files-found: error
  423. archive: false
  424. - name: Prepare AnyKernel3 Zip
  425. uses: ./.github/actions/prepare-anykernel3
  426. - name: Upload Artifacts
  427. uses: actions/upload-artifact@v7
  428. with:
  429. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  430. path: ${{ github.workspace }}/AnyKernel3/**
  431. if-no-files-found: ignore
  432. compression-level: 9