build.yml 30 KB

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