build.yml 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. name: Build Script
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. use_make:
  9. required: true
  10. type: boolean
  11. android_version:
  12. required: true
  13. type: string
  14. kernel_version:
  15. required: true
  16. type: string
  17. sub_level:
  18. required: true
  19. type: string
  20. os_patch_level:
  21. required: true
  22. type: string
  23. kernelsu_variant:
  24. required: true
  25. type: string
  26. kernelsu_branch:
  27. required: true
  28. type: string
  29. kernelsu_branch_other:
  30. required: false
  31. type: string
  32. revision:
  33. required: false
  34. type: string
  35. jobs:
  36. build-gki:
  37. runs-on: ubuntu-latest
  38. timeout-minutes: 120
  39. env:
  40. CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
  41. CCACHE_NOHASHDIR: "true"
  42. CCACHE_HARDLINK: "true"
  43. steps:
  44. - name: Maximize Build Space
  45. uses: AdityaGarg8/remove-unwanted-software@v5
  46. with:
  47. remove-dotnet: 'true' # Frees ~2 GB
  48. remove-android: 'true' # Frees ~9 GB
  49. remove-haskell: 'true' # Frees ~5.2 GB
  50. remove-codeql: 'true' # Frees ~5.4 GB
  51. remove-docker-images: 'true' # Frees ~3.2 GB
  52. remove-large-packages: 'true' # Frees ~3.1 GB
  53. remove-swapfile: 'true' # Frees ~4 GB
  54. remove-cached-tools: 'false' # Avoid unless confirmed safe
  55. verbose: 'true' # Enable detailed logging
  56. - name: Set CONFIG Environment Variable
  57. run: |
  58. # Set CONFIG dynamically based on inputs values
  59. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  60. # Set CONFIG as an environment variable for future steps
  61. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  62. echo "CONFIG set to: $CONFIG"
  63. - name: Install ccache
  64. run: sudo apt update && sudo apt install -y ccache
  65. - name: Set up ccache
  66. run: |
  67. mkdir -p ~/.cache/bazel
  68. ccache --version
  69. ccache --max-size=2G
  70. ccache --set-config=compression=true
  71. echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
  72. - name: Download toolchain
  73. run: |
  74. AOSP_MIRROR=https://android.googlesource.com
  75. BRANCH=main-kernel-build-2024
  76. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  77. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  78. - name: Set environment variables
  79. run: |
  80. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  81. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  82. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  83. - name: Set boot sign key
  84. env:
  85. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  86. run: |
  87. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  88. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  89. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  90. else
  91. echo "BOOT_SIGN_KEY is not set. Using AOSP sign key..."
  92. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  93. fi
  94. - name: Install Repo
  95. run: |
  96. mkdir -p ./git-repo
  97. echo "Downloading repo tool..."
  98. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  99. chmod a+rx ./git-repo/repo
  100. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  101. - name: Clone AnyKernel3 and Other Dependencies
  102. run: |
  103. echo "Cloning AnyKernel3 and other dependencies..."
  104. ANYKERNEL_BRANCH="gki-2.0"
  105. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  106. echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
  107. echo "Using branch for SUSFS: $SUSFS_BRANCH"
  108. git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  109. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  110. git clone https://github.com/WildPlusKernel/kernel_patches.git
  111. - name: Initialize and Sync Kernel Source
  112. run: |
  113. echo "Creating folder for configuration: $CONFIG..."
  114. mkdir -p "$CONFIG"
  115. cd "$CONFIG"
  116. echo "Initializing and syncing kernel source..."
  117. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  118. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  119. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  120. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  121. if grep -q deprecated <<< $REMOTE_BRANCH; then
  122. echo "Found deprecated branch: $FORMATTED_BRANCH"
  123. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  124. fi
  125. $REPO --version
  126. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  127. - name: Fix Less Then 6.6.50 Builds
  128. run: |
  129. cd "$CONFIG/common"
  130. if [ "${{ inputs.android_version }}" = "android15" ] && [ "${{ inputs.kernel_version }}" = "6.6" ]; then
  131. if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
  132. sed -i '/#include <trace\/hooks\/blk.h>/a #include <trace\/hooks\/fs.h>' ./fs/namespace.c
  133. else
  134. echo "Line already present. Skipping insert."
  135. fi
  136. fi
  137. - name: Determine the branch for KernelSU
  138. run: |
  139. case "${{ inputs.kernelsu_branch }}" in
  140. "Stable")
  141. echo "BRANCH=-" >> $GITHUB_ENV
  142. ;;
  143. "Dev")
  144. if [[ "${{ inputs.kernelsu_variant }}" =~ ^(KSU|MKSU)$ ]]; then
  145. echo "BRANCH=-s main" >> $GITHUB_ENV
  146. elif [[ "${{ inputs.kernelsu_variant }}" == "NEXT" ]]; then
  147. echo "BRANCH=-s next" >> $GITHUB_ENV
  148. elif [[ "${{ inputs.kernelsu_variant }}" == "WILD" ]]; then
  149. echo "BRANCH=-s wild" >> $GITHUB_ENV
  150. fi
  151. ;;
  152. "Other")
  153. if [[ -n "${{ inputs.kernelsu_branch_other }}" ]]; then
  154. echo "BRANCH=-s ${{ inputs.kernelsu_branch_other }}" >> $GITHUB_ENV
  155. else
  156. echo "Error: Custom branch not provided for 'Other'" >&2
  157. exit 1
  158. fi
  159. ;;
  160. esac
  161. - name: Add KernelSU
  162. run: |
  163. echo "Changing to configuration directory: $CONFIG..."
  164. cd "$CONFIG"
  165. case "${{ inputs.kernelsu_variant }}" in
  166. "WILD")
  167. echo "Adding Wild KSU..."
  168. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash ${{ env.BRANCH }}
  169. ;;
  170. "KSU")
  171. echo "Adding KernelSU Official..."
  172. curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  173. ;;
  174. "NEXT")
  175. echo "Adding KernelSU Next..."
  176. curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash ${{ env.BRANCH }}
  177. ;;
  178. "MKSU")
  179. echo "Adding KernelSU MKSU..."
  180. curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  181. ;;
  182. esac
  183. - name: Apply SUSFS Patches for KernelSU Variants
  184. run: |
  185. echo "Changing to configuration directory: $CONFIG..."
  186. cd "$CONFIG"
  187. echo "Applying SUSFS patches..."
  188. # Copy SUSFS patches
  189. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  190. cd common
  191. patch -p1 --forward < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch
  192. cd ..
  193. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  194. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  195. case "${{ inputs.kernelsu_variant }}" in
  196. "WILD")
  197. echo "Applying SUSFS patches for Official KernelSU..."
  198. cd ./Wild_KSU
  199. ;;
  200. "KSU")
  201. echo "Applying SUSFS patches for Official KernelSU..."
  202. cd ./KernelSU
  203. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  204. patch -p1 --forward < 10_enable_susfs_for_ksu.patch
  205. ;;
  206. "NEXT")
  207. echo "Applying SUSFS patches for KernelSU Next..."
  208. cd ./KernelSU-Next
  209. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  210. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  211. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_apk_sign.c.patch ./
  212. patch -p1 --forward < fix_apk_sign.c.patch
  213. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_core_hook.c.patch ./
  214. patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
  215. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_rules.c.patch ./
  216. patch -p1 --forward < fix_rules.c.patch
  217. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_sucompat.c.patch ./
  218. patch -p1 --forward < fix_sucompat.c.patch
  219. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_kernel_compat.c.patch ./
  220. patch -p1 --forward < fix_kernel_compat.c.patch
  221. ;;
  222. "MKSU")
  223. echo "Applying SUSFS patches for MKSU..."
  224. cd ./KernelS
  225. ;;
  226. esac
  227. - name: Getting KernelSU Version
  228. run: |
  229. echo "Changing to configuration directory: $CONFIG..."
  230. cd "$CONFIG"
  231. case "${{ inputs.kernelsu_variant }}" in
  232. "WILD")
  233. echo "Applying SUSFS patches for Official KernelSU..."
  234. cd ./Wild_KSU
  235. BASE_VERSION=10200
  236. ;;
  237. "KSU")
  238. echo "Applying SUSFS patches for Official KernelSU..."
  239. cd ./KernelSU
  240. BASE_VERSION=10200
  241. ;;
  242. "NEXT")
  243. cd ./KernelSU-Next
  244. BASE_VERSION=10200
  245. ;;
  246. "MKSU")
  247. ;;
  248. esac
  249. cd ./kernel
  250. KSU_VERSION=$(expr $(/usr/bin/git rev-list --count HEAD) "+" $BASE_VERSION)
  251. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  252. - name: Apply Hooks Patches
  253. run: |
  254. echo "Changing to configuration directory: $CONFIG..."
  255. cd "$CONFIG/common"
  256. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ]; then
  257. echo "Applying hooks for KernelSU-Next..."
  258. cp ../../kernel_patches/next/scope_min_manual_hooks_v1.4.patch ./
  259. patch -p1 --forward -F 3 < scope_min_manual_hooks_v1.4.patch
  260. elif [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  261. echo "Applying hooks for Wild KSU..."
  262. cp ../../kernel_patches/wild/syscall_hooks.patch ./
  263. patch -p1 --forward -F 3 < syscall_hooks.patch
  264. fi
  265. - name: Apply Hide Stuff Patches
  266. run: |
  267. echo "Changing to configuration directory: $CONFIG..."
  268. cd "$CONFIG/common"
  269. cp ../../kernel_patches/69_hide_stuff.patch ./
  270. patch -p1 --forward -F 3 < 69_hide_stuff.patch
  271. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  272. if: ${{ ( inputs.kernel_version == '6.6' ) }}
  273. run: |
  274. echo "[+] Adding Samsung KDP exported symbols to abi_gki_aarch64_galaxy"
  275. SYMBOL_LIST=$CONFIG/common/android/abi_gki_aarch64_galaxy
  276. echo "kdp_set_cred_non_rcu" >> $SYMBOL_LIST
  277. echo "kdp_usecount_dec_and_test" >> $SYMBOL_LIST
  278. echo "kdp_usecount_inc" >> $SYMBOL_LIST
  279. echo "[+] Adding Samsung KDP exported symbols definition to abi_gki_aarch64.stg"
  280. cd $CONFIG/common
  281. PATCH="../../kernel_patches/samsung/min_kdp/add-min_kdp-symbols.patch"
  282. if patch -p1 --dry-run < $PATCH; then
  283. echo "[+] Successfully added Samsung KDP exported symbols definition to abi_gki_aarch64.stg"
  284. patch -p1 --no-backup-if-mismatch < $PATCH
  285. fi
  286. echo "[+] Adding Samsung minimal KDP driver"
  287. cd drivers
  288. cp "../../../kernel_patches/samsung/min_kdp/min_kdp.c" min_kdp.c
  289. echo "obj-y += min_kdp.o" >> Makefile
  290. - name: Add Configuration Settings
  291. run: |
  292. echo "Changing to configuration directory: $CONFIG..."
  293. cd "$CONFIG"
  294. echo "Adding configuration settings to gki_defconfig..."
  295. # Add KSU configuration settings
  296. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  297. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  298. echo "CONFIG_KSU_KPROBES_HOOK=n" >> ./common/arch/arm64/configs/gki_defconfig
  299. fi
  300. # Add additional tmpfs config setting
  301. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  302. echo "CONFIG_TMPFS_POSIX_ACL=y" >> ./common/arch/arm64/configs/gki_defconfig
  303. # Add additional config setting
  304. echo "CONFIG_IP_NF_TARGET_TTL=y" >> ./common/arch/arm64/configs/gki_defconfig
  305. echo "CONFIG_IP6_NF_TARGET_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  306. echo "CONFIG_IP6_NF_MATCH_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  307. # Add BBR Config
  308. echo "CONFIG_TCP_CONG_ADVANCED=y" >> ./common/arch/arm64/configs/gki_defconfig
  309. echo "CONFIG_TCP_CONG_BBR=y" >> ./common/arch/arm64/configs/gki_defconfig
  310. echo "CONFIG_NET_SCH_FQ=y" >> ./common/arch/arm64/configs/gki_defconfig
  311. echo "CONFIG_TCP_CONG_BIC=n" >> ./common/arch/arm64/configs/gki_defconfig
  312. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> ./common/arch/arm64/configs/gki_defconfig
  313. echo "CONFIG_TCP_CONG_HTCP=n" >> ./common/arch/arm64/configs/gki_defconfig
  314. # Remove check_defconfig
  315. sed -i 's/check_defconfig//' ./common/build.config.gki
  316. - name: Add SUSFS Configuration Settings
  317. run: |
  318. echo "Changing to configuration directory: $CONFIG..."
  319. cd "$CONFIG"
  320. # Add SUSFS configuration settings
  321. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  322. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  323. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  324. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  325. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  326. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  327. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  328. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> ./common/arch/arm64/configs/gki_defconfig
  329. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  330. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  331. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  332. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  333. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  334. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  335. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  336. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  337. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
  338. else
  339. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  340. fi
  341. - name: Change Kernel Name
  342. run: |
  343. cd "$CONFIG"
  344. if [ -f "build/build.sh" ]; then
  345. perl -pi -e 's/-dirty//' ./common/scripts/setlocalversion
  346. perl -0777 -pi -e 's/(.*)(echo "\$res")/$1echo "\$res-Next-v\$KSUVER-SUSFS-v1.5.9-Wild"/s' ./common/scripts/setlocalversion
  347. perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sun Apr 20 04:20:00 UTC 2025"}' ./common/scripts/mkcompile_h
  348. else
  349. #Remove -maybe-dirty
  350. perl -pi -e 's/-maybe-dirty//g' ./build/kernel/kleaf/impl/stamp.bzl
  351. #Set Kernel Name
  352. echo "CONFIG_LOCALVERSION=\"-NEXT-v$KSUVER-SUSFS-v1.5.9-Wild\"" >> ./common/arch/arm64/configs/gki_defconfig
  353. #Set Kernel Timestamp
  354. perl -pi -e 's/build-timestamp = \$\(or \$\(KBUILD_BUILD_TIMESTAMP\), \$\(build-timestamp-auto\)\)/build-timestamp = "Sun Apr 20 04:20:00 UTC 2025"/' ./common/init/Makefile
  355. #Remove Abi Exports and Error
  356. rm -rf ./common/android/abi_gki_protected_exports_*
  357. perl -pi -e 's/^\s*"protected_exports_list"\s*:\s*"android\/abi_gki_protected_exports_aarch64",\s*$//;' ./common/BUILD.bazel
  358. fi
  359. - name: Build
  360. if: ${{ inputs.use_make == 'false' }}
  361. run : |
  362. set -e
  363. set -x
  364. cd "$CONFIG"
  365. echo "Building the kernel..."
  366. if [ -f "build/build.sh" ]; then
  367. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh CC="/usr/bin/ccache clang" || exit 1
  368. else
  369. tools/bazel build --disk_cache=/home/runner/.cache/bazel --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  370. fi
  371. ccache --show-stats
  372. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  373. if: ${{ (inputs.android_version == 'android12' || inputs.android_version == 'android13') && inputs.use_make == 'false' }}
  374. run: |
  375. mkdir bootimgs
  376. echo "Creating bootimgs folder and copying images..."
  377. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
  378. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
  379. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
  380. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
  381. # Create gzip of the Image file
  382. gzip -n -k -f -9 ./Image > ./Image.gz
  383. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  384. if: ${{ (inputs.android_version == 'android14' || inputs.android_version == 'android15') && inputs.use_make == 'false' }}
  385. run: |
  386. mkdir bootimgs
  387. echo "Creating bootimgs folder and copying images..."
  388. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  389. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  390. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
  391. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
  392. # Create gzip of the Image file
  393. gzip -n -k -f -9 ./Image > ./Image.gz
  394. - name: Create ZIP Files for Different Formats
  395. if: ${{ inputs.use_make == 'false' }}
  396. run: |
  397. echo "Creating zip files for all formats..."
  398. cd ./AnyKernel3
  399. # Create and upload zip for each format
  400. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  401. echo "Creating zip file: $ZIP_NAME..."
  402. mv ../Image ./Image
  403. zip -r "../$ZIP_NAME" ./*
  404. rm ./Image
  405. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-lz4.zip"
  406. echo "Creating zip file: $ZIP_NAME..."
  407. mv ../Image.lz4 ./Image.lz4
  408. zip -r "../$ZIP_NAME" ./*
  409. rm ./Image.lz4
  410. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-gz.zip"
  411. echo "Creating zip file: $ZIP_NAME..."
  412. mv ../Image.gz ./Image.gz
  413. zip -r "../$ZIP_NAME" ./*
  414. rm ./Image.gz
  415. - name: Android 12 boot image build script
  416. if: ${{ inputs.android_version == 'android12' && inputs.use_make == 'false' }}
  417. run: |
  418. echo "Changing to configuration directory: $CONFIG..."
  419. cd bootimgs
  420. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
  421. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  422. # Check if the GKI URL is available
  423. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  424. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  425. if [ "$status" = "200" ]; then
  426. echo "[+] Downloading from GKI_URL"
  427. curl -Lo gki-kernel.zip "$GKI_URL"
  428. else
  429. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  430. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  431. fi
  432. # Unzip the downloaded kernel and remove the zip
  433. echo "Unzipping the downloaded kernel..."
  434. unzip gki-kernel.zip && rm gki-kernel.zip
  435. echo "Unpacking boot.img..."
  436. FULL_PATH=$(pwd)/boot-5.10.img
  437. echo "Unpacking using: $FULL_PATH"
  438. echo "Running unpack_bootimg.py..."
  439. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  440. # Create gzip of the Image file
  441. gzip -n -k -f -9 ./Image > ./Image.gz
  442. echo "Building boot.img"
  443. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  444. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  445. cp ./boot.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  446. echo "Building boot-gz.img"
  447. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  448. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  449. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  450. echo "Building boot-lz4.img"
  451. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  452. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  453. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  454. - name: Android 13/14/15 boot image build script
  455. if: ${{ (inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15') && inputs.use_make == 'false' }}
  456. run: |
  457. cd bootimgs
  458. # Create gzip of the Image file
  459. gzip -n -k -f -9 ./Image > ./Image.gz
  460. echo "Building boot.img"
  461. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  462. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  463. cp ./boot.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  464. echo "Building boot-gz.img"
  465. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  466. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  467. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  468. echo "Building boot-lz4.img"
  469. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  470. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  471. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  472. - name: Compress all img files with gzip
  473. if: ${{ inputs.use_make == 'false' }}
  474. run: |
  475. for image in *.img; do
  476. gzip -vnf9 "$image"
  477. done
  478. - name: Add Build based configs
  479. if: ${{ github.event.inputs.use_make == 'true' }}
  480. run: |
  481. echo "Changing to configuration directory: $CONFIG..."
  482. cd "$CONFIG"
  483. echo "CONFIG_LTO_CLANG_THIN=y" >> ./common/arch/arm64/configs/gki_defconfig
  484. echo "CONFIG_LTO_CLANG=y" >> ./common/arch/arm64/configs/gki_defconfig
  485. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y" >> "./common/arch/arm64/configs/gki_defconfig"
  486. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=n" >> "./common/arch/arm64/configs/gki_defconfig"
  487. - name: Detect Clang Version from Configs
  488. if: ${{ github.event.inputs.use_make == 'true' }}
  489. shell: bash
  490. run: |
  491. KERNEL_PATH="$GITHUB_WORKSPACE/$CONFIG"
  492. DEFCONFIG="$KERNEL_PATH/common/arch/arm64/configs/gki_defconfig"
  493. BUILDCONFIG="$KERNEL_PATH/common/build.config.gki"
  494. CONSTANTSCONFIG="$KERNEL_PATH/common/build.config.constants"
  495. CLANG_VERSION=""
  496. CLANG_BIN_PATH=""
  497. if grep -q '^CONFIG_CLANG_VERSION=' "$DEFCONFIG" 2>/dev/null; then
  498. CLANG_VERSION=$(grep '^CONFIG_CLANG_VERSION=' "$DEFCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | tr -d '"' | xargs)
  499. elif grep -q '^CLANG_VERSION=' "$BUILDCONFIG" 2>/dev/null; then
  500. CLANG_VERSION=$(grep '^CLANG_VERSION=' "$BUILDCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | xargs)
  501. elif grep -q '^CLANG_VERSION=' "$CONSTANTSCONFIG" 2>/dev/null; then
  502. CLANG_VERSION=$(grep '^CLANG_VERSION=' "$CONSTANTSCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | xargs)
  503. CLANG_VERSION="clang-$CLANG_VERSION"
  504. else
  505. echo "No clang version found in config, will auto-detect in prebuilts."
  506. fi
  507. if [ -z "$CLANG_VERSION" ]; then
  508. if [ -d "$KERNEL_PATH/prebuilts/clang/host/linux-x86" ]; then
  509. CLANG_VERSION=$(ls -d "$KERNEL_PATH"/prebuilts/clang/host/linux-x86/clang-r*/ | tail -n 1 | xargs basename)
  510. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin"
  511. elif [ -d "$KERNEL_PATH/prebuilts-master/clang/host/linux-x86" ]; then
  512. CLANG_VERSION=$(ls -d "$KERNEL_PATH"/prebuilts-master/clang/host/linux-x86/clang-r*/ | tail -n 1 | xargs basename)
  513. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts-master/clang/host/linux-x86/$CLANG_VERSION/bin"
  514. else
  515. CLANG_VERSION="clang"
  516. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin" # dummy
  517. fi
  518. else
  519. if [ -d "$KERNEL_PATH/prebuilts/clang/host/linux-x86" ]; then
  520. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin"
  521. else
  522. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts-master/clang/host/linux-x86/$CLANG_VERSION/bin"
  523. fi
  524. fi
  525. echo "Detected CLANG_VERSION: $CLANG_VERSION"
  526. echo "CLANG_VERSION=$CLANG_VERSION" >> $GITHUB_ENV
  527. echo "CLANG_BIN_PATH=$CLANG_BIN_PATH" >> $GITHUB_ENV
  528. - name: Build Kernel
  529. if: ${{ github.event.inputs.use_make == 'true' }}
  530. shell: bash
  531. run: |
  532. KERNEL_PATH="$GITHUB_WORKSPACE/$CONFIG"
  533. CLANG_BIN_PATH="${{ env.CLANG_BIN_PATH }}"
  534. CLANG_VERSION="${{ env.CLANG_VERSION }}"
  535. if [ -d "$CLANG_BIN_PATH" ] && [ -x "$CLANG_BIN_PATH/clang" ]; then
  536. echo "Adding Clang to PATH: $CLANG_BIN_PATH"
  537. export PATH="$CLANG_BIN_PATH:$PATH"
  538. SELECTED_CLANG="$CLANG_BIN_PATH/clang"
  539. elif command -v clang >/dev/null 2>&1; then
  540. SELECTED_CLANG="$(command -v clang)"
  541. echo "Using system Clang: $SELECTED_CLANG"
  542. exit 1
  543. else
  544. echo "Error: No valid Clang binary found"
  545. exit 1
  546. fi
  547. echo "Using Clang version: $($SELECTED_CLANG --version | head -n1)"
  548. LLVM_TOOLS="clang ld.lld llvm-ar llvm-objcopy llvm-objdump llvm-nm"
  549. MISSING_TOOLS=""
  550. for tool in $LLVM_TOOLS; do
  551. if ! command -v $tool >/dev/null 2>&1; then
  552. MISSING_TOOLS="$MISSING_TOOLS $tool"
  553. fi
  554. done
  555. if [ -n "$MISSING_TOOLS" ]; then
  556. echo "Installing missing LLVM tools:$MISSING_TOOLS"
  557. sudo apt-get update
  558. sudo apt-get install -yq --no-install-recommends llvm
  559. for tool in $MISSING_TOOLS; do
  560. if ! command -v $tool >/dev/null 2>&1; then
  561. echo "Error: Failed to install $tool"
  562. exit 1
  563. fi
  564. done
  565. fi
  566. KERNEL_VERSION="${{ inputs.kernel_version }}"
  567. if [[ "$KERNEL_VERSION" == "5.10" ]]; then
  568. USE_LLVM_IAS=true
  569. fi
  570. cd "$KERNEL_PATH/common" || exit 1
  571. MAKE_ARGS="LLVM=1 ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- \
  572. RUSTC=$KERNEL_PATH/prebuilts/rust/linux-x86/1.73.0b/bin/rustc \
  573. PAHOLE=$KERNEL_PATH/prebuilts/kernel-build-tools/linux-x86/bin/pahole \
  574. LD=ld.lld HOSTLD=ld.lld"
  575. if [[ -v USE_LLVM_IAS ]]; then
  576. MAKE_ARGS="LLVM_IAS=1 $MAKE_ARGS"
  577. fi
  578. make -j$(nproc --all) O=out $MAKE_ARGS KCFLAGS+="-Wno-error -O2 -flto=thin -fno-stack-protector" gki_defconfig || exit 1
  579. make -j$(nproc --all) O=out $MAKE_ARGS KCFLAGS+="-Wno-error -O2 -flto=thin -fno-stack-protector" || exit 1
  580. - name: Create Kernel ZIP
  581. if: ${{ github.event.inputs.use_make == 'true' }}
  582. run: |
  583. cp $CONFIG/common/out/arch/arm64/boot/Image AnyKernel3/Image
  584. cd AnyKernel3
  585. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  586. zip -r "../$ZIP_NAME" ./*
  587. - name: Upload Build Artifacts
  588. uses: actions/upload-artifact@v4
  589. with:
  590. name: ${{ inputs.kernelsu_variant }}-kernel-${{ env.CONFIG }}
  591. path: |
  592. *.zip
  593. *.img.gz
  594. *Image*