build.yml 33 KB

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