build.yml 17 KB

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