build-wsa-kernel.yml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. name: WSA Kernel Build
  2. permissions:
  3. contents: write # Allow writing to repository contents (for pushing tags)
  4. actions: write # Allows triggering actions
  5. on:
  6. workflow_call: # This allows this workflow to be called from another workflow
  7. inputs:
  8. android_version:
  9. required: true
  10. type: string
  11. kernel_version:
  12. required: true
  13. type: string
  14. wsa_branch:
  15. required: true
  16. type: string
  17. wsa_arch:
  18. required: true
  19. type: string
  20. runner:
  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. jobs:
  33. build-kernel-kernelsu-susfs:
  34. runs-on: ${{ inputs.runner }}
  35. steps:
  36. - name: Clean up workspace
  37. run: rm -rf ${{ github.workspace }}/*
  38. - name: Install Build Tools
  39. uses: awalsh128/cache-apt-pkgs-action@v1
  40. with:
  41. packages: bc bison build-essential flex libelf-dev binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu gzip ccache
  42. version: 1.0
  43. - name: Cache LLVM
  44. id: cache-llvm
  45. uses: actions/cache@v4
  46. with:
  47. path: ./llvm
  48. key: llvm-12.0.1
  49. - name: Setup LLVM
  50. uses: KyleMayes/install-llvm-action@v1
  51. with:
  52. version: "12.0.1"
  53. force-version: true
  54. ubuntu-version: "16.04"
  55. cached: ${{ steps.cache-llvm.outputs.cache-hit }}
  56. - name: Setup kernel source
  57. uses: actions/checkout@v4
  58. with:
  59. repository: microsoft/WSA-Linux-Kernel
  60. ref: android-lts/latte-2/${{ inputs.wsa_branch }}
  61. path: WSA-Linux-Kernel-${{ inputs.wsa_arch }}
  62. - name: Set CONFIG Environment Variable
  63. run: |
  64. # Set CONFIG dynamically based on inputs values
  65. CONFIG="WSA-Linux-Kernel-${{ inputs.wsa_arch }}"
  66. # Set CONFIG as an environment variable for future steps
  67. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  68. echo "CONFIG set to: $CONFIG"
  69. - name: Clone AnyKernel3 and Other Dependencies
  70. run: |
  71. echo "Cloning AnyKernel3 and other dependencies..."
  72. # Define the branch names using the inputs values
  73. ANYKERNEL_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  74. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  75. # Debug print the branches
  76. echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
  77. echo "Using branch for SUSFS: $SUSFS_BRANCH"
  78. # Clone repositories using the branch names
  79. git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  80. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  81. git clone https://github.com/WildPlusKernel/kernel_patches.git
  82. - name: Determine the branch for KernelSU
  83. run: |
  84. if [[ "${{ inputs.kernelsu_branch }}" == "Stable" ]]; then
  85. echo "BRANCH=-" >> $GITHUB_ENV
  86. elif [[ "${{ inputs.kernelsu_branch }}" == "Dev" && ( "${{ inputs.kernelsu_variant }}" == "Official" || "${{ inputs.kernelsu_variant }}" == "MKSU" ) ]]; then
  87. echo "BRANCH=-s main" >> $GITHUB_ENV
  88. elif [[ "${{ inputs.kernelsu_branch }}" == "Dev" && "${{ inputs.kernelsu_variant }}" == "Next" ]]; then
  89. echo "BRANCH=-s main" >> $GITHUB_ENV
  90. elif [[ "${{ inputs.kernelsu_branch }}" == "Other" && -n "${{ inputs.kernelsu_branch_other }}" ]]; then
  91. echo "BRANCH=-s ${{ inputs.kernelsu_branch_other }}" >> $GITHUB_ENV
  92. else
  93. echo "Error: Custom branch not provided for 'Other'" >&2
  94. exit 1
  95. fi
  96. - name: Add KernelSU
  97. run: |
  98. echo "Changing to configuration directory: $CONFIG..."
  99. cd "$CONFIG"
  100. if [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then
  101. echo "Adding KernelSU Official..."
  102. curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash $BRANCH
  103. elif [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then
  104. echo "Adding KernelSU Next..."
  105. curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash $BRANCH
  106. elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then
  107. echo "Adding KernelSU MKSU..."
  108. curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash $BRANCH
  109. # Revert commit of remove pts_unix98_lookup_pre
  110. cd KernelSU
  111. git revert -m 1 $(git log --grep="remove devpts hook" --pretty=format:"%h") -n
  112. KSU_VERSION=$(expr $(/usr/bin/git rev-list --count HEAD) "+" 12063)
  113. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  114. sed -i "s/DKSU_VERSION=16/DKSU_VERSION=${KSU_VERSION}/" kernel/Makefile
  115. else
  116. echo "Invalid KernelSU variant selected!"
  117. exit 1
  118. fi
  119. - name: Apply SUSFS Patches for KernelSU Variants
  120. run: |
  121. echo "Changing to configuration directory: $CONFIG..."
  122. cd "$CONFIG"
  123. echo "Applying SUSFS patches..."
  124. # Copy SUSFS patches
  125. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./
  126. cp ../susfs4ksu/kernel_patches/fs/* ./fs/
  127. cp ../susfs4ksu/kernel_patches/include/linux/* ./include/linux/
  128. if [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then
  129. echo "Applying SUSFS patches for Official KernelSU..."
  130. cd ./KernelSU
  131. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  132. patch -p1 --forward < 10_enable_susfs_for_ksu.patch
  133. elif [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then
  134. echo "Applying SUSFS patches for KernelSU-Next..."
  135. cd ./KernelSU-Next
  136. cp ../../kernel_patches/KernelSU-Next-Implement-SUSFS-v1.5.5-Universal.patch ./
  137. patch -p1 --forward < KernelSU-Next-Implement-SUSFS-v1.5.5-Universal.patch || true
  138. elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then
  139. echo "Applying SUSFS patches for MKSU..."
  140. cd ./KernelSU
  141. cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  142. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  143. echo "Applying MKSU specific SUSFS patch..."
  144. cp ../../kernel_patches/mksu_susfs.patch ../KernelSU/
  145. patch -p1 < mksu_susfs.patch
  146. else
  147. echo "Invalid KernelSU variant selected!"
  148. exit 1
  149. fi
  150. # Change to common directory and apply common SUSFS patch
  151. cd ../
  152. patch -p1 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
  153. - name: Add SUSFS Configuration Settings
  154. run: |
  155. echo "Changing to configuration directory: $CONFIG..."
  156. cd "$CONFIG"
  157. echo "Adding configuration settings to gki_defconfig..."
  158. declare -A ARCH_MAP=(["x86_64"]="x64" ["arm64"]="arm64")
  159. cp configs/wsa/config-wsa-${ARCH_MAP[${{ inputs.wsa_arch }}]} .config
  160. echo "startofsus" >> .config
  161. # Add SUSFS configuration settings
  162. echo "CONFIG_KSU=y" >> .config
  163. echo "CONFIG_KSU_SUSFS=y" >> .config
  164. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> .config
  165. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> .config
  166. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> .config
  167. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> .config
  168. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> .config
  169. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> .config
  170. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> .config
  171. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> .config
  172. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> .config
  173. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> .config
  174. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> .config
  175. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> .config
  176. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> .config
  177. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> .config
  178. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> .config
  179. # Add additional tmpfs config setting
  180. echo "CONFIG_TMPFS_XATTR=y" >> .config
  181. echo "CONFIG_TMPFS_POSIX_ACL=y" >> .config
  182. echo "CONFIG_FANOTIFY=n" >> .config
  183. echo "endofsus" >> .config
  184. - name: Build the Kernel
  185. run: |
  186. echo "Changing to configuration directory: $CONFIG..."
  187. cd "$CONFIG"
  188. sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./scripts/setlocalversion
  189. # Run perl command to modify UTS_VERSION
  190. perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sat Apr 20 04:20:00 UTC 2024"}' ./scripts/mkcompile_h
  191. sed -i 's/-dirty//' ./scripts/setlocalversion
  192. sed -i 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION="-Wild+"/' ./scripts/setlocalversion
  193. make olddefconfig
  194. declare -A FILE_NAME=(["x86_64"]="bzImage" ["arm64"]="Image")
  195. make -j`nproc` LLVM=1 ARCH=${{ inputs.wsa_arch }} $(if [ "${{ inputs.wsa_arch }}" == "arm64" ]; then echo CROSS_COMPILE=aarch64-linux-gnu; fi) ${FILE_NAME[${{ inputs.wsa_arch }}]}
  196. declare -A ARCH_MAP_FILE=(["x86_64"]="x86" ["arm64"]="arm64")
  197. echo "file_path=WSA-Linux-Kernel-${{ inputs.wsa_arch }}/arch/${ARCH_MAP_FILE[${{ inputs.wsa_arch }}]}/boot/${FILE_NAME[${{ inputs.wsa_arch }}]}" >> $GITHUB_ENV
  198. - name: Upload Build Artifacts
  199. uses: actions/upload-artifact@v4
  200. with:
  201. name: kernel-${{ env.CONFIG }}
  202. path: "${{ env.file_path }}"