build.yml 16 KB

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