build.yml 34 KB

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