build.yml 28 KB

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