build.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. # Verify kernel/common exists and is a git repo
  79. if [ ! -d "${{ github.workspace }}/kernel/common" ]; then
  80. echo "ERROR: kernel/common directory does not exist!"
  81. echo "Contents of kernel/:"
  82. ls -la "${{ github.workspace }}/kernel/" || true
  83. exit 1
  84. fi
  85. if [ ! -d "${{ github.workspace }}/kernel/common/.git" ]; then
  86. echo "ERROR: kernel/common is not a git repository!"
  87. exit 1
  88. fi
  89. # Try to get commit timestamp
  90. SOURCE_DATE_EPOCH=$(git -C "${{ github.workspace }}/kernel/common" log -1 --format=%ct 2>&1)
  91. if [ -z "$SOURCE_DATE_EPOCH" ] || [ "$SOURCE_DATE_EPOCH" = "0" ]; then
  92. echo "WARNING: Failed to get commit timestamp from kernel/common, using current time"
  93. SOURCE_DATE_EPOCH=$(date -u +%s)
  94. fi
  95. echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
  96. KBUILD_TS=$(date -u -d @${SOURCE_DATE_EPOCH} '+%a %b %d %H:%M:%S UTC %Y')
  97. echo "KBUILD_BUILD_TIMESTAMP=${KBUILD_TS}" >> $GITHUB_ENV
  98. # Set git author/committer date so any commits done by actions use this timestamp
  99. GIT_DATE=$(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%dT%H:%M:%SZ')
  100. echo "GIT_COMMITTER_DATE=${GIT_DATE}" >> $GITHUB_ENV
  101. echo "GIT_AUTHOR_DATE=${GIT_DATE}" >> $GITHUB_ENV
  102. echo "Build timestamp set to: $(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S UTC') (epoch: $SOURCE_DATE_EPOCH)"
  103. - name: Extract Sublevel and Set File Name
  104. id: extract
  105. uses: ./.github/actions/extract-sublevel-file-name
  106. with:
  107. android_version: ${{ inputs.android_version }}
  108. kernel_version: ${{ inputs.kernel_version }}
  109. sublevel: ${{ inputs.sublevel }}
  110. os_patch_level: ${{ inputs.os_patch_level }}
  111. variant: ${{ inputs.variant }}
  112. - name: Kernel Fixes
  113. uses: ./.github/actions/kernel-fixes
  114. with:
  115. version: ${{ inputs.version }}
  116. android_version: ${{ inputs.android_version }}
  117. kernel_version: ${{ inputs.kernel_version }}
  118. sublevel: ${{ steps.extract.outputs.sublevel }}
  119. os_patch_level: ${{ inputs.os_patch_level }}
  120. - name: Setup KernelSU-Next
  121. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  122. uses: ./.github/actions/kernelsu
  123. - name: SUSFS
  124. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  125. uses: ./.github/actions/susfs
  126. with:
  127. version: ${{ inputs.version }}
  128. android_version: ${{ inputs.android_version }}
  129. kernel_version: ${{ inputs.kernel_version }}
  130. os_patch_level: ${{ inputs.os_patch_level }}
  131. sublevel: ${{ steps.extract.outputs.sublevel }}
  132. - name: Baseband Guard
  133. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL')
  134. uses: ./.github/actions/bbg
  135. - name: Setup Networking
  136. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  137. uses: ./.github/actions/networking
  138. with:
  139. kernel_version: ${{ inputs.kernel_version }}
  140. android_version: ${{ inputs.android_version }}
  141. - name: DroidSpaces-OSS Patches
  142. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  143. uses: ./.github/actions/droidspaces
  144. with:
  145. version: ${{ inputs.version }}
  146. kernel_version: ${{ inputs.kernel_version }}
  147. - name: Setup Misc Configs
  148. uses: ./.github/actions/misc
  149. with:
  150. version: ${{ inputs.version }}
  151. kernel_version: ${{ inputs.kernel_version }}
  152. android_version: ${{ inputs.android_version }}
  153. sublevel: ${{ steps.extract.outputs.sublevel }}
  154. variant: ${{ inputs.variant }}
  155. - name: Apply Device-Specific Patches
  156. uses: ./.github/actions/apply-device-patches
  157. with:
  158. version: ${{ inputs.version }}
  159. kernel_version: ${{ inputs.kernel_version }}
  160. - name: Apply ABI Compare Bypass
  161. if: false
  162. working-directory: ${{ github.workspace }}/kernel
  163. run: |
  164. # ABI compare bypass per kernel/android version
  165. # Edit each block as needed per version
  166. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  167. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  168. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  169. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  170. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  171. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  172. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  173. 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
  174. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  175. 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
  176. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  177. 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
  178. fi
  179. - name: Apply Kernel Branding
  180. uses: ./.github/actions/apply-kernel-branding
  181. with:
  182. variant: ${{ inputs.variant }}
  183. kernel_version: ${{ inputs.kernel_version }}
  184. android_version: ${{ inputs.android_version }}
  185. sublevel: ${{ steps.extract.outputs.sublevel }}
  186. - name: Remove Protected Exports
  187. uses: ./.github/actions/remove-protected-exports
  188. - name: Clean Kernel Flags
  189. uses: ./.github/actions/clean-kernel-flags
  190. - name: Scan and collect patch rejects
  191. id: scan
  192. if: ${{ always() && inputs.variant == 'Normal' }}
  193. uses: ./.github/actions/scan-patch-rejects
  194. - name: Upload Rejects
  195. if: ${{ always() && inputs.variant == 'Normal' }}
  196. uses: actions/upload-artifact@v7
  197. with:
  198. name: ${{ steps.extract.outputs.file_name }}-Rejects
  199. path: patch-rejects/
  200. if-no-files-found: ignore
  201. compression-level: 9
  202. - name: 'Setup Cache and Build Environment'
  203. uses: ./.github/actions/cache-setup
  204. with:
  205. version: ${{ inputs.version }}
  206. android_version: ${{ inputs.android_version }}
  207. kernel_version: ${{ inputs.kernel_version }}
  208. sublevel: ${{ steps.extract.outputs.sublevel }}
  209. - name: Restore ccache
  210. id: restore-ccache
  211. if: false
  212. uses: ./.github/actions/cache-restore
  213. with:
  214. cache_path: /home/runner/.ccache
  215. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  216. cache_bucket: ccache-cache
  217. compression_level: 9
  218. restore_keys: |
  219. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  220. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  221. - name: Restore lto-cache (ccache versions)
  222. id: restore-lto-ccache
  223. if: false
  224. uses: ./.github/actions/cache-restore
  225. with:
  226. cache_path: /home/runner/.ld_cache
  227. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  228. cache_bucket: lto-cache
  229. compression_level: 9
  230. restore_keys: |
  231. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  232. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  233. - name: Restore bazel-cache
  234. id: restore-bazel
  235. uses: ./.github/actions/cache-restore
  236. with:
  237. cache_path: /home/runner/.cache/bazel
  238. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  239. cache_bucket: bazel-cache
  240. compression_level: 9
  241. restore_keys: |
  242. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  243. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  244. - name: Restore lto-cache (bazel versions)
  245. id: restore-lto-bazel
  246. uses: ./.github/actions/cache-restore
  247. with:
  248. cache_path: /home/runner/.ld_cache
  249. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  250. cache_bucket: lto-cache
  251. compression_level: 9
  252. restore_keys: |
  253. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  254. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  255. - name: Check cache hit
  256. run: |
  257. echo "Cache restore status:" CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  258. LTO_CCACHE_HIT="${{ steps.restore-lto-ccache.outputs.cache-hit || 'skipped' }}"
  259. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  260. LTO_BAZEL_HIT="${{ steps.restore-lto-bazel.outputs.cache-hit || 'skipped' }}"
  261. echo " ccache: $CCACHE_HIT"
  262. echo " lto (ccache versions): $LTO_CCACHE_HIT"
  263. echo " bazel: $BAZEL_HIT"
  264. echo " lto (bazel versions): $LTO_BAZEL_HIT"
  265. - name: Get Cache Stats
  266. uses: ./.github/actions/cache-stats
  267. with:
  268. clear_stats: true
  269. - name: Build Normal Kernel
  270. env:
  271. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  272. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  273. uses: ./.github/actions/build-kernel
  274. with:
  275. version: ${{ inputs.version }}
  276. bypass: false
  277. - name: Get Cache Stats
  278. uses: ./.github/actions/cache-stats
  279. with:
  280. clear_stats: false
  281. - name: Save ccache
  282. uses: ./.github/actions/cache-save
  283. with:
  284. cache_path: /home/runner/.ccache
  285. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  286. cache_bucket: ccache-cache
  287. compression_level: 9
  288. github_token: ${{ secrets.GITHUB_TOKEN }}
  289. - name: Save lto-cache
  290. uses: ./.github/actions/cache-save
  291. with:
  292. cache_path: /home/runner/.ld_cache
  293. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  294. cache_bucket: lto-cache
  295. compression_level: 9
  296. github_token: ${{ secrets.GITHUB_TOKEN }}
  297. - name: Save bazel-cache
  298. uses: ./.github/actions/cache-save
  299. with:
  300. cache_path: /home/runner/.cache/bazel
  301. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  302. cache_bucket: bazel-cache
  303. compression_level: 9
  304. github_token: ${{ secrets.GITHUB_TOKEN }}
  305. - name: Build Bypass Kernel
  306. env:
  307. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  308. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  309. uses: ./.github/actions/build-kernel
  310. with:
  311. bypass: true
  312. version: ${{ inputs.version }}
  313. - name: Upload Artifacts
  314. uses: actions/upload-artifact@v7
  315. with:
  316. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  317. path: ${{ github.workspace }}/AnyKernel3/**
  318. if-no-files-found: ignore
  319. compression-level: 9