build.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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: 🧹 Emergency Disk Cleanup
  41. if: false
  42. uses: ./.github/actions/disk-cleanup
  43. - name: Free Disk Space
  44. if: true
  45. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  46. with:
  47. remove_android: true
  48. remove_dotnet: true
  49. remove_haskell: true
  50. remove_tool_cache: true
  51. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  52. remove_packages_one_command: true
  53. 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"
  54. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  55. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  56. testing: false
  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: Setup Build Environment
  63. uses: ./.github/actions/setup-build-environment
  64. env:
  65. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  66. - name: Download Kernel Repository
  67. uses: ./.github/actions/download-kernel
  68. with:
  69. version: ${{ inputs.version }}
  70. android_version: ${{ inputs.android_version }}
  71. kernel_version: ${{ inputs.kernel_version }}
  72. os_patch_level: ${{ inputs.os_patch_level }}
  73. use_repo: ${{ inputs.use_repo }}
  74. - name: Set Build Timestamp from Kernel Commit
  75. shell: bash
  76. run: |
  77. set -x
  78. # Hardcode the build timestamp to the 5th day of the patch level
  79. # at 04:20 UTC, using the existing timestamp formats expected by the build.
  80. FIXED_BUILD_DATE="${{ inputs.os_patch_level }}-05 04:20:00 UTC"
  81. SOURCE_DATE_EPOCH=$(date -u -d "$FIXED_BUILD_DATE" +%s)
  82. echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
  83. KBUILD_TS=$(date -u -d @${SOURCE_DATE_EPOCH} '+%a %b %d %H:%M:%S UTC %Y')
  84. echo "KBUILD_BUILD_TIMESTAMP=${KBUILD_TS}" >> $GITHUB_ENV
  85. # Keep git metadata aligned with the same fixed timestamp.
  86. GIT_DATE=$(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%dT%H:%M:%SZ')
  87. echo "GIT_COMMITTER_DATE=${GIT_DATE}" >> $GITHUB_ENV
  88. echo "GIT_AUTHOR_DATE=${GIT_DATE}" >> $GITHUB_ENV
  89. echo "Build timestamp set to: $(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S UTC') (epoch: $SOURCE_DATE_EPOCH)"
  90. - name: Extract Sublevel and Set File Name
  91. id: extract
  92. uses: ./.github/actions/extract-sublevel-file-name
  93. with:
  94. android_version: ${{ inputs.android_version }}
  95. kernel_version: ${{ inputs.kernel_version }}
  96. sublevel: ${{ inputs.sublevel }}
  97. os_patch_level: ${{ inputs.os_patch_level }}
  98. variant: ${{ inputs.variant }}
  99. - name: Kernel Fixes
  100. uses: ./.github/actions/kernel-fixes
  101. with:
  102. version: ${{ inputs.version }}
  103. android_version: ${{ inputs.android_version }}
  104. kernel_version: ${{ inputs.kernel_version }}
  105. sublevel: ${{ steps.extract.outputs.sublevel }}
  106. os_patch_level: ${{ inputs.os_patch_level }}
  107. - name: Setup KernelSU-Next
  108. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  109. uses: ./.github/actions/kernelsu
  110. - name: SUSFS
  111. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  112. uses: ./.github/actions/susfs
  113. with:
  114. version: ${{ inputs.version }}
  115. android_version: ${{ inputs.android_version }}
  116. kernel_version: ${{ inputs.kernel_version }}
  117. os_patch_level: ${{ inputs.os_patch_level }}
  118. sublevel: ${{ steps.extract.outputs.sublevel }}
  119. - name: Baseband Guard
  120. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL')
  121. uses: ./.github/actions/bbg
  122. - name: Setup Networking
  123. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  124. uses: ./.github/actions/networking
  125. with:
  126. kernel_version: ${{ inputs.kernel_version }}
  127. android_version: ${{ inputs.android_version }}
  128. - name: DroidSpaces-OSS Patches
  129. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  130. uses: ./.github/actions/droidspaces
  131. with:
  132. version: ${{ inputs.version }}
  133. kernel_version: ${{ inputs.kernel_version }}
  134. - name: Setup Misc Configs
  135. uses: ./.github/actions/misc
  136. with:
  137. version: ${{ inputs.version }}
  138. kernel_version: ${{ inputs.kernel_version }}
  139. android_version: ${{ inputs.android_version }}
  140. sublevel: ${{ steps.extract.outputs.sublevel }}
  141. variant: ${{ inputs.variant }}
  142. - name: Apply Device-Specific Patches
  143. uses: ./.github/actions/apply-device-patches
  144. with:
  145. version: ${{ inputs.version }}
  146. kernel_version: ${{ inputs.kernel_version }}
  147. - name: Apply ABI Compare Bypass
  148. if: false
  149. working-directory: ${{ github.workspace }}/kernel
  150. run: |
  151. # ABI compare bypass per kernel/android version
  152. # Edit each block as needed per version
  153. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  154. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  155. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  156. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  157. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  158. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  159. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  160. 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
  161. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  162. 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
  163. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  164. 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
  165. fi
  166. - name: Apply Kernel Branding
  167. uses: ./.github/actions/apply-kernel-branding
  168. with:
  169. variant: ${{ inputs.variant }}
  170. kernel_version: ${{ inputs.kernel_version }}
  171. android_version: ${{ inputs.android_version }}
  172. sublevel: ${{ steps.extract.outputs.sublevel }}
  173. - name: Remove Protected Exports
  174. uses: ./.github/actions/remove-protected-exports
  175. - name: Clean Kernel Flags
  176. uses: ./.github/actions/clean-kernel-flags
  177. - name: Scan and collect patch rejects
  178. id: scan
  179. if: ${{ always() && inputs.variant == 'Normal' }}
  180. uses: ./.github/actions/scan-patch-rejects
  181. - name: Upload Rejects
  182. if: ${{ always() && inputs.variant == 'Normal' }}
  183. uses: actions/upload-artifact@v7
  184. with:
  185. name: ${{ steps.extract.outputs.file_name }}-Rejects
  186. path: patch-rejects/
  187. if-no-files-found: ignore
  188. compression-level: 9
  189. - name: 'Setup Cache and Build Environment'
  190. uses: ./.github/actions/cache-setup
  191. with:
  192. version: ${{ inputs.version }}
  193. android_version: ${{ inputs.android_version }}
  194. kernel_version: ${{ inputs.kernel_version }}
  195. sublevel: ${{ steps.extract.outputs.sublevel }}
  196. - name: Restore ccache
  197. id: restore-ccache
  198. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  199. uses: ./.github/actions/cache-restore
  200. with:
  201. cache_path: /home/runner/.ccache
  202. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  203. cache_bucket: ccache-cache
  204. compression_level: 9
  205. restore_keys: |
  206. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  207. - name: Restore lto-cache (ccache versions)
  208. id: restore-lto-ccache
  209. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || 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. - name: Restore bazel-cache
  219. id: restore-bazel
  220. if: inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12'
  221. uses: ./.github/actions/cache-restore
  222. with:
  223. cache_path: /home/runner/.cache/bazel
  224. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  225. cache_bucket: bazel-cache
  226. compression_level: 9
  227. restore_keys: |
  228. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  229. - name: Check cache hit
  230. run: |
  231. echo "Cache restore status:" CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  232. LTO_CCACHE_HIT="${{ steps.restore-lto-ccache.outputs.cache-hit || 'skipped' }}"
  233. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  234. LTO_BAZEL_HIT="${{ steps.restore-lto-bazel.outputs.cache-hit || 'skipped' }}"
  235. echo " ccache: $CCACHE_HIT"
  236. echo " lto (ccache versions): $LTO_CCACHE_HIT"
  237. echo " bazel: $BAZEL_HIT"
  238. echo " lto (bazel versions): $LTO_BAZEL_HIT"
  239. - name: Get Cache Stats
  240. uses: ./.github/actions/cache-stats
  241. with:
  242. clear_stats: true
  243. - name: Build Normal Kernel
  244. env:
  245. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  246. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  247. uses: ./.github/actions/build-kernel
  248. with:
  249. version: ${{ inputs.version }}
  250. bypass: false
  251. - name: Get Cache Stats
  252. uses: ./.github/actions/cache-stats
  253. with:
  254. clear_stats: false
  255. - name: Save ccache
  256. uses: ./.github/actions/cache-save
  257. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  258. with:
  259. cache_path: /home/runner/.ccache
  260. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  261. cache_bucket: ccache-cache
  262. compression_level: 9
  263. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  264. - name: Save lto-cache
  265. uses: ./.github/actions/cache-save
  266. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  267. with:
  268. cache_path: /home/runner/.ld_cache
  269. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  270. cache_bucket: lto-cache
  271. compression_level: 9
  272. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  273. - name: Save bazel-cache
  274. uses: ./.github/actions/cache-save
  275. if: inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12'
  276. with:
  277. cache_path: /home/runner/.cache/bazel
  278. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  279. cache_bucket: bazel-cache
  280. compression_level: 9
  281. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  282. - name: Build Bypass Kernel
  283. env:
  284. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  285. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  286. uses: ./.github/actions/build-kernel
  287. with:
  288. bypass: true
  289. version: ${{ inputs.version }}
  290. - name: Upload Artifacts
  291. uses: actions/upload-artifact@v7
  292. with:
  293. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  294. path: ${{ github.workspace }}/AnyKernel3/**
  295. if-no-files-found: ignore
  296. compression-level: 9