build.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. ksu_commit:
  15. required: false
  16. type: string
  17. anykernel_commit:
  18. required: false
  19. type: string
  20. patches_commit:
  21. required: false
  22. type: string
  23. susfs_commit:
  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.variant }})"
  35. runs-on: ubuntu-latest
  36. timeout-minutes: 60
  37. steps:
  38. - name: Checkout Repository
  39. uses: actions/checkout@v5
  40. - name: Parse kernel version
  41. id: parse
  42. uses: ./.github/actions/parse-kernel-version
  43. with:
  44. kernel_version: ${{ inputs.kernel_version }}
  45. - name: Free Disk Space
  46. if: true
  47. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  48. with:
  49. remove_android: true
  50. remove_dotnet: true
  51. remove_haskell: true
  52. remove_tool_cache: true
  53. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  54. remove_packages_one_command: true
  55. 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"
  56. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  57. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  58. testing: false
  59. - name: Setup more Swap (for LTO)
  60. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  61. with:
  62. swap-size-gb: 25 # 10-24 GB is common for heavy LTO
  63. # swap-space-path: /mnt/swapfile # optional
  64. - name: Setup Build Environment
  65. uses: ./.github/actions/setup-build-environment
  66. env:
  67. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  68. with:
  69. patches_commit: ${{ inputs.patches_commit }}
  70. anykernel_commit: ${{ inputs.anykernel_commit }}
  71. - name: Download Kernel Repository
  72. uses: ./.github/actions/download-kernel
  73. with:
  74. android_version: ${{ steps.parse.outputs.android_version }}
  75. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  76. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  77. use_repo: ${{ inputs.use_repo }}
  78. - name: Grep for vm_flags_clear after download
  79. run: |
  80. grep -n 'vm_flags_clear' ${{ github.workspace }}/kernel/common/mm/mmap.c || echo 'Not found'
  81. - name: Extract Sublevel and Set File Name
  82. id: extract
  83. uses: ./.github/actions/extract-sublevel-file-name
  84. with:
  85. variant: ${{ matrix.variant }}
  86. - name: Kernel Fixes
  87. uses: ./.github/actions/kernel-fixes
  88. with:
  89. android_version: ${{ steps.parse.outputs.android_version }}
  90. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  91. sublevel: ${{ steps.extract.outputs.sublevel }}
  92. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  93. - name: Setup KernelSU-Next
  94. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  95. uses: ./.github/actions/kernelsu
  96. with:
  97. ksu_commit: ${{ inputs.ksu_commit }}
  98. - name: SUSFS
  99. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  100. uses: ./.github/actions/susfs
  101. with:
  102. android_version: ${{ steps.parse.outputs.android_version }}
  103. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  104. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  105. sublevel: ${{ steps.extract.outputs.sublevel }}
  106. susfs_commit: ${{ inputs.susfs_commit }}
  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: ${{ steps.parse.outputs.kernel_version }}
  115. android_version: ${{ steps.parse.outputs.android_version }}
  116. - name: Setup Misc Configs
  117. uses: ./.github/actions/misc
  118. with:
  119. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  120. android_version: ${{ steps.parse.outputs.android_version }}
  121. - name: Apply Module Check Bypass
  122. if: ${{ matrix.variant == 'Bypass' }}
  123. uses: ./.github/actions/module-check-bypass
  124. with:
  125. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  126. - name: Apply Device-Specific Patches
  127. uses: ./.github/actions/apply-device-patches
  128. with:
  129. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  130. - name: Apply ABI Compare Bypass
  131. if: false
  132. working-directory: ${{ github.workspace }}/kernel
  133. run: |
  134. # ABI compare bypass per kernel/android version
  135. # Edit each block as needed per version
  136. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  137. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  138. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  139. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  140. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  141. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  142. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  143. 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
  144. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  145. 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
  146. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  147. 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
  148. fi
  149. - name: Apply Kernel Branding
  150. uses: ./.github/actions/apply-kernel-branding
  151. with:
  152. variant: ${{ matrix.variant }}
  153. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  154. android_version: ${{ steps.parse.outputs.android_version }}
  155. sublevel: ${{ steps.extract.outputs.sublevel }}
  156. - name: Remove Protected Exports
  157. uses: ./.github/actions/remove-protected-exports
  158. - name: Clean Kernel Flags
  159. uses: ./.github/actions/clean-kernel-flags
  160. - name: Scan and collect patch rejects
  161. id: scan
  162. if: ${{ always() && inputs.variant == 'Normal' }}
  163. uses: ./.github/actions/scan-patch-rejects
  164. - name: Upload Rejects
  165. if: ${{ always() && inputs.variant == 'Normal' }}
  166. uses: actions/upload-artifact@v7
  167. with:
  168. name: ${{ steps.extract.outputs.file_name }}-Rejects
  169. path: patch-rejects/
  170. if-no-files-found: ignore
  171. compression-level: 9
  172. - name: Grep for vm_flags_clear before build
  173. run: |
  174. grep -n 'vm_flags_clear' ${{ github.workspace }}/kernel/common/mm/mmap.c || echo 'Not found'
  175. - name: Restore build caches (ccache, Bazel)
  176. uses: actions/cache@v4
  177. with:
  178. path: |
  179. .ccache
  180. bazel-*
  181. .cache/bazel
  182. key: buildcache-${{ inputs.kernel_version }}
  183. restore-keys: |
  184. buildcache-
  185. - name: ♻️ Configure ccache (bounded)
  186. run: |
  187. echo "::group::Configure ccache environment"
  188. set -euo pipefail
  189. if command -v ccache >/dev/null 2>&1; then
  190. CACHE_DIR="${{ github.workspace }}/.ccache"
  191. mkdir -p "$CACHE_DIR"
  192. SETTINGS=(
  193. "CCACHE_DIR=$CACHE_DIR"
  194. "CCACHE_MAXSIZE=1G"
  195. "CCACHE_COMPILERCHECK=content"
  196. "CCACHE_BASEDIR=${GITHUB_WORKSPACE}"
  197. "CCACHE_NOHASHDIR=true"
  198. "CCACHE_IGNOREOPTIONS=--sysroot*"
  199. "CCACHE_COMPRESSION=true"
  200. "CCACHE_COMPRESSION_LEVEL=3"
  201. "CCACHE_DIRECT=true"
  202. "CCACHE_FILE_CLONE=true"
  203. "CCACHE_INODE_CACHE=true"
  204. "CCACHE_UMASK=002"
  205. "CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
  206. )
  207. for setting in "${SETTINGS[@]}"; do
  208. export "$setting"
  209. echo "$setting" >> "$GITHUB_ENV"
  210. done
  211. if ccache --help 2>&1 | grep -q 'depend_mode'; then
  212. export CCACHE_DEPEND=true
  213. echo "CCACHE_DEPEND=true" >> "$GITHUB_ENV"
  214. fi
  215. echo "✅ ccache configured successfully"
  216. echo "Current ccache configuration:"
  217. ccache -p
  218. else
  219. echo "ccache not found, skipping configuration."
  220. fi
  221. echo "::endgroup::"
  222. - name: Build Kernel
  223. env:
  224. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  225. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  226. uses: ./.github/actions/build-kernel
  227. - name: Save build caches (ccache, Bazel)
  228. if: always()
  229. uses: actions/cache@v4
  230. with:
  231. path: |
  232. .ccache
  233. bazel-*
  234. .cache/bazel
  235. key: buildcache-${{ inputs.kernel_version }}
  236. - name: Create Bootimgs Folder and Build Boot Images
  237. uses: ./.github/actions/build-boot-images
  238. - name: Upload Boot Image (boot.img)
  239. uses: actions/upload-artifact@v7
  240. with:
  241. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  242. if-no-files-found: error
  243. archive: false
  244. - name: Upload Boot Image (boot-gz.img)
  245. uses: actions/upload-artifact@v7
  246. with:
  247. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  248. if-no-files-found: error
  249. archive: false
  250. - name: Upload Boot Image (boot-lz4.img)
  251. uses: actions/upload-artifact@v7
  252. with:
  253. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  254. if-no-files-found: error
  255. archive: false
  256. - name: Prepare AnyKernel3 Zip
  257. uses: ./.github/actions/prepare-anykernel3
  258. - name: Upload Artifacts
  259. uses: actions/upload-artifact@v7
  260. with:
  261. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  262. path: ${{ github.workspace }}/AnyKernel3/**
  263. if-no-files-found: ignore
  264. compression-level: 9