build.yml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. name: Kernel Build Process
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. android_version:
  9. required: true
  10. type: string
  11. kernel_version:
  12. required: true
  13. type: string
  14. sub_level:
  15. required: true
  16. type: string
  17. os_patch_level:
  18. required: true
  19. type: string
  20. revision:
  21. required: false
  22. type: string
  23. jobs:
  24. build-gki:
  25. runs-on: ubuntu-latest
  26. timeout-minutes: 120
  27. strategy:
  28. matrix:
  29. build_type: ["make", "normal"]
  30. apply_symbol_fix: [true, false]
  31. steps:
  32. # # - name: Maximize Build Space
  33. # uses: AdityaGarg8/remove-unwanted-software@v5
  34. # with:
  35. # remove-dotnet: 'true' # Frees ~2 GB
  36. # remove-android: 'true' # Frees ~9 GB
  37. # remove-haskell: 'true' # Frees ~5.2 GB
  38. # remove-codeql: 'true' # Frees ~5.4 GB
  39. # remove-docker-images: 'true' # Frees ~3.2 GB
  40. # remove-large-packages: 'true' # Frees ~3.1 GB
  41. # remove-swapfile: 'true' # Frees ~4 GB
  42. # remove-cached-tools: 'false' # Avoid unless confirmed safe
  43. # verbose: 'true' # Enable detailed logging
  44. - name: Set CONFIG Environment Variable
  45. run: |
  46. # Set CONFIG dynamically based on inputs values
  47. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  48. # Set CONFIG as an environment variable for future steps
  49. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  50. - name: Setup Build Environment
  51. run: |
  52. sudo apt update && sudo apt install -y libelf-dev libssl-dev build-essential
  53. AOSP_MIRROR=https://android.googlesource.com
  54. BRANCH=main-kernel-2025
  55. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools &
  56. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg &
  57. wait
  58. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  59. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  60. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  61. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  62. echo "PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin:$PATH" >> $GITHUB_ENV
  63. mkdir -p ./git-repo
  64. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  65. chmod a+rx ./git-repo/repo
  66. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  67. - name: Set boot sign key
  68. env:
  69. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  70. run: |
  71. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  72. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  73. fi
  74. - name: Clone AnyKernel3 and Other Dependencies
  75. run: |
  76. ANYKERNEL_BRANCH="gki-2.0"
  77. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  78. git clone https://github.com/WildKernels/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  79. git clone https://github.com/WildKernels/kernel_patches.git
  80. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  81. # Checkout specific commits for certain Android/kernel version combinations
  82. if [ "${{ inputs.android_version }}-${{ inputs.kernel_version }}" = "android12-5.10" ]; then
  83. cd susfs4ksu
  84. git checkout 0ed20c1656af7806a1760837ad320e62a8fb40fd
  85. cd ..
  86. elif [ "${{ inputs.android_version }}-${{ inputs.kernel_version }}" = "android13-5.10" ]; then
  87. cd susfs4ksu
  88. git checkout 19e5b616464577c986e079cea0700428422bccb5
  89. cd ..
  90. elif [ "${{ inputs.android_version }}-${{ inputs.kernel_version }}" = "android13-5.15" ]; then
  91. cd susfs4ksu
  92. git checkout b443e5be35cd8275b97a776f8cc84fbbf8169749
  93. cd ..
  94. elif [ "${{ inputs.android_version }}-${{ inputs.kernel_version }}" = "android14-5.15" ]; then
  95. cd susfs4ksu
  96. git checkout 40823c6a92d072721c2c05f37776f69e3689ce8f
  97. cd ..
  98. elif [ "${{ inputs.android_version }}-${{ inputs.kernel_version }}" = "android14-6.1" ]; then
  99. cd susfs4ksu
  100. git checkout 0e19a05277d28182c7b653580117145c53e69e92
  101. cd ..
  102. elif [ "${{ inputs.android_version }}-${{ inputs.kernel_version }}" = "android15-6.6" ]; then
  103. cd susfs4ksu
  104. git checkout ef036830ec9d56035d63d328185281c09726b20f
  105. cd ..
  106. fi
  107. - name: Initialize and Sync Kernel Source
  108. run: |
  109. mkdir -p "$CONFIG"
  110. cd "$CONFIG"
  111. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  112. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  113. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  114. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  115. if grep -q deprecated <<< $REMOTE_BRANCH; then
  116. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  117. fi
  118. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  119. - name: Extract Actual Sublevel for LTS Builds
  120. if: inputs.sub_level == 'X'
  121. run: |
  122. cd "$CONFIG/common"
  123. if [ -f "Makefile" ]; then
  124. ACTUAL_SUBLEVEL=$(grep '^SUBLEVEL = ' Makefile | awk '{print $3}')
  125. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  126. OLD_CONFIG="$CONFIG"
  127. NEW_CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-$ACTUAL_SUBLEVEL"
  128. echo "CONFIG=$NEW_CONFIG" >> $GITHUB_ENV
  129. echo "ACTUAL_SUBLEVEL=$ACTUAL_SUBLEVEL" >> $GITHUB_ENV
  130. cd ../..
  131. if [ -d "$OLD_CONFIG" ]; then
  132. mv "$OLD_CONFIG" "$NEW_CONFIG"
  133. fi
  134. fi
  135. fi
  136. - name: Apply glibc 2.38 Compatibility Fix
  137. if: inputs.android_version == 'android14' && inputs.kernel_version == '6.1'
  138. run: |
  139. if [ ! -e build/build.sh ]; then
  140. GLIBC_VERSION=$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')
  141. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n1)" = "2.38" ]; then
  142. cd $CONFIG/common/ && sed -i '/\$(Q)\$(MAKE) -C \$(SUBCMD_SRC) OUTPUT=\$(abspath \$(dir \$@))\/ \$(abspath \$@)/s//$(Q)$(MAKE) -C $(SUBCMD_SRC) EXTRA_CFLAGS="$(CFLAGS)" OUTPUT=$(abspath $(dir $@))\/ $(abspath $@)/' tools/bpf/resolve_btfids/Makefile 2>/dev/null || true
  143. fi
  144. fi
  145. - name: Fix Less Then 6.6.50 Builds
  146. if: inputs.android_version == 'android15' && inputs.kernel_version == '6.6'
  147. run: |
  148. cd "$CONFIG/common"
  149. if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
  150. sed -i '/#include <trace\/hooks\/blk.h>/a #include <trace\/hooks\/fs.h>' ./fs/namespace.c
  151. fi
  152. - name: Apply ptrace patch for older kernels
  153. if: fromJSON(inputs.kernel_version) < 5.16
  154. run: |
  155. cd "$CONFIG/common"
  156. patch -p1 -F 3 < "../../kernel_patches/gki_ptrace.patch"
  157. - name: Add KernelSU
  158. run: |
  159. cd "$CONFIG"
  160. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash -s wild
  161. - name: Apply SUSFS Patches for KernelSU Variants
  162. run: |
  163. cd "$CONFIG"
  164. # Apply core SUSFS patches
  165. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  166. cd common
  167. patch -p1 --forward < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch
  168. cd ..
  169. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  170. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  171. # Apply KSU integration patches
  172. cd ./Wild_KSU
  173. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch .
  174. #cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.10/10_enable_susfs_for_ksu.patch ./
  175. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  176. # Apply compatibility fixes
  177. cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.10/fix_core_hook.c.patch ./
  178. patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
  179. ## Skip fix_rules.c.patch for Android 14 with kernel 6.1
  180. #if [ "${{ inputs.android_version }}" != "android14" ] && [ "${{ inputs.kernel_version }}" != "6.1" ]; then
  181. # cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.10/fix_rules.c.patch ./
  182. # patch -p1 --forward < fix_rules.c.patch
  183. #fi
  184. cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.10/fix_sucompat.c.patch ./
  185. patch -p1 --forward < fix_sucompat.c.patch
  186. cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.10/fix_kernel_compat.c.patch ./
  187. patch -p1 --forward < fix_kernel_compat.c.patch
  188. - name: Getting KernelSU Version
  189. run: |
  190. cd "$CONFIG/Wild_KSU/kernel"
  191. BASE_VERSION=10200
  192. COMMIT_COUNT=$(/usr/bin/git rev-list --count HEAD)
  193. KSU_VERSION=$(expr $COMMIT_COUNT "+" $BASE_VERSION)
  194. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  195. - name: Apply Hooks Patches
  196. run: |
  197. cd "$CONFIG/common"
  198. cp ../../kernel_patches/wild/hooks/scope_min_manual_hooks_v1.4.patch ./
  199. patch -p1 --forward -F 3 < scope_min_manual_hooks_v1.4.patch
  200. - name: Apply Module Symbol Version Fix Patch
  201. if: ${{ matrix.apply_symbol_fix }}
  202. run: |
  203. if [[ "${{ inputs.kernel_version }}" == "6.1" || "${{ inputs.kernel_version }}" == "6.6" ]]; then
  204. cd "$CONFIG/common/kernel/module"
  205. #sed -i 's/pr_warn("%s: disagrees about version of symbol %s\\n"/pr_warn("%s: disagrees about version of symbol %s, but ignore...\\n"/' version.c
  206. sed -i '/bad_version:/{:a;n;/return 0;/{s/return 0;/return 1;/;b};ba}' version.c
  207. else
  208. cd "$CONFIG/common/kernel"
  209. #sed -i 's/pr_warn("%s: disagrees about version of symbol %s\\n"/pr_warn("%s: disagrees about version of symbol %s, but ignore...\\n"/' module.c
  210. sed -i '/bad_version:/{:a;n;/return 0;/{s/return 0;/return 1;/;b};ba}' module.c
  211. fi
  212. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  213. if: ${{ ( inputs.kernel_version == '6.6' ) }}
  214. run: |
  215. SYMBOL_LIST=$CONFIG/common/android/abi_gki_aarch64_galaxy
  216. echo "kdp_set_cred_non_rcu" >> $SYMBOL_LIST
  217. echo "kdp_usecount_dec_and_test" >> $SYMBOL_LIST
  218. echo "kdp_usecount_inc" >> $SYMBOL_LIST
  219. cd $CONFIG/common
  220. PATCH="../../kernel_patches/samsung/min_kdp/add-min_kdp-symbols.patch"
  221. if patch -p1 --dry-run < $PATCH; then
  222. patch -p1 --no-backup-if-mismatch < $PATCH
  223. fi
  224. cd drivers
  225. cp "../../../kernel_patches/samsung/min_kdp/min_kdp.c" min_kdp.c
  226. echo "obj-y += min_kdp.o" >> Makefile
  227. - name: Apply Kernel Configuration
  228. run: |
  229. cd "$CONFIG"
  230. defconfig="./common/arch/arm64/configs/gki_defconfig"
  231. echo "Applying kernel configurations one by one..."
  232. # KernelSU Core Configuration
  233. echo "CONFIG_KSU=y" >> "$defconfig"
  234. echo "CONFIG_KSU_KPROBES_HOOK=n" >> "$defconfig"
  235. # Mountify Support
  236. echo "CONFIG_TMPFS_XATTR=y" >> "$defconfig"
  237. echo "CONFIG_TMPFS_POSIX_ACL=y" >> "$defconfig"
  238. # Networking Configuration
  239. echo "CONFIG_IP_NF_TARGET_TTL=y" >> "$defconfig"
  240. echo "CONFIG_IP6_NF_TARGET_HL=y" >> "$defconfig"
  241. echo "CONFIG_IP6_NF_MATCH_HL=y" >> "$defconfig"
  242. # BBR TCP Congestion Control
  243. echo "CONFIG_TCP_CONG_ADVANCED=y" >> "$defconfig"
  244. echo "CONFIG_TCP_CONG_BBR=y" >> "$defconfig"
  245. echo "CONFIG_NET_SCH_FQ=y" >> "$defconfig"
  246. echo "CONFIG_TCP_CONG_BIC=n" >> "$defconfig"
  247. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> "$defconfig"
  248. echo "CONFIG_TCP_CONG_HTCP=n" >> "$defconfig"
  249. # IPSet support
  250. echo "CONFIG_IP_SET=y" >> "$defconfig"
  251. echo "CONFIG_IP_SET_MAX=256" >> "$defconfig"
  252. echo "CONFIG_IP_SET_BITMAP_IP=y" >> "$defconfig"
  253. echo "CONFIG_IP_SET_BITMAP_IPMAC=y" >> "$defconfig"
  254. echo "CONFIG_IP_SET_BITMAP_PORT=y" >> "$defconfig"
  255. echo "CONFIG_IP_SET_HASH_IP=y" >> "$defconfig"
  256. echo "CONFIG_IP_SET_HASH_IPPORT=y" >> "$defconfig"
  257. echo "CONFIG_IP_SET_HASH_IPPORTIP=y" >> "$defconfig"
  258. echo "CONFIG_IP_SET_HASH_IPPORTNET=y" >> "$defconfig"
  259. echo "CONFIG_IP_SET_HASH_NET=y" >> "$defconfig"
  260. echo "CONFIG_IP_SET_HASH_NETNET=y" >> "$defconfig"
  261. echo "CONFIG_IP_SET_HASH_NETPORT=y" >> "$defconfig"
  262. echo "CONFIG_IP_SET_HASH_NETIFACE=y" >> "$defconfig"
  263. # SUSFS Configuration
  264. echo "CONFIG_KSU_SUSFS=y" >> "$defconfig"
  265. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> "$defconfig"
  266. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> "$defconfig"
  267. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> "$defconfig"
  268. # SUSFS Auto Mount Features
  269. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> "$defconfig"
  270. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> "$defconfig"
  271. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> "$defconfig"
  272. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> "$defconfig"
  273. # SUSFS Advanced Features
  274. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> "$defconfig"
  275. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> "$defconfig"
  276. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> "$defconfig"
  277. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> "$defconfig"
  278. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> "$defconfig"
  279. # SUSFS Debugging and Security
  280. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> "$defconfig"
  281. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> "$defconfig"
  282. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> "$defconfig"
  283. # Build Optimization Configuration
  284. echo "CONFIG_LTO_CLANG_THIN=y" >> "$defconfig"
  285. echo "CONFIG_LTO_CLANG=y" >> "$defconfig"
  286. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y" >> "$defconfig"
  287. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=n" >> "$defconfig"
  288. # Remove check_defconfig
  289. sed -i 's/check_defconfig//' ./common/build.config.gki
  290. - name: Change Kernel Name
  291. run: |
  292. cd "$CONFIG"
  293. perl -pi -e 's/-dirty//' ./common/scripts/setlocalversion
  294. perl -pi -e 's/-maybe-dirty//g' ./build/kernel/kleaf/impl/stamp.bzl
  295. #Set Kernel Timestamp
  296. 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
  297. #Set Kernel Name
  298. if [ "${{ matrix.build_type }}" = "make" ] && [ "${{ inputs.kernel_version }}" = "6.6" ]; then
  299. perl -0777 -pi -e 's/(echo "\$\{KERNELVERSION\}\$\{file_localversion\}\$\{config_localversion\}\$\{LOCALVERSION\}\$\{scm_version\}")/echo "\$\{KERNELVERSION\}-${{ inputs.android_version }}-Wild"/s' ./common/scripts/setlocalversion
  300. elif [ "${{ matrix.build_type }}" = "make" ]; then
  301. perl -0777 -pi -e 's/(echo "\$res")(?!.*echo "\$res")/echo "\-${{ inputs.android_version }}-Wild"/s' ./common/scripts/setlocalversion
  302. elif [ "${{ matrix.build_type }}" = "normal" ] && [ "${{ inputs.kernel_version }}" = "6.6" ]; then
  303. perl -0777 -pi -e 's/(echo "\$\{KERNELVERSION\}\$\{file_localversion\}\$\{config_localversion\}\$\{LOCALVERSION\}\$\{scm_version\}")/echo "\$\{KERNELVERSION\}\$\{file_localversion\}\$\{config_localversion\}\$\{LOCALVERSION\}\$\{scm_version\}-Wild"/s' ./common/scripts/setlocalversion
  304. elif [ "${{ matrix.build_type }}" = "normal" ]; then
  305. perl -0777 -pi -e 's/(echo "\$res")(?!.*echo "\$res")/echo "\$res-Wild"/s' ./common/scripts/setlocalversion
  306. fi
  307. #Set Kernel Timestamp
  308. 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
  309. #Remove Abi Exports and Error
  310. rm -rf ./common/android/abi_gki_protected_exports_*
  311. perl -pi -e 's/^\s*"protected_exports_list"\s*:\s*"android\/abi_gki_protected_exports_aarch64",\s*$//;' ./common/BUILD.bazel
  312. - name: Build
  313. if: ${{ matrix.build_type == 'normal' }}
  314. run : |
  315. set -e
  316. set -x
  317. cd "$CONFIG"
  318. echo "Building the kernel..."
  319. if [ -f "build/build.sh" ]; then
  320. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh || exit 1
  321. else
  322. tools/bazel build --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  323. fi
  324. - name: Detect Clang Version from Configs
  325. if: ${{ matrix.build_type == 'make' }}
  326. run: |
  327. KERNEL_PATH="$GITHUB_WORKSPACE/$CONFIG"
  328. DEFCONFIG="$KERNEL_PATH/common/arch/arm64/configs/gki_defconfig"
  329. BUILDCONFIG="$KERNEL_PATH/common/build.config.gki"
  330. CONSTANTSCONFIG="$KERNEL_PATH/common/build.config.constants"
  331. CLANG_VERSION=""
  332. CLANG_BIN_PATH=""
  333. if grep -q '^CONFIG_CLANG_VERSION=' "$DEFCONFIG" 2>/dev/null; then
  334. CLANG_VERSION=$(grep '^CONFIG_CLANG_VERSION=' "$DEFCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | tr -d '"' | xargs)
  335. elif grep -q '^CLANG_VERSION=' "$BUILDCONFIG" 2>/dev/null; then
  336. CLANG_VERSION=$(grep '^CLANG_VERSION=' "$BUILDCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | xargs)
  337. elif grep -q '^CLANG_VERSION=' "$CONSTANTSCONFIG" 2>/dev/null; then
  338. CLANG_VERSION=$(grep '^CLANG_VERSION=' "$CONSTANTSCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | xargs)
  339. CLANG_VERSION="clang-$CLANG_VERSION"
  340. else
  341. echo "No clang version found in config, will auto-detect in prebuilts."
  342. fi
  343. if [ -z "$CLANG_VERSION" ]; then
  344. if [ -d "$KERNEL_PATH/prebuilts/clang/host/linux-x86" ]; then
  345. CLANG_VERSION=$(ls -d "$KERNEL_PATH"/prebuilts/clang/host/linux-x86/clang-r*/ | tail -n 1 | xargs basename)
  346. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin"
  347. elif [ -d "$KERNEL_PATH/prebuilts-master/clang/host/linux-x86" ]; then
  348. CLANG_VERSION=$(ls -d "$KERNEL_PATH"/prebuilts-master/clang/host/linux-x86/clang-r*/ | tail -n 1 | xargs basename)
  349. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts-master/clang/host/linux-x86/$CLANG_VERSION/bin"
  350. else
  351. CLANG_VERSION="clang"
  352. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin" # dummy
  353. fi
  354. else
  355. if [ -d "$KERNEL_PATH/prebuilts/clang/host/linux-x86" ]; then
  356. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin"
  357. else
  358. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts-master/clang/host/linux-x86/$CLANG_VERSION/bin"
  359. fi
  360. fi
  361. echo "CLANG_VERSION=$CLANG_VERSION" >> $GITHUB_ENV
  362. echo "CLANG_BIN_PATH=$CLANG_BIN_PATH" >> $GITHUB_ENV
  363. - name: Build Kernel
  364. if: ${{ matrix.build_type == 'make' }}
  365. run: |
  366. KERNEL_PATH="$GITHUB_WORKSPACE/$CONFIG"
  367. CLANG_BIN_PATH="${{ env.CLANG_BIN_PATH }}"
  368. CLANG_VERSION="${{ env.CLANG_VERSION }}"
  369. if [ -d "$CLANG_BIN_PATH" ] && [ -x "$CLANG_BIN_PATH/clang" ]; then
  370. export PATH="$CLANG_BIN_PATH:$PATH"
  371. SELECTED_CLANG="$CLANG_BIN_PATH/clang"
  372. elif command -v clang >/dev/null 2>&1; then
  373. SELECTED_CLANG="$(command -v clang)"
  374. exit 1
  375. else
  376. exit 1
  377. fi
  378. LLVM_TOOLS="clang ld.lld llvm-ar llvm-objcopy llvm-objdump llvm-nm"
  379. MISSING_TOOLS=""
  380. for tool in $LLVM_TOOLS; do
  381. if ! command -v $tool >/dev/null 2>&1; then
  382. MISSING_TOOLS="$MISSING_TOOLS $tool"
  383. fi
  384. done
  385. if [ -n "$MISSING_TOOLS" ]; then
  386. sudo apt-get update
  387. sudo apt-get install -yq --no-install-recommends llvm
  388. for tool in $MISSING_TOOLS; do
  389. if ! command -v $tool >/dev/null 2>&1; then
  390. exit 1
  391. fi
  392. done
  393. fi
  394. KERNEL_VERSION="${{ inputs.kernel_version }}"
  395. if [[ "$KERNEL_VERSION" == "5.10" ]]; then
  396. USE_LLVM_IAS=true
  397. fi
  398. cd "$KERNEL_PATH/common" || exit 1
  399. MAKE_ARGS="LLVM=1 ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- \
  400. RUSTC=$KERNEL_PATH/prebuilts/rust/linux-x86/1.73.0b/bin/rustc \
  401. PAHOLE=$KERNEL_PATH/prebuilts/kernel-build-tools/linux-x86/bin/pahole \
  402. LD=ld.lld HOSTLD=ld.lld"
  403. if [[ -v USE_LLVM_IAS ]]; then
  404. MAKE_ARGS="LLVM_IAS=1 $MAKE_ARGS"
  405. fi
  406. make -j$(nproc --all) O=out $MAKE_ARGS KCFLAGS+="-Wno-error -O2 -flto=thin -fno-stack-protector" gki_defconfig Image Image.gz Image.lz4 || exit 1
  407. make -j$(nproc --all) O=out $MAKE_ARGS KCFLAGS+="-Wno-error -O2 -flto=thin -fno-stack-protector" || exit 1
  408. - name: Create AK3 ZIP
  409. run: |
  410. # Try different Image locations based on build type
  411. if [ -f "$CONFIG/common/out/arch/arm64/boot/Image" ]; then
  412. cp $CONFIG/common/out/arch/arm64/boot/Image AnyKernel3/Image
  413. elif [ -f "./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image" ]; then
  414. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image AnyKernel3/Image
  415. elif [ -f "./$CONFIG/bazel-bin/common/kernel_aarch64/Image" ]; then
  416. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image AnyKernel3/Image
  417. else
  418. echo "Error: Image file not found in any expected location"
  419. exit 1
  420. fi
  421. cd AnyKernel3
  422. # Use actual sublevel for LTS builds if available
  423. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  424. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  425. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  426. fi
  427. ZIP_NAME="WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  428. zip -r "../$ZIP_NAME" ./*
  429. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  430. if: ${{ matrix.build_type == 'make' }}
  431. run: |
  432. mkdir bootimgs
  433. echo "Creating bootimgs folder and copying images..."
  434. cp $CONFIG/common/out/arch/arm64/boot/Image ./bootimgs
  435. cp $CONFIG/common/out/arch/arm64/boot/Image.gz ./bootimgs
  436. cp $CONFIG/common/out/arch/arm64/boot/Image.lz4 ./bootimgs
  437. cp $CONFIG/common/out/arch/arm64/boot/Image ./
  438. cp $CONFIG/common/out/arch/arm64/boot/Image.gz ./
  439. cp $CONFIG/common/out/arch/arm64/boot/Image.lz4 ./
  440. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  441. if: ${{ (inputs.android_version == 'android12' || inputs.android_version == 'android13') && matrix.build_type == 'normal' }}
  442. run: |
  443. mkdir bootimgs
  444. echo "Creating bootimgs folder and copying images..."
  445. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
  446. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
  447. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
  448. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
  449. # Create gzip of the Image file
  450. gzip -n -k -f -9 ./Image > ./Image.gz
  451. gzip -n -k -f -9 ./Image > ./bootimgs/Image.gz
  452. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  453. if: ${{ (inputs.android_version == 'android14' || inputs.android_version == 'android15') && matrix.build_type == 'normal' }}
  454. run: |
  455. mkdir bootimgs
  456. echo "Creating bootimgs folder and copying images..."
  457. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  458. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  459. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
  460. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
  461. # Create gzip of the Image file
  462. gzip -n -k -f -9 ./Image > ./Image.gz
  463. gzip -n -k -f -9 ./Image > ./bootimgs/Image.gz
  464. - name: Android 12 boot image build script
  465. if: ${{ inputs.android_version == 'android12' }}
  466. run: |
  467. echo "Changing to configuration directory: $CONFIG..."
  468. cd bootimgs
  469. # Prepare sublevel for naming
  470. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  471. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  472. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  473. fi
  474. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
  475. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  476. # Check if the GKI URL is available
  477. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  478. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  479. if [ "$status" = "200" ]; then
  480. echo "[+] Downloading from GKI_URL"
  481. curl -Lo gki-kernel.zip "$GKI_URL"
  482. else
  483. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  484. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  485. fi
  486. # Unzip the downloaded kernel and remove the zip
  487. echo "Unzipping the downloaded kernel..."
  488. unzip gki-kernel.zip && rm gki-kernel.zip
  489. echo "Unpacking boot.img..."
  490. FULL_PATH=$(pwd)/boot-5.10.img
  491. echo "Unpacking using: $FULL_PATH"
  492. echo "Running unpack_bootimg.py..."
  493. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  494. echo "Building boot.img"
  495. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  496. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  497. cp ./boot.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot.img
  498. echo "Building boot-gz.img"
  499. $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 }}"
  500. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  501. cp ./boot-gz.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-gz.img
  502. echo "Building boot-lz4.img"
  503. $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 }}"
  504. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  505. cp ./boot-lz4.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-lz4.img
  506. - name: Android 13/14/15 boot image build script
  507. if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  508. run: |
  509. cd bootimgs
  510. # Prepare sublevel for naming
  511. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  512. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  513. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  514. fi
  515. echo "Building boot.img"
  516. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  517. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  518. cp ./boot.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot.img
  519. echo "Building boot-gz.img"
  520. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  521. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  522. cp ./boot-gz.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-gz.img
  523. echo "Building boot-lz4.img"
  524. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  525. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  526. cp ./boot-lz4.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-lz4.img
  527. - name: Upload Build Artifacts
  528. uses: actions/upload-artifact@v4
  529. with:
  530. name: WKSU-${{ env.KSUVER }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ env.ACTUAL_SUBLEVEL || inputs.sub_level }}-${{ inputs.os_patch_level }}-${{ matrix.build_type }}-${{ matrix.apply_symbol_fix && 'SymbolFix'}}
  531. path: |
  532. *.zip
  533. *.img