build.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. name: Kernel Build Process
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. branch:
  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. build_type:
  18. required: false
  19. type: string
  20. susfs:
  21. required: true
  22. type: string
  23. bbg:
  24. required: true
  25. type: string
  26. unicodefix:
  27. required: true
  28. type: string
  29. zeromount:
  30. required: true
  31. type: string
  32. nomount:
  33. required: true
  34. type: string
  35. ksun:
  36. required: true
  37. type: string
  38. droidspace:
  39. required: true
  40. type: string
  41. ntsync:
  42. required: true
  43. type: string
  44. bbrv1:
  45. required: true
  46. type: string
  47. bbrv3:
  48. required: true
  49. type: string
  50. cache:
  51. required: true
  52. type: string
  53. ipv6_nat:
  54. required: true
  55. type: string
  56. optimization:
  57. required: true
  58. type: string
  59. ttl:
  60. required: true
  61. type: string
  62. jobs:
  63. build-samsung-gki:
  64. name: "${{ inputs.branch }}-${{ inputs.kernel_version }}-${{ inputs.android_version }}"
  65. runs-on: ubuntu-latest
  66. strategy:
  67. fail-fast: false
  68. steps:
  69. - name: Checkout Repository
  70. uses: actions/checkout@v5
  71. - name: Free Disk Space
  72. if: true
  73. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  74. with:
  75. remove_android: true
  76. remove_dotnet: true
  77. remove_haskell: true
  78. remove_tool_cache: true
  79. remove_swap: true
  80. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  81. remove_packages_one_command: true
  82. 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"
  83. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  84. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  85. testing: false
  86. - name: Setup more Swap (for LTO)
  87. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  88. with:
  89. swap-size-gb: 25 # 10-24 GB is common for heavy LTO
  90. # swap-space-path: /mnt/swapfile # optional
  91. - name: Parse branch for cache keys
  92. if: inputs.cache == 'true'
  93. uses: ./.github/actions/parse-branch
  94. with:
  95. branch: ${{ inputs.branch }}
  96. # - name: set up bazel cache dir
  97. # if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  98. # run: |
  99. # BCACHE_DIR="${{ github.workspace }}/.cache/bazel-disk-kernel"
  100. # mkdir -p "$BCACHE_DIR"
  101. # echo "BCACHE_DIR=$BCACHE_DIR" >> $GITHUB_ENV
  102. # - name: set up bazel cache
  103. # if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  104. # uses: actions/cache@v4
  105. # with:
  106. # path: ${{ env.BCACHE_DIR }}
  107. # key: bcache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.FULL_BRANCH }}
  108. # restore-keys: |
  109. # bcache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.FULL_BRANCH }}
  110. - name: Install ccache
  111. if: inputs.cache == 'true' && inputs.build_type == 'make'
  112. run: sudo apt-get update && sudo apt-get install -y ccache
  113. - name: Export ccache + determinism
  114. if: inputs.cache == 'true' && inputs.build_type == 'make'
  115. run: |
  116. CACHE_DIR="${{ github.workspace }}/.ccache"
  117. mkdir -p "$CACHE_DIR"
  118. CCACHE_LOG="${{ github.workspace }}/ccache.log"
  119. SETTINGS=(
  120. "CCACHE_DIR=$CACHE_DIR"
  121. "CCACHE_MAXSIZE=12G"
  122. "CCACHE_COMPILERCHECK=content"
  123. "CCACHE_BASEDIR=${GITHUB_WORKSPACE}"
  124. "CCACHE_NOHASHDIR=true"
  125. "CCACHE_IGNOREOPTIONS=-sysroot* -fdebug-prefix-map=* -fmacro-prefix-map=*"
  126. "CCACHE_COMPRESS=true"
  127. "CCACHE_COMPRESSLEVEL=8"
  128. "CCACHE_DIRECT=true"
  129. "CCACHE_FILE_CLONE=true"
  130. "CCACHE_INODE_CACHE=true"
  131. "CCACHE_IS_KERNEL_COMPILING=true"
  132. "CCACHE_UMASK=002"
  133. "KBUILD_BUILD_TIMESTAMP=2026-01-01"
  134. "CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale,file_stat_matches"
  135. )
  136. for setting in "${SETTINGS[@]}"; do
  137. export "$setting"
  138. echo "$setting" >> $GITHUB_ENV
  139. done
  140. if ccache --help 2>&1 | grep -q 'depend_mode'; then
  141. export CCACHE_DEPEND=true
  142. echo "CCACHE_DEPEND=true" >> "$GITHUB_ENV"
  143. fi
  144. - name: restore ccache
  145. if: inputs.cache == 'true' && inputs.build_type == 'make'
  146. uses: actions/cache@v4
  147. with:
  148. path: ${{ env.CCACHE_DIR }}
  149. key: ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }}
  150. restore-keys: |
  151. ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }}
  152. ccache-${{ runner.os }}-${{ inputs.build_type }}-
  153. - name: Ensure ccache is used
  154. if: inputs.cache == 'true' && inputs.build_type == 'make'
  155. run: |
  156. echo "/usr/lib/ccache" >> $GITHUB_PATH
  157. echo "CC='ccache clang'" >> $GITHUB_ENV
  158. echo "CXX='ccache clang++'" >> $GITHUB_ENV
  159. - name: Set CONFIG Environment Variable
  160. run: |
  161. # Set CONFIG dynamically based on inputs values
  162. CONFIG="${{ inputs.branch }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  163. # Set CONFIG as an environment variable for future steps
  164. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  165. - name: dependencies
  166. uses: ./.github/actions/dependencies
  167. with:
  168. zeromount: ${{ inputs.zeromount }}
  169. nomount: ${{ inputs.nomount }}
  170. susfs: ${{ inputs.susfs }}
  171. android_version: ${{ inputs.android_version }}
  172. kernel_version: ${{ inputs.kernel_version }}
  173. - name: Download Kernel
  174. uses: ./.github/actions/clone-kernel
  175. with:
  176. branch: ${{ inputs.branch }}
  177. - name: Set Path Environment Variables
  178. uses: ./.github/actions/env-variables
  179. with:
  180. branch: ${{ inputs.branch }}
  181. susfs: ${{ inputs.susfs }}
  182. zeromount: ${{ inputs.zeromount }}
  183. nomount: ${{ inputs.nomount }}
  184. - name: Extract all tar.xz files and delete them
  185. run: |
  186. cd "$CONFIG"
  187. find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do
  188. echo "Extracting $file"
  189. tar -xf "$file"
  190. rm "$file"
  191. done
  192. - name: Add KernelSU-Next
  193. if: inputs.ksun == 'true'
  194. uses: ./.github/actions/ksun
  195. with:
  196. susfs: ${{ inputs.susfs }}
  197. - name: Apply SUSFS Patches
  198. if: inputs.susfs == 'true'
  199. uses: ./.github/actions/susfs-patches
  200. with:
  201. android_version: ${{ inputs.android_version }}
  202. kernel_version: ${{ inputs.kernel_version }}
  203. branch: ${{ inputs.branch }}
  204. - name: Apply zeromount Patches
  205. if: inputs.susfs == 'true' && inputs.zeromount == 'true'
  206. uses: ./.github/actions/zeromount
  207. with:
  208. android_version: ${{ inputs.android_version }}
  209. kernel_version: ${{ inputs.kernel_version }}
  210. - name: add nomount
  211. if: inputs.nomount == 'true'
  212. uses: ./.github/actions/nomount
  213. with:
  214. kernel_version: ${{ inputs.kernel_version }}
  215. - name: Add BBG
  216. if: inputs.bbg == 'true'
  217. uses: ./.github/actions/bbg
  218. - name: Add unicodefix
  219. if: inputs.unicodefix == 'true'
  220. uses: ./.github/actions/unicode
  221. with:
  222. kernel_version: ${{ inputs.kernel_version }}
  223. - name: Add droidspace support
  224. if: inputs.droidspace == 'true'
  225. uses: ./.github/actions/droidspaces
  226. with:
  227. kernel_version: ${{ inputs.kernel_version }}
  228. - name: Add ntsync
  229. if: inputs.ntsync == 'true'
  230. uses: ./.github/actions/ntsync
  231. with:
  232. android_version: ${{ inputs.android_version }}
  233. kernel_version: ${{ inputs.kernel_version }}
  234. - name: Add bbrv1
  235. if: inputs.bbrv1 == 'true'
  236. uses: ./.github/actions/bbrv1
  237. - name: Add bbrv3
  238. if: inputs.bbrv3 == 'true'
  239. uses: ./.github/actions/bbrv3
  240. with:
  241. android_version: ${{ inputs.android_version }}
  242. kernel_version: ${{ inputs.kernel_version }}
  243. - name: Add IP-SET and IPv6_NAT support
  244. if: inputs.ipv6_nat == 'true'
  245. uses: ./.github/actions/IPv6_NAT
  246. - name: Add TTL support
  247. if: inputs.ttl == 'true'
  248. uses: ./.github/actions/TTL
  249. - name: add optimization patches
  250. if: inputs.optimization == 'true'
  251. uses: ./.github/actions/optimization
  252. with:
  253. kernel_version: ${{ inputs.kernel_version }}
  254. branch: ${{ inputs.branch }}
  255. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  256. if: inputs.kernel_version == '6.6'
  257. uses: ./.github/actions/6.6-fix
  258. with:
  259. branch: ${{ inputs.branch }}
  260. - name: temp fix for m55 bootloop maybe
  261. if: inputs.branch == 'SM-M556B-Oneui8'
  262. uses: ./.github/actions/m55-fix
  263. - name: Set Kernel Configuration Variables
  264. if: inputs.ksun == 'true'
  265. uses: ./.github/actions/configs
  266. with:
  267. branch: ${{ inputs.branch }}
  268. - name: Change Kernel Name and clean dirty
  269. uses: ./.github/actions/kernel-name
  270. - name: remove protected exports
  271. uses: ./.github/actions/abi-export
  272. - name: Set file name
  273. if: inputs.ksun == 'true'
  274. uses: ./.github/actions/file-name
  275. with:
  276. branch: ${{ inputs.branch }}
  277. ksun: ${{ inputs.ksun }}
  278. susfs: ${{ inputs.susfs }}
  279. zeromount: ${{ inputs.zeromount }}
  280. bbg: ${{ inputs.bbg }}
  281. bbrv1: ${{ inputs.bbrv1 }}
  282. bbrv3: ${{ inputs.bbrv3 }}
  283. droidspaces: ${{ inputs.droidspace }}
  284. ntsync: ${{ inputs.ntsync }}
  285. ipv6_nat: ${{ inputs.ipv6_nat }}
  286. ttl: ${{ inputs.ttl }}
  287. unicodefix: ${{ inputs.unicodefix }}
  288. # - name: ensure bazel cache is set to be used
  289. # if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  290. # uses: ./.github/actions/use-bazcache
  291. - name: change variables to ccache
  292. if: inputs.cache == 'true' && inputs.build_type == 'make'
  293. uses: ./.github/actions/use-ccache
  294. - name: Build
  295. uses: ./.github/actions/build
  296. with:
  297. branch: ${{ inputs.branch }}
  298. build_type: ${{ inputs.build_type }}
  299. kernel_version: ${{ inputs.kernel_version }}
  300. - name: clean up ccache
  301. if: inputs.cache == 'true' && inputs.build_type == 'make'
  302. run: ccache -c
  303. - name: ccache stats
  304. if: inputs.cache == 'true' && inputs.build_type == 'make'
  305. run: ccache -s -v || ccache -s
  306. # - name: bazel cache stats
  307. # if: inputs.cache == 'true' && inputs.build_type == 'Bazel'
  308. # run: bazel analyze-profile profile.json
  309. - name: Prepare AnyKernel3
  310. uses: ./.github/actions/ak3zip-prep
  311. with:
  312. branch: ${{ inputs.branch }}
  313. - name: Upload AnyKernel3 Artifacts
  314. id: upload_ak3
  315. uses: actions/upload-artifact@v6
  316. with:
  317. name: ${{ env.FILE_NAME }}-AnyKernel3
  318. path: |
  319. ./AnyKernel3/**
  320. compression-level: 9
  321. - name: Scan and collect patch rejects
  322. if: ${{ always() }}
  323. run: |
  324. set -e
  325. CONFIG_DIR="$CONFIG"
  326. REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects"
  327. mkdir -p "$REJECTS_DIR"
  328. # Find all .rej files under the configuration directory
  329. mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej')
  330. REJ_COUNT=${#REJS[@]}
  331. echo "Found $REJ_COUNT .rej files under $CONFIG_DIR"
  332. echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV
  333. if [ "$REJ_COUNT" -gt 0 ]; then
  334. for REJ in "${REJS[@]}"; do
  335. # Relative path from $CONFIG
  336. REL="${REJ#"$CONFIG_DIR"/}"
  337. DEST="$REJECTS_DIR/$REL"
  338. mkdir -p "$(dirname "$DEST")"
  339. cp "$REJ" "$DEST"
  340. # Copy the associated original file alongside the .rej
  341. ORIG="${REJ%.rej}"
  342. if [ -f "$ORIG" ]; then
  343. ORIG_DEST="$REJECTS_DIR/${REL%.rej}"
  344. mkdir -p "$(dirname "$ORIG_DEST")"
  345. cp "$ORIG" "$ORIG_DEST"
  346. fi
  347. echo "$REL" >> "$REJECTS_DIR/index.txt"
  348. done
  349. fi
  350. - name: Generate Build Summary
  351. if: ${{ always() }}
  352. run: |
  353. # Create build summary file for inclusion in Misc artifact
  354. echo "# Kernel Build Summary" > build_summary.md
  355. # Add build variant header
  356. echo "## ${{ env.FILE_NAME }}" >> build_summary.md
  357. # Add build info
  358. echo "## Build Information" >> build_summary.md
  359. echo "- **Android Version**: ${{ inputs.android_version }}" >> build_summary.md
  360. echo "- **Kernel Version**: ${{ inputs.kernel_version }}.${{ inputs.sub_level }}" >> build_summary.md
  361. echo "- **BBG**: Installed" >> build_summary.md
  362. echo "" >> build_summary.md
  363. # Get KernelSU-Next commit
  364. if [ -d "$CONFIG/KernelSU-Next" ]; then
  365. cd "$CONFIG/KernelSU-Next"
  366. KSUN_COMMIT=$(git rev-parse HEAD)
  367. KSUN_URL="https://github.com/WildKernels/KernelSU-Next/commit/$KSUN_COMMIT"
  368. echo "- **KernelSU-Next**: [$KSUN_COMMIT]($KSUN_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  369. cd "$GITHUB_WORKSPACE"
  370. else
  371. echo "- **KernelSU-Next**: not present" >> build_summary.md
  372. fi
  373. # Get Baseband-guard commit
  374. if [ -d "$CONFIG/Baseband-guard" ]; then
  375. cd "$CONFIG/Baseband-guard"
  376. BBG_COMMIT=$(git rev-parse HEAD)
  377. BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT"
  378. echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  379. cd "$GITHUB_WORKSPACE"
  380. else
  381. echo "- **Baseband-guard**: not present" >> build_summary.md
  382. fi
  383. # Get SUSFS4KSU commit
  384. if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then
  385. cd "$GITHUB_WORKSPACE/susfs4ksu"
  386. SUSFS_COMMIT=$(git rev-parse HEAD)
  387. SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT"
  388. echo "- **SUSFS4KSU (v2.1.0)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  389. cd "$GITHUB_WORKSPACE"
  390. else
  391. echo "- **SUSFS4KSU (v2.1.0)**: not present" >> build_summary.md
  392. fi
  393. echo "" >> build_summary.md
  394. # Add artifact summary with presence verification
  395. echo "## Build Artifacts" >> build_summary.md
  396. # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build)
  397. if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then
  398. AK3_STATUS="✅"
  399. else
  400. AK3_STATUS="❌"
  401. fi
  402. echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md
  403. echo "### Misc (uploaded files)" >> build_summary.md
  404. FILES_PRESENT=0
  405. for f in "${{ env.FILE_NAME }}-Image" "${{ env.FILE_NAME }}-Image.gz" "${{ env.FILE_NAME }}-Image.lz4" "${{ env.FILE_NAME }}-boot.img" "${{ env.FILE_NAME }}-boot-gz.img" "${{ env.FILE_NAME }}-boot-lz4.img"; do
  406. if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi
  407. done
  408. if [ "$FILES_PRESENT" -gt 0 ]; then
  409. MISC_STATUS="✅"
  410. else
  411. MISC_STATUS="❌"
  412. fi
  413. echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md
  414. if [ "$MISC_STATUS" = "✅" ]; then
  415. echo " Included:" >> build_summary.md
  416. for f in "${{ env.FILE_NAME }}-Image" "${{ env.FILE_NAME }}-Image.gz" "${{ env.FILE_NAME }}-Image.lz4" "${{ env.FILE_NAME }}-boot.img" "${{ env.FILE_NAME }}-boot-gz.img" "${{ env.FILE_NAME }}-boot-lz4.img"; do
  417. if [ -f "$f" ]; then
  418. echo " - $f" >> build_summary.md
  419. fi
  420. done
  421. fi
  422. echo "### Diagnostics" >> build_summary.md
  423. echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md
  424. if [ -f patch-rejects/index.txt ]; then
  425. if [ -s patch-rejects/index.txt ]; then
  426. echo " Rejected files:" >> build_summary.md
  427. while IFS= read -r line; do
  428. echo " - $line" >> build_summary.md
  429. done < patch-rejects/index.txt
  430. else
  431. echo " Rejected file list is empty." >> build_summary.md
  432. fi
  433. else
  434. echo " No rejected patches found." >> build_summary.md
  435. fi