build.yml 13 KB

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