build.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. feature_set:
  15. required: true
  16. type: string
  17. use_repo:
  18. required: false
  19. type: boolean
  20. jobs:
  21. build-gki:
  22. name: "${{ inputs.kernel_version }} (${{ inputs.variant }})"
  23. runs-on: ubuntu-latest
  24. timeout-minutes: 60
  25. steps:
  26. - name: Checkout Repository
  27. uses: actions/checkout@v5
  28. - name: Parse kernel version
  29. id: parse
  30. uses: ./.github/actions/parse-kernel-version
  31. with:
  32. kernel_version: ${{ inputs.kernel_version }}
  33. - name: Free Disk Space
  34. if: true
  35. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  36. with:
  37. remove_android: true
  38. remove_dotnet: true
  39. remove_haskell: true
  40. remove_tool_cache: true
  41. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  42. remove_packages_one_command: true
  43. 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"
  44. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  45. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  46. testing: false
  47. - name: Setup more Swap (for LTO)
  48. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  49. with:
  50. swap-size-gb: 10 # 10-24 GB is common for heavy LTO
  51. # swap-space-path: /mnt/swapfile # optional
  52. - name: Setup Build Environment
  53. uses: ./.github/actions/setup-build-environment
  54. env:
  55. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  56. - name: Download Kernel Repository
  57. uses: ./.github/actions/download-kernel
  58. with:
  59. android_version: ${{ steps.parse.outputs.android_version }}
  60. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  61. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  62. use_repo: ${{ inputs.use_repo }}
  63. - name: Extract Sublevel and Set File Name
  64. id: extract
  65. uses: ./.github/actions/extract-sublevel-file-name
  66. with:
  67. variant: ${{ inputs.variant }}
  68. - name: Kernel Fixes
  69. uses: ./.github/actions/kernel-fixes
  70. with:
  71. android_version: ${{ steps.parse.outputs.android_version }}
  72. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  73. sublevel: ${{ steps.extract.outputs.sublevel }}
  74. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  75. - name: Setup KernelSU-Next
  76. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  77. uses: ./.github/actions/kernelsu
  78. - name: SUSFS
  79. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  80. uses: ./.github/actions/susfs
  81. with:
  82. android_version: ${{ steps.parse.outputs.android_version }}
  83. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  84. os_patch_level: ${{ steps.parse.outputs.os_patch_level }}
  85. sublevel: ${{ steps.extract.outputs.sublevel }}
  86. - name: Baseband Guard
  87. if: contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL'
  88. uses: ./.github/actions/bbg
  89. - name: Setup Networking
  90. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  91. uses: ./.github/actions/networking
  92. with:
  93. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  94. android_version: ${{ steps.parse.outputs.android_version }}
  95. - name: DroidSpaces-OSS Patches
  96. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  97. uses: ./.github/actions/droidspaces
  98. with:
  99. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  100. - name: Setup Misc Configs
  101. uses: ./.github/actions/misc
  102. with:
  103. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  104. android_version: ${{ steps.parse.outputs.android_version }}
  105. - name: Apply Module Check Bypass
  106. if: ${{ inputs.variant == 'Bypass' }}
  107. uses: ./.github/actions/module-check-bypass
  108. with:
  109. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  110. - name: Apply Device-Specific Patches
  111. uses: ./.github/actions/apply-device-patches
  112. with:
  113. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  114. - name: Apply ABI Compare Bypass
  115. if: false
  116. working-directory: ${{ github.workspace }}/kernel
  117. run: |
  118. # ABI compare bypass per kernel/android version
  119. # Edit each block as needed per version
  120. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  121. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  122. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  123. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  124. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  125. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  126. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  127. 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
  128. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  129. 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
  130. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  131. 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
  132. fi
  133. - name: Apply Kernel Branding
  134. uses: ./.github/actions/apply-kernel-branding
  135. with:
  136. variant: ${{ inputs.variant }}
  137. kernel_version: ${{ steps.parse.outputs.kernel_version }}
  138. android_version: ${{ steps.parse.outputs.android_version }}
  139. sublevel: ${{ steps.extract.outputs.sublevel }}
  140. - name: Remove Protected Exports
  141. uses: ./.github/actions/remove-protected-exports
  142. - name: Clean Kernel Flags
  143. uses: ./.github/actions/clean-kernel-flags
  144. - name: Scan and collect patch rejects
  145. id: scan
  146. if: ${{ always() && inputs.variant == 'Normal' }}
  147. uses: ./.github/actions/scan-patch-rejects
  148. - name: Upload Rejects
  149. if: ${{ always() && inputs.variant == 'Normal' }}
  150. uses: actions/upload-artifact@v7
  151. with:
  152. name: ${{ steps.extract.outputs.file_name }}-Rejects
  153. path: patch-rejects/
  154. if-no-files-found: ignore
  155. compression-level: 9
  156. - name: 'Setup ccache and Build Environment'
  157. shell: bash
  158. if: true
  159. working-directory: ${{ github.workspace }}
  160. run: |
  161. set -euo pipefail
  162. # Download and install ccache
  163. echo "Installing ccache..."
  164. curl -LfsS --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 30 --tcp-fastopen -H "User-Agent: Mozilla/5.0" "https://github.com/WildKernels/kernel_patches/raw/refs/heads/main/ccache/ccache-x86-64" -o ccache || { echo "❌ Failed to download ccache"; exit 1; }
  165. sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
  166. sudo chmod +x /usr/bin/ccache
  167. rm -f ./ccache
  168. # Verify ccache
  169. if ! /usr/bin/ccache --version > /dev/null 2>&1; then
  170. echo "❌ ccache installation failed or binary is corrupted"
  171. exit 1
  172. fi
  173. echo "✅ ccache binary verified: $(/usr/bin/ccache --version | head -1)"
  174. # Setup cache directories
  175. export CCACHE_DIR="/home/runner/.ccache"
  176. echo "CCACHE_DIR=$CCACHE_DIR" >> $GITHUB_ENV
  177. export LDCACHE_DIR="/home/runner/.ld_cache"
  178. echo "LDCACHE_DIR=$LDCACHE_DIR" >> $GITHUB_ENV
  179. mkdir -p "$CCACHE_DIR" "$LDCACHE_DIR"
  180. # Create LD wrapper for thin-LTO caching
  181. cat > "$GITHUB_WORKSPACE/kernel/common/ld-wrapper" << 'EOF'
  182. #!/bin/bash
  183. ld.lld "$@" --thinlto-cache-dir="$LDCACHE_DIR" --thinlto-jobs="$(nproc --all)"
  184. EOF
  185. chmod +x "$GITHUB_WORKSPACE/kernel/common/ld-wrapper"
  186. echo "CC=/usr/bin/ccache clang" >> "$GITHUB_ENV"
  187. echo "CXX=/usr/bin/ccache clang++" >> "$GITHUB_ENV"
  188. echo "HOSTCC=/usr/bin/ccache clang" >> "$GITHUB_ENV"
  189. echo "HOSTCXX=/usr/bin/ccache clang++" >> "$GITHUB_ENV"
  190. echo "LD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> "$GITHUB_ENV"
  191. echo "HOSTLD=$GITHUB_WORKSPACE/kernel/common/ld-wrapper" >> "$GITHUB_ENV"
  192. export CCACHE_MAXSIZE="12G"
  193. echo CCACHE_MAXSIZE="$CCACHE_MAXSIZE" >> $GITHUB_ENV
  194. export CCACHE_COMPILERCHECK="%compiler% -dumpmachine; %compiler% -dumpversion"
  195. echo CCACHE_COMPILERCHECK="$CCACHE_COMPILERCHECK" >> $GITHUB_ENV
  196. export CCACHE_BASEDIR="${GITHUB_WORKSPACE}"
  197. echo CCACHE_BASEDIR="${GITHUB_WORKSPACE}" >> $GITHUB_ENV
  198. export CCACHE_NOHASHDIR="true"
  199. echo CCACHE_NOHASHDIR="true" >> $GITHUB_ENV
  200. export CCACHE_IGNOREOPTIONS="--sysroot*"
  201. echo CCACHE_IGNOREOPTIONS="--sysroot*" >> $GITHUB_ENV
  202. export CCACHE_COMPRESSION="true"
  203. echo CCACHE_COMPRESSION="true" >> $GITHUB_ENV
  204. export CCACHE_COMPRESSLEVEL="9"
  205. echo CCACHE_COMPRESSION_LEVEL="9" >> $GITHUB_ENV
  206. export CCACHE_DIRECT="true"
  207. echo CCACHE_DIRECT="true" >> $GITHUB_ENV
  208. export CCACHE_FILE_CLONE="true"
  209. echo CCACHE_FILE_CLONE="true" >> $GITHUB_ENV
  210. export CCACHE_INODE_CACHE="true"
  211. echo CCACHE_INODE_CACHE="true" >> $GITHUB_ENV
  212. export CCACHE_IS_KERNEL_COMPILING="true"
  213. echo CCACHE_IS_KERNEL_COMPILING="true" >> $GITHUB_ENV
  214. export CCACHE_UMASK="002"
  215. echo CCACHE_UMASK="002" >> $GITHUB_ENV
  216. export CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
  217. echo CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale" >> $GITHUB_ENV
  218. #export CCACHE_HARDLINK="true"
  219. #echo CCACHE_HARDLINK="$CCACHE_HARDLINK" >> $GITHUB_ENV
  220. if ccache --help 2>&1 | grep -q 'depend_mode'; then
  221. export CCACHE_DEPEND=true
  222. echo "CCACHE_DEPEND=true" >> "$GITHUB_ENV"
  223. fi
  224. # Initialize ccache
  225. #ccache -M 100G
  226. ccache -p
  227. ccache -s
  228. ccache -z
  229. echo "✅ Build environment ready"
  230. echo " CCACHE_DIR: $CCACHE_DIR"
  231. echo " LDCACHE_DIR: $LDCACHE_DIR"
  232. - name: Restore build caches (ccache)
  233. id: restore-ccache
  234. uses: ./.github/actions/restore-cache
  235. with:
  236. cache_path: /home/runner/.ccache
  237. cache_key: buildcache-${{ inputs.kernel_version }}
  238. cache_bucket: "ccache-cache"
  239. compression_level: 9
  240. restore_keys: |
  241. buildcache-
  242. - name: Restore build caches (bazel)
  243. id: restore-bazel-cache
  244. uses: ./.github/actions/restore-cache
  245. with:
  246. cache_path: /home/runner/.cache/bazel
  247. cache_key: buildcache-${{ inputs.kernel_version }}
  248. cache_bucket: "bazel-cache"
  249. compression_level: 9
  250. restore_keys: |
  251. buildcache-
  252. - name: Restore build caches (LTO/ld_cache)
  253. id: restore-ldcache
  254. uses: ./.github/actions/restore-cache
  255. with:
  256. cache_path: /home/runner/.ld_cache
  257. cache_key: buildcache-${{ inputs.kernel_version }}
  258. cache_bucket: "lto-cache"
  259. compression_level: 9
  260. restore_keys: |
  261. buildcache-
  262. - name: Check cache hit
  263. run: |
  264. if [ "${{ steps.restore-ccache.outputs.cache-hit }}" = "true" ]; then
  265. echo "✅ ccache HIT - Key: ${{ steps.restore-ccache.outputs.cache-key }} - Size: ${{ steps.restore-ccache.outputs.cache-size }}"
  266. else
  267. echo "❌ ccache MISS - Fresh build"
  268. fi
  269. if [ "${{ steps.restore-bazel-cache.outputs.cache-hit }}" = "true" ]; then
  270. echo "✅ bazel cache HIT - Key: ${{ steps.restore-bazel-cache.outputs.cache-key }} - Size: ${{ steps.restore-bazel-cache.outputs.cache-size }}"
  271. else
  272. echo "❌ bazel cache MISS - Fresh build"
  273. fi
  274. if [ "${{ steps.restore-ldcache.outputs.cache-hit }}" = "true" ]; then
  275. echo "✅ ld_cache HIT - Key: ${{ steps.restore-ldcache.outputs.cache-key }} - Size: ${{ steps.restore-ldcache.outputs.cache-size }}"
  276. else
  277. echo "❌ ld_cache MISS - Fresh build"
  278. fi
  279. ccache -p
  280. ccache -s
  281. ccache -z
  282. - name: List cache contents
  283. working-directory: ${{ github.workspace }}
  284. run: |
  285. echo "=== .ccache ==="
  286. du -sh /home/runner/.ccache || true
  287. ls -l /home/runner/.ccache || true
  288. echo "=== .cache/bazel ==="
  289. du -sh /home/runner/.cache/bazel || true
  290. ls -l /home/runner/.cache/bazel || true
  291. echo "=== .ld_cache ==="
  292. du -sh /home/runner/.ld_cache || true
  293. ls -l /home/runner/.ld_cache || true
  294. - name: Build Kernel
  295. env:
  296. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  297. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  298. uses: ./.github/actions/build-kernel
  299. - name: Post-build cache stats
  300. id: post-cache-stats
  301. run: |
  302. set -euo pipefail
  303. STATS="$(ccache -s)"
  304. CACHEABLE=$(echo "$STATS" | awk '/Cacheable calls:/ {
  305. match($0, /[0-9]+/);
  306. print substr($0, RSTART, RLENGTH)
  307. }' | head -n1)
  308. HITS=$(echo "$STATS" | awk '/^[[:space:]]*Hits:/ {
  309. match($0, /[0-9]+/);
  310. print substr($0, RSTART, RLENGTH)
  311. }' | head -n1)
  312. DIRECT=$(echo "$STATS" | awk '/Direct:/ {
  313. match($0, /[0-9]+/);
  314. print substr($0, RSTART, RLENGTH)
  315. }' | head -n1)
  316. if [ "${CACHEABLE:-0}" -gt 0 ]; then
  317. HIT_RATE=$(awk -v h="${HITS:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (h/c)*100}')
  318. DIRECT_RATE=$(awk -v d="${DIRECT:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (d/c)*100}')
  319. else
  320. HIT_RATE="0.0"
  321. DIRECT_RATE="0.0"
  322. fi
  323. echo "hit_rate=${HIT_RATE}%"
  324. echo "direct_rate=${DIRECT_RATE}%"
  325. - name: List cache contents
  326. working-directory: ${{ github.workspace }}
  327. run: |
  328. echo "=== .ccache ==="
  329. du -sh /home/runner/.ccache || true
  330. ls -l /home/runner/.ccache || true
  331. echo "=== .cache/bazel ==="
  332. du -sh /home/runner/.cache/bazel || true
  333. ls -l /home/runner/.cache/bazel || true
  334. echo "=== .ld_cache ==="
  335. du -sh /home/runner/.ld_cache || true
  336. ls -l /home/runner/.ld_cache || true
  337. - name: Save ccache cache
  338. uses: ./.github/actions/save-cache
  339. with:
  340. cache_path: /home/runner/.ccache
  341. cache_key: buildcache-${{ inputs.kernel_version }}
  342. cache_bucket: "ccache-cache"
  343. compression_level: 9
  344. github_token: ${{ secrets.GITHUB_TOKEN }}
  345. - name: Save bazel cache
  346. uses: ./.github/actions/save-cache
  347. with:
  348. cache_path: /home/runner/.cache/bazel
  349. cache_key: buildcache-${{ inputs.kernel_version }}
  350. cache_bucket: "bazel-cache"
  351. compression_level: 9
  352. github_token: ${{ secrets.GITHUB_TOKEN }}
  353. - name: Save LTO LD cache
  354. uses: ./.github/actions/save-cache
  355. with:
  356. cache_path: /home/runner/.ld_cache
  357. cache_key: buildcache-${{ inputs.kernel_version }}
  358. cache_bucket: "lto-cache"
  359. compression_level: 9
  360. github_token: ${{ secrets.GITHUB_TOKEN }}
  361. - name: Create Bootimgs Folder and Build Boot Images
  362. uses: ./.github/actions/build-boot-images
  363. - name: Upload Boot Image (boot.img)
  364. uses: actions/upload-artifact@v7
  365. with:
  366. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  367. if-no-files-found: error
  368. archive: false
  369. - name: Upload Boot Image (boot-gz.img)
  370. uses: actions/upload-artifact@v7
  371. with:
  372. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  373. if-no-files-found: error
  374. archive: false
  375. - name: Upload Boot Image (boot-lz4.img)
  376. uses: actions/upload-artifact@v7
  377. with:
  378. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  379. if-no-files-found: error
  380. archive: false
  381. - name: Prepare AnyKernel3 Zip
  382. uses: ./.github/actions/prepare-anykernel3
  383. - name: Upload Artifacts
  384. uses: actions/upload-artifact@v7
  385. with:
  386. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  387. path: ${{ github.workspace }}/AnyKernel3/**
  388. if-no-files-found: ignore
  389. compression-level: 9