name: WSA Kernel Build permissions: contents: write # Allow writing to repository contents (for pushing tags) actions: write # Allows triggering actions on: workflow_call: # This allows this workflow to be called from another workflow inputs: android_version: required: true type: string kernel_version: required: true type: string wsa_branch: required: true type: string wsa_arch: required: true type: string runner: required: true type: string kernelsu_variant: required: true type: string kernelsu_branch: required: true type: string kernelsu_branch_other: required: false type: string jobs: build-kernel-kernelsu-susfs: runs-on: ${{ inputs.runner }} steps: - name: Clean up workspace run: rm -rf ${{ github.workspace }}/* - name: Install Build Tools uses: awalsh128/cache-apt-pkgs-action@v1 with: packages: bc bison build-essential flex libelf-dev binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu gzip ccache version: 1.0 - name: Cache LLVM id: cache-llvm uses: actions/cache@v4 with: path: ./llvm key: llvm-12.0.1 - name: Setup LLVM uses: KyleMayes/install-llvm-action@v1 with: version: "12.0.1" force-version: true ubuntu-version: "16.04" cached: ${{ steps.cache-llvm.outputs.cache-hit }} - name: Setup kernel source uses: actions/checkout@v4 with: repository: microsoft/WSA-Linux-Kernel ref: android-lts/latte-2/${{ inputs.wsa_branch }} path: WSA-Linux-Kernel-${{ inputs.wsa_arch }} - name: Set CONFIG Environment Variable run: | # Set CONFIG dynamically based on inputs values CONFIG="WSA-Linux-Kernel-${{ inputs.wsa_arch }}" # Set CONFIG as an environment variable for future steps echo "CONFIG=$CONFIG" >> $GITHUB_ENV echo "CONFIG set to: $CONFIG" - name: Clone AnyKernel3 and Other Dependencies run: | echo "Cloning AnyKernel3 and other dependencies..." # Define the branch names using the inputs values ANYKERNEL_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}" SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}" # Debug print the branches echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH" echo "Using branch for SUSFS: $SUSFS_BRANCH" # Clone repositories using the branch names git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH" git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH" git clone https://github.com/WildPlusKernel/kernel_patches.git - name: Determine the branch for KernelSU run: | if [[ "${{ inputs.kernelsu_branch }}" == "Stable" ]]; then echo "BRANCH=-" >> $GITHUB_ENV elif [[ "${{ inputs.kernelsu_branch }}" == "Dev" && ( "${{ inputs.kernelsu_variant }}" == "Official" || "${{ inputs.kernelsu_variant }}" == "MKSU" ) ]]; then echo "BRANCH=-s main" >> $GITHUB_ENV elif [[ "${{ inputs.kernelsu_branch }}" == "Dev" && "${{ inputs.kernelsu_variant }}" == "Next" ]]; then echo "BRANCH=-s main" >> $GITHUB_ENV elif [[ "${{ inputs.kernelsu_branch }}" == "Other" && -n "${{ inputs.kernelsu_branch_other }}" ]]; then echo "BRANCH=-s ${{ inputs.kernelsu_branch_other }}" >> $GITHUB_ENV else echo "Error: Custom branch not provided for 'Other'" >&2 exit 1 fi - name: Add KernelSU run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" if [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then echo "Adding KernelSU Official..." curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash $BRANCH elif [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then echo "Adding KernelSU Next..." curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash $BRANCH elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then echo "Adding KernelSU MKSU..." curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash $BRANCH # Revert commit of remove pts_unix98_lookup_pre cd KernelSU git revert -m 1 $(git log --grep="remove devpts hook" --pretty=format:"%h") -n KSU_VERSION=$(expr $(/usr/bin/git rev-list --count HEAD) "+" 12063) echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV sed -i "s/DKSU_VERSION=16/DKSU_VERSION=${KSU_VERSION}/" kernel/Makefile else echo "Invalid KernelSU variant selected!" exit 1 fi - name: Apply SUSFS Patches for KernelSU Variants run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Applying SUSFS patches..." # Copy SUSFS patches cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./ cp ../susfs4ksu/kernel_patches/fs/* ./fs/ cp ../susfs4ksu/kernel_patches/include/linux/* ./include/linux/ if [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then echo "Applying SUSFS patches for Official KernelSU..." cd ./KernelSU cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./ patch -p1 --forward < 10_enable_susfs_for_ksu.patch elif [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then echo "Applying SUSFS patches for KernelSU-Next..." cd ./KernelSU-Next cp ../../kernel_patches/KernelSU-Next-Implement-SUSFS-v1.5.5-Universal.patch ./ patch -p1 --forward < KernelSU-Next-Implement-SUSFS-v1.5.5-Universal.patch || true elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then echo "Applying SUSFS patches for MKSU..." cd ./KernelSU cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./ patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true echo "Applying MKSU specific SUSFS patch..." cp ../../kernel_patches/mksu_susfs.patch ../KernelSU/ patch -p1 < mksu_susfs.patch else echo "Invalid KernelSU variant selected!" exit 1 fi # Change to common directory and apply common SUSFS patch cd ../ patch -p1 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true - name: Add SUSFS Configuration Settings run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Adding configuration settings to gki_defconfig..." declare -A ARCH_MAP=(["x86_64"]="x64" ["arm64"]="arm64") cp configs/wsa/config-wsa-${ARCH_MAP[${{ inputs.wsa_arch }}]} .config echo "startofsus" >> .config # Add SUSFS configuration settings echo "CONFIG_KSU=y" >> .config echo "CONFIG_KSU_SUSFS=y" >> .config echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> .config echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> .config echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> .config echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> .config echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> .config echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> .config echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> .config echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> .config echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> .config echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> .config echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> .config echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> .config echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> .config echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> .config echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> .config # Add additional tmpfs config setting echo "CONFIG_TMPFS_XATTR=y" >> .config echo "CONFIG_TMPFS_POSIX_ACL=y" >> .config echo "CONFIG_FANOTIFY=n" >> .config echo "endofsus" >> .config - name: Build the Kernel run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./scripts/setlocalversion # Run perl command to modify UTS_VERSION 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 sed -i 's/-dirty//' ./scripts/setlocalversion sed -i 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION="-Wild+"/' ./scripts/setlocalversion make olddefconfig declare -A FILE_NAME=(["x86_64"]="bzImage" ["arm64"]="Image") 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 }}]} declare -A ARCH_MAP_FILE=(["x86_64"]="x86" ["arm64"]="arm64") echo "file_path=WSA-Linux-Kernel-${{ inputs.wsa_arch }}/arch/${ARCH_MAP_FILE[${{ inputs.wsa_arch }}]}/boot/${FILE_NAME[${{ inputs.wsa_arch }}]}" >> $GITHUB_ENV - name: Upload Build Artifacts uses: actions/upload-artifact@v4 with: name: kernel-${{ env.CONFIG }} path: "${{ env.file_path }}"