build.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. name: Kernel Build Process
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. version:
  9. required: true
  10. type: string
  11. android_version:
  12. required: true
  13. type: string
  14. kernel_version:
  15. required: true
  16. type: string
  17. sublevel:
  18. required: true
  19. type: string
  20. os_patch_level:
  21. required: true
  22. type: string
  23. variant:
  24. required: false
  25. type: string
  26. feature_set:
  27. required: true
  28. type: string
  29. use_repo:
  30. required: false
  31. type: boolean
  32. jobs:
  33. build-gki:
  34. name: "${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} (${{ inputs.variant }})"
  35. runs-on: ubuntu-latest
  36. timeout-minutes: 60
  37. steps:
  38. - name: Checkout Repository
  39. uses: actions/checkout@v5
  40. - name: Free Disk Space
  41. if: false
  42. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  43. with:
  44. remove_android: true
  45. remove_dotnet: true
  46. remove_haskell: true
  47. remove_tool_cache: true
  48. #remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  49. #remove_packages_one_command: true
  50. 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"
  51. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  52. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  53. testing: false
  54. - name: Setup more Swap (for LTO)
  55. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  56. with:
  57. swap-size-gb: 10 # 10-24 GB is common for heavy LTO
  58. # swap-space-path: /mnt/swapfile # optional
  59. - name: Setup Build Environment
  60. uses: ./.github/actions/setup-build-environment
  61. env:
  62. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  63. - name: Download Kernel Repository
  64. uses: ./.github/actions/download-kernel
  65. with:
  66. version: ${{ inputs.version }}
  67. android_version: ${{ inputs.android_version }}
  68. kernel_version: ${{ inputs.kernel_version }}
  69. os_patch_level: ${{ inputs.os_patch_level }}
  70. use_repo: ${{ inputs.use_repo }}
  71. - name: Set Build Timestamp from Kernel Commit
  72. shell: bash
  73. run: |
  74. SOURCE_DATE_EPOCH=$(git -C "${{ github.workspace }}/kernel/common" log -1 --format=%ct 2>/dev/null || date -u +%s)
  75. echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
  76. echo "KBUILD_BUILD_TIMESTAMP=$(date -u -d @${SOURCE_DATE_EPOCH} '+%a %b %d %H:%M:%S UTC %Y')" >> $GITHUB_ENV
  77. echo "Build timestamp set to: $(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S UTC')"
  78. - name: Extract Sublevel and Set File Name
  79. id: extract
  80. uses: ./.github/actions/extract-sublevel-file-name
  81. with:
  82. android_version: ${{ inputs.android_version }}
  83. kernel_version: ${{ inputs.kernel_version }}
  84. sublevel: ${{ inputs.sublevel }}
  85. os_patch_level: ${{ inputs.os_patch_level }}
  86. variant: ${{ inputs.variant }}
  87. - name: Kernel Fixes
  88. uses: ./.github/actions/kernel-fixes
  89. with:
  90. version: ${{ inputs.version }}
  91. android_version: ${{ inputs.android_version }}
  92. kernel_version: ${{ inputs.kernel_version }}
  93. sublevel: ${{ steps.extract.outputs.sublevel }}
  94. os_patch_level: ${{ inputs.os_patch_level }}
  95. - name: Setup KernelSU-Next
  96. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  97. uses: ./.github/actions/kernelsu
  98. - name: SUSFS
  99. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  100. uses: ./.github/actions/susfs
  101. with:
  102. version: ${{ inputs.version }}
  103. android_version: ${{ inputs.android_version }}
  104. kernel_version: ${{ inputs.kernel_version }}
  105. os_patch_level: ${{ inputs.os_patch_level }}
  106. sublevel: ${{ steps.extract.outputs.sublevel }}
  107. - name: Baseband Guard
  108. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL')
  109. uses: ./.github/actions/bbg
  110. - name: Setup Networking
  111. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  112. uses: ./.github/actions/networking
  113. with:
  114. kernel_version: ${{ inputs.kernel_version }}
  115. android_version: ${{ inputs.android_version }}
  116. - name: DroidSpaces-OSS Patches
  117. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  118. uses: ./.github/actions/droidspaces
  119. with:
  120. version: ${{ inputs.version }}
  121. kernel_version: ${{ inputs.kernel_version }}
  122. - name: Setup Misc Configs
  123. uses: ./.github/actions/misc
  124. with:
  125. version: ${{ inputs.version }}
  126. kernel_version: ${{ inputs.kernel_version }}
  127. android_version: ${{ inputs.android_version }}
  128. sublevel: ${{ steps.extract.outputs.sublevel }}
  129. variant: ${{ inputs.variant }}
  130. - name: Apply Module Check Bypass
  131. if: ${{ inputs.variant == 'Bypass' }}
  132. uses: ./.github/actions/module-check-bypass
  133. with:
  134. kernel_version: ${{ inputs.kernel_version }}
  135. # - name: Apply Device-Specific Patches
  136. # uses: ./.github/actions/apply-device-patches
  137. # with:
  138. # version: ${{ inputs.version }}
  139. # kernel_version: ${{ inputs.kernel_version }}
  140. - name: Apply ABI Compare Bypass
  141. if: false
  142. working-directory: ${{ github.workspace }}/kernel
  143. run: |
  144. # ABI compare bypass per kernel/android version
  145. # Edit each block as needed per version
  146. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  147. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  148. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  149. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  150. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  151. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  152. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  153. 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
  154. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  155. 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
  156. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  157. 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
  158. fi
  159. - name: Apply Kernel Branding
  160. uses: ./.github/actions/apply-kernel-branding
  161. with:
  162. variant: ${{ inputs.variant }}
  163. kernel_version: ${{ inputs.kernel_version }}
  164. android_version: ${{ inputs.android_version }}
  165. sublevel: ${{ steps.extract.outputs.sublevel }}
  166. - name: Remove Protected Exports
  167. uses: ./.github/actions/remove-protected-exports
  168. - name: Clean Kernel Flags
  169. uses: ./.github/actions/clean-kernel-flags
  170. - name: Scan and collect patch rejects
  171. id: scan
  172. if: ${{ always() && inputs.variant == 'Normal' }}
  173. uses: ./.github/actions/scan-patch-rejects
  174. - name: Upload Rejects
  175. if: ${{ always() && inputs.variant == 'Normal' }}
  176. uses: actions/upload-artifact@v7
  177. with:
  178. name: ${{ steps.extract.outputs.file_name }}-Rejects
  179. path: patch-rejects/
  180. if-no-files-found: ignore
  181. compression-level: 9
  182. - name: 'Setup Cache and Build Environment'
  183. uses: ./.github/actions/cache-setup
  184. with:
  185. version: ${{ inputs.version }}
  186. android_version: ${{ inputs.android_version }}
  187. kernel_version: ${{ inputs.kernel_version }}
  188. sublevel: ${{ steps.extract.outputs.sublevel }}
  189. - name: Restore ccache
  190. id: restore-ccache
  191. if: |
  192. inputs.version == 'android12-5.10' ||
  193. inputs.version == 'android13-5.10' ||
  194. inputs.version == 'android13-5.15'
  195. uses: ./.github/actions/cache-restore
  196. with:
  197. cache_path: /home/runner/.ccache
  198. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  199. cache_bucket: ccache-cache
  200. compression_level: 9
  201. restore_keys: |
  202. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  203. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  204. - name: Restore lto-cache (ccache versions)
  205. id: restore-lto-ccache
  206. if: |
  207. inputs.version == 'android12-5.10' ||
  208. inputs.version == 'android13-5.10' ||
  209. inputs.version == 'android13-5.15'
  210. uses: ./.github/actions/cache-restore
  211. with:
  212. cache_path: /home/runner/.ld_cache
  213. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  214. cache_bucket: lto-cache
  215. compression_level: 9
  216. restore_keys: |
  217. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  218. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  219. - name: Restore bazel-cache
  220. id: restore-bazel
  221. if: |
  222. inputs.version == 'android14-5.15' ||
  223. inputs.version == 'android14-6.1' ||
  224. inputs.version == 'android15-6.6' ||
  225. inputs.version == 'android16-6.12'
  226. uses: ./.github/actions/cache-restore
  227. with:
  228. cache_path: /home/runner/.cache/bazel
  229. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  230. cache_bucket: bazel-cache
  231. compression_level: 9
  232. restore_keys: |
  233. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  234. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  235. - name: Restore lto-cache (bazel versions)
  236. id: restore-lto-bazel
  237. if: |
  238. inputs.version == 'android14-5.15' ||
  239. inputs.version == 'android14-6.1' ||
  240. inputs.version == 'android15-6.6' ||
  241. inputs.version == 'android16-6.12'
  242. uses: ./.github/actions/cache-restore
  243. with:
  244. cache_path: /home/runner/.ld_cache
  245. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  246. cache_bucket: lto-cache
  247. compression_level: 9
  248. restore_keys: |
  249. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  250. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  251. - name: Check cache hit
  252. run: |
  253. echo "Cache restore status:" CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  254. LTO_CCACHE_HIT="${{ steps.restore-lto-ccache.outputs.cache-hit || 'skipped' }}"
  255. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  256. LTO_BAZEL_HIT="${{ steps.restore-lto-bazel.outputs.cache-hit || 'skipped' }}"
  257. echo " ccache: $CCACHE_HIT"
  258. echo " lto (ccache versions): $LTO_CCACHE_HIT"
  259. echo " bazel: $BAZEL_HIT"
  260. echo " lto (bazel versions): $LTO_BAZEL_HIT"
  261. - name: Get Cache Stats
  262. uses: ./.github/actions/cache-stats
  263. with:
  264. clear_stats: true
  265. - name: Build Kernel
  266. env:
  267. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  268. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  269. uses: ./.github/actions/build-kernel
  270. - name: Get Cache Stats
  271. uses: ./.github/actions/cache-stats
  272. with:
  273. clear_stats: false
  274. - name: Save ccache
  275. if: |
  276. inputs.version == 'android12-5.10' ||
  277. inputs.version == 'android13-5.10' ||
  278. inputs.version == 'android13-5.15'
  279. uses: ./.github/actions/cache-save
  280. with:
  281. cache_path: /home/runner/.ccache
  282. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  283. cache_bucket: ccache-cache
  284. compression_level: 9
  285. github_token: ${{ secrets.GITHUB_TOKEN }}
  286. - name: Save lto-cache (ccache versions)
  287. if: |
  288. inputs.version == 'android12-5.10' ||
  289. inputs.version == 'android13-5.10' ||
  290. inputs.version == 'android13-5.15'
  291. uses: ./.github/actions/cache-save
  292. with:
  293. cache_path: /home/runner/.ld_cache
  294. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  295. cache_bucket: lto-cache
  296. compression_level: 9
  297. github_token: ${{ secrets.GITHUB_TOKEN }}
  298. - name: Save bazel-cache
  299. if: |
  300. inputs.version == 'android14-5.15' ||
  301. inputs.version == 'android14-6.1' ||
  302. inputs.version == 'android15-6.6' ||
  303. inputs.version == 'android16-6.12'
  304. uses: ./.github/actions/cache-save
  305. with:
  306. cache_path: /home/runner/.cache/bazel
  307. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  308. cache_bucket: bazel-cache
  309. compression_level: 9
  310. github_token: ${{ secrets.GITHUB_TOKEN }}
  311. - name: Save lto-cache (bazel versions)
  312. if: |
  313. inputs.version == 'android14-5.15' ||
  314. inputs.version == 'android14-6.1' ||
  315. inputs.version == 'android15-6.6' ||
  316. inputs.version == 'android16-6.12'
  317. uses: ./.github/actions/cache-save
  318. with:
  319. cache_path: /home/runner/.ld_cache
  320. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  321. cache_bucket: lto-cache
  322. compression_level: 9
  323. github_token: ${{ secrets.GITHUB_TOKEN }}
  324. - name: Create Bootimgs Folder and Build Boot Images
  325. uses: ./.github/actions/build-boot-images
  326. with:
  327. android_version: ${{ inputs.android_version }}
  328. kernel_version: ${{ inputs.kernel_version }}
  329. os_patch_level: ${{ inputs.os_patch_level }}
  330. file_name: ${{ steps.extract.outputs.file_name }}
  331. - name: Upload Boot Image (.img)
  332. uses: actions/upload-artifact@v7
  333. with:
  334. name: ${{ steps.extract.outputs.file_name }}-boot.img
  335. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  336. if-no-files-found: error
  337. archive: false
  338. - name: Upload Boot Image (.img.gz)
  339. uses: actions/upload-artifact@v7
  340. with:
  341. name: ${{ steps.extract.outputs.file_name }}-boot-gz.img
  342. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  343. if-no-files-found: error
  344. archive: false
  345. - name: Upload Boot Image (.img.lz4)
  346. uses: actions/upload-artifact@v7
  347. with:
  348. name: ${{ steps.extract.outputs.file_name }}-boot-lz4.img
  349. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  350. if-no-files-found: error
  351. archive: false
  352. - name: Prepare AnyKernel3 Zip
  353. uses: ./.github/actions/prepare-anykernel3
  354. with:
  355. android_version: ${{ inputs.android_version }}
  356. kernel_version: ${{ inputs.kernel_version }}
  357. - name: Upload Artifacts
  358. uses: actions/upload-artifact@v7
  359. with:
  360. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  361. path: ${{ github.workspace }}/AnyKernel3/**
  362. if-no-files-found: ignore
  363. compression-level: 9