build.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. if: false
  50. with:
  51. swap-size-gb: 25 # 10-24 GB is common for heavy LTO
  52. # swap-space-path: /mnt/swapfile # optional
  53. - name: Setup Build Environment
  54. uses: ./.github/actions/setup-build-environment
  55. env:
  56. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  57. - name: Download Kernel Repository
  58. uses: ./.github/actions/download-kernel
  59. with:
  60. android_version: ${{ steps.parse.outputs.android_version }}
  61. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  62. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  63. use_repo: ${{ inputs.use_repo }}
  64. - name: Grep for vm_flags_clear after download
  65. run: |
  66. grep -n 'vm_flags_clear' ${{ github.workspace }}/kernel/common/mm/mmap.c || echo 'Not found'
  67. - name: Extract Sublevel and Set File Name
  68. id: extract
  69. uses: ./.github/actions/extract-sublevel-file-name
  70. with:
  71. variant: ${{ inputs.variant }}
  72. - name: Kernel Fixes
  73. uses: ./.github/actions/kernel-fixes
  74. with:
  75. android_version: ${{ steps.parse.outputs.android_version }}
  76. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  77. sublevel: ${{ steps.extract.outputs.sublevel }}
  78. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  79. - name: Setup KernelSU-Next
  80. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  81. uses: ./.github/actions/kernelsu
  82. - name: SUSFS
  83. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  84. uses: ./.github/actions/susfs
  85. with:
  86. android_version: ${{ steps.parse.outputs.android_version }}
  87. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  88. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  89. sublevel: ${{ steps.extract.outputs.sublevel }}
  90. - name: Baseband Guard
  91. if: contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL'
  92. uses: ./.github/actions/bbg
  93. - name: Setup Networking
  94. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  95. uses: ./.github/actions/networking
  96. with:
  97. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  98. android_version: ${{ steps.parse.outputs.android_version }}
  99. - name: DroidSpaces-OSS Patches
  100. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  101. uses: ./.github/actions/droidspaces
  102. with:
  103. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  104. - name: Setup Misc Configs
  105. uses: ./.github/actions/misc
  106. with:
  107. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  108. android_version: ${{ steps.parse.outputs.android_version }}
  109. - name: Apply Module Check Bypass
  110. if: ${{ inputs.variant == 'Bypass' }}
  111. uses: ./.github/actions/module-check-bypass
  112. with:
  113. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  114. - name: Apply Device-Specific Patches
  115. uses: ./.github/actions/apply-device-patches
  116. with:
  117. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  118. - name: Apply ABI Compare Bypass
  119. if: false
  120. working-directory: ${{ github.workspace }}/kernel
  121. run: |
  122. # ABI compare bypass per kernel/android version
  123. # Edit each block as needed per version
  124. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  125. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  126. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  127. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  128. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  129. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  130. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; 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. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  133. 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
  134. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  135. 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
  136. fi
  137. - name: Apply Kernel Branding
  138. uses: ./.github/actions/apply-kernel-branding
  139. with:
  140. variant: ${{ inputs.variant }}
  141. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  142. android_version: ${{ steps.parse.outputs.android_version }}
  143. sublevel: ${{ steps.extract.outputs.sublevel }}
  144. - name: Remove Protected Exports
  145. uses: ./.github/actions/remove-protected-exports
  146. - name: Clean Kernel Flags
  147. uses: ./.github/actions/clean-kernel-flags
  148. - name: Scan and collect patch rejects
  149. id: scan
  150. if: ${{ always() && inputs.variant == 'Normal' }}
  151. uses: ./.github/actions/scan-patch-rejects
  152. - name: Upload Rejects
  153. if: ${{ always() && inputs.variant == 'Normal' }}
  154. uses: actions/upload-artifact@v7
  155. with:
  156. name: ${{ steps.extract.outputs.file_name }}-Rejects
  157. path: patch-rejects/
  158. if-no-files-found: ignore
  159. compression-level: 9
  160. - name: Grep for vm_flags_clear before build
  161. run: |
  162. grep -n 'vm_flags_clear' ${{ github.workspace }}/kernel/common/mm/mmap.c || echo 'Not found'
  163. - name: Restore build caches (ccache)
  164. id: restore-ccache
  165. uses: ./.github/actions/restore-cache
  166. with:
  167. cache_path: ${{ github.workspace }}/.ccache
  168. cache_key: buildcache-${{ inputs.kernel_version }}
  169. cache_bucket: "ccache-cache"
  170. compression_level: 9
  171. restore_keys: |
  172. buildcache-
  173. - name: Check ccache hit
  174. run: |
  175. if [ "${{ steps.restore-ccache.outputs.cache-hit }}" = "true" ]; then
  176. echo "✅ ccache HIT - Key: ${{ steps.restore-ccache.outputs.cache-key }} - Size: ${{ steps.restore-ccache.outputs.cache-size }}"
  177. else
  178. echo "❌ ccache MISS - Fresh build"
  179. fi
  180. - name: Restore build caches (LTO/ld_cache)
  181. id: restore-ldcache
  182. uses: ./.github/actions/restore-cache
  183. with:
  184. cache_path: ${{ github.workspace }}/.ld_cache
  185. cache_key: buildcache-${{ inputs.kernel_version }}
  186. cache_bucket: "lto-cache"
  187. compression_level: 9
  188. restore_keys: |
  189. buildcache-
  190. - name: Check ld_cache hit
  191. run: |
  192. if [ "${{ steps.restore-ldcache.outputs.cache-hit }}" = "true" ]; then
  193. echo "✅ ld_cache HIT - Key: ${{ steps.restore-ldcache.outputs.cache-key }} - Size: ${{ steps.restore-ldcache.outputs.cache-size }}"
  194. else
  195. echo "❌ ld_cache MISS - Fresh build"
  196. fi
  197. - name: Pre-build cache stats
  198. id: pre-cache-stats
  199. run: |
  200. set -euo pipefail
  201. stats=$(ccache -s || true)
  202. pre_hits=$(echo "$stats" | awk '/cache hit/ {h+=$NF} END{print (h+0)}')
  203. pre_misses=$(echo "$stats" | awk '/cache miss/ {m+=$NF} END{print (m+0)}')
  204. echo "pre_hits=$pre_hits" >> $GITHUB_OUTPUT
  205. echo "pre_misses=$pre_misses" >> $GITHUB_OUTPUT
  206. pre_ld_size=$(du -sh "$GITHUB_WORKSPACE/.ld_cache" 2>/dev/null | awk '{print $1}' || echo "0B")
  207. pre_ld_files=$(find "$GITHUB_WORKSPACE/.ld_cache" -type f 2>/dev/null | wc -l || true)
  208. echo "pre_ld_size=$pre_ld_size" >> $GITHUB_OUTPUT
  209. echo "pre_ld_files=$pre_ld_files" >> $GITHUB_OUTPUT
  210. - name: Build Kernel
  211. env:
  212. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  213. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  214. uses: ./.github/actions/build-kernel
  215. - name: Post-build cache stats
  216. id: post-cache-stats
  217. run: |
  218. set -euo pipefail
  219. stats=$(ccache -s || true)
  220. post_hits=$(echo "$stats" | awk '/cache hit/ {h+=$NF} END{print (h+0)}')
  221. post_misses=$(echo "$stats" | awk '/cache miss/ {m+=$NF} END{print (m+0)}')
  222. pre_hits=${{ steps.pre-cache-stats.outputs.pre_hits }}
  223. pre_misses=${{ steps.pre-cache-stats.outputs.pre_misses }}
  224. delta_hits=$((post_hits - pre_hits)) || true
  225. delta_misses=$((post_misses - pre_misses)) || true
  226. delta_total=$((delta_hits + delta_misses))
  227. if [ "$delta_total" -gt 0 ]; then
  228. percent=$(( delta_hits * 100 / delta_total ))
  229. echo "ccache hit during build: ${percent}% (${delta_hits} hits / ${delta_total} accesses)"
  230. else
  231. echo "No compiler activity detected (no ccache accesses)."
  232. fi
  233. post_ld_size=$(du -sh "$GITHUB_WORKSPACE/.ld_cache" 2>/dev/null | awk '{print $1}' || echo "0B")
  234. post_ld_files=$(find "$GITHUB_WORKSPACE/.ld_cache" -type f 2>/dev/null | wc -l || true)
  235. echo "ld_cache size before: ${{ steps.pre-cache-stats.outputs.pre_ld_size }}, after: $post_ld_size"
  236. echo "ld_cache files before: ${{ steps.pre-cache-stats.outputs.pre_ld_files }}, after: $post_ld_files"
  237. - name: List cache contents
  238. working-directory: ${{ github.workspace }}
  239. run: |
  240. echo "=== .ccache ==="
  241. du -sh .ccache || true
  242. ls -l .ccache || true
  243. echo "=== .cache/bazel ==="
  244. du -sh .cache/bazel || true
  245. ls -l .cache/bazel || true
  246. - name: Save ccache cache
  247. uses: ./.github/actions/save-cache
  248. with:
  249. cache_path: ${{ github.workspace }}/.ccache
  250. cache_key: buildcache-${{ inputs.kernel_version }}
  251. cache_bucket: "ccache-cache"
  252. compression_level: 9
  253. github_token: ${{ secrets.GITHUB_TOKEN }}
  254. - name: Save LTO LD cache
  255. uses: ./.github/actions/save-cache
  256. with:
  257. cache_path: ${{ github.workspace }}/.ld_cache
  258. cache_key: buildcache-${{ inputs.kernel_version }}
  259. cache_bucket: "lto-cache"
  260. compression_level: 9
  261. github_token: ${{ secrets.GITHUB_TOKEN }}
  262. - name: Create Bootimgs Folder and Build Boot Images
  263. uses: ./.github/actions/build-boot-images
  264. - name: Upload Boot Image (boot.img)
  265. uses: actions/upload-artifact@v7
  266. with:
  267. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  268. if-no-files-found: error
  269. archive: false
  270. - name: Upload Boot Image (boot-gz.img)
  271. uses: actions/upload-artifact@v7
  272. with:
  273. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  274. if-no-files-found: error
  275. archive: false
  276. - name: Upload Boot Image (boot-lz4.img)
  277. uses: actions/upload-artifact@v7
  278. with:
  279. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  280. if-no-files-found: error
  281. archive: false
  282. - name: Prepare AnyKernel3 Zip
  283. uses: ./.github/actions/prepare-anykernel3
  284. - name: Upload Artifacts
  285. uses: actions/upload-artifact@v7
  286. with:
  287. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  288. path: ${{ github.workspace }}/AnyKernel3/**
  289. if-no-files-found: ignore
  290. compression-level: 9