Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kernel CI] Refactor config.sh & Fix for New Graysky Compiler Patch #102

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions .github/workflows/build-lts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
- cron: '0 0 1 * *'

env:
IS_LTS: YES
MIMALLOC_ALLOW_LARGE_OS_PAGES: 1

jobs:
Expand Down Expand Up @@ -50,15 +49,11 @@ jobs:
- name: Trust this directory
run: git config --global --add safe.directory '*' # v2.35.3 or later

- name: Prepare source code
- name: Setup kernel source
shell: bash
run: |
export CURL_UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0"
export VERSION_BRANCH=$(curl -s https://xanmod.org/ -A $CURL_UA | awk '/LTS/{getline; getline; print}' | grep -oP '[0-9]+\.[0-9]+')
git clone https://gitlab.com/xanmod/linux.git -b $VERSION_BRANCH --depth 1 linux
cd linux && ../config.sh
scripts/config -d GENERIC_CPU3 # avoid override warning for duplicate arch flags
scripts/config -e ${{ matrix.arch }}
./setup.sh --arch ${{ matrix.arch }} --branch LTS
cd linux

# Load version info into env
echo "CLANG_VERSION=$(clang --version | head -n1)" | tee -a $GITHUB_ENV
Expand Down Expand Up @@ -115,6 +110,7 @@ jobs:
- uses: actions/download-artifact@main
with:
path: release_images/
merge-multiple: true

- id: fetch_commit_sha
run: |
Expand All @@ -126,8 +122,13 @@ jobs:
echo "RELEASE_TAG=${{ needs.build.outputs.current_version }}.1" | tee -a $GITHUB_ENV
fi

- name: Remove misc files
run: |
rm -rf release_images/.config*
# We don't release .config files, they are in the artifact only for debugging

- name: Release
uses: softprops/action-gh-release@master
uses: softprops/action-gh-release@v2.1.0
if: ${{ needs.build.outputs.rebuild_flag }}
with:
name: ${{ env.RELEASE_TAG }}-lts
Expand All @@ -147,7 +148,7 @@ jobs:
**NOTE for Win11**: the minimum requirement of Win11 ensures generic-x86_64-v3 support, so feel free to use `bzImage-x64v3`.

files: |
release_images/*/*
release_images/*
token: ${{ secrets.GITHUB_TOKEN }}
# generate_release_notes: true
fail_on_unmatched_files: true
23 changes: 12 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
- cron: '0 6,14,22 * * *'

env:
IS_LTS: NO
MIMALLOC_ALLOW_LARGE_OS_PAGES: 1

jobs:
Expand All @@ -33,7 +32,6 @@ jobs:
image-name: bzImage-x64v3
- arch: MSKYLAKE
image-name: bzImage-skylake

steps:

- uses: actions/checkout@main
Expand All @@ -50,15 +48,11 @@ jobs:
- name: Trust this directory
run: git config --global --add safe.directory '*' # v2.35.3 or later

- name: Prepare source code
- name: Setup kernel source
shell: bash
run: |
export CURL_UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0"
export VERSION_BRANCH=$(curl -s https://xanmod.org/ -A $CURL_UA | awk '/MAIN/{getline; getline; print}' | grep -oP '[0-9]+\.[0-9]+')
git clone https://gitlab.com/xanmod/linux.git -b $VERSION_BRANCH --depth 1 linux
cd linux && ../config.sh
scripts/config -d GENERIC_CPU3 # avoid override warning for duplicate arch flags
scripts/config -e ${{ matrix.arch }}
./setup.sh --arch ${{ matrix.arch }} --branch MAIN
cd linux

# Load version info into env
echo "CLANG_VERSION=$(clang --version | head -n1)" | tee -a $GITHUB_ENV
Expand Down Expand Up @@ -110,6 +104,7 @@ jobs:
path: |
${{ matrix.image-name }}
${{ matrix.image-name }}.sha256
.config-${{ matrix.arch }}

- id: out
run: |
Expand All @@ -129,6 +124,7 @@ jobs:
- uses: actions/download-artifact@main
with:
path: release_images/
merge-multiple: true

- id: fetch_commit_sha
run: |
Expand All @@ -140,8 +136,13 @@ jobs:
echo "RELEASE_TAG=${{ needs.build.outputs.current_version }}.1" | tee -a $GITHUB_ENV
fi

- name: Remove misc files
run: |
rm -rf release_images/.config*
# We don't release .config files, they are in the artifact only for debugging

- name: Release
uses: softprops/action-gh-release@master
uses: softprops/action-gh-release@v2.1.0
if: ${{ needs.build.outputs.rebuild_flag }}
with:
name: ${{ env.RELEASE_TAG }}
Expand All @@ -161,7 +162,7 @@ jobs:
**NOTE for Win11**: the minimum requirement of Win11 ensures generic-x86_64-v3 support, so feel free to use `bzImage-x64v3`.

files: |
release_images/*/*
release_images/*
token: ${{ secrets.GITHUB_TOKEN }}
# generate_release_notes: true
fail_on_unmatched_files: true
44 changes: 0 additions & 44 deletions config.sh

This file was deleted.

138 changes: 138 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/bin/bash

shopt -s nullglob

# Function to display usage
usage() {
echo "Usage: $0 [options]"
echo "Options:"
echo " -a|--arch <architecture> - Specify the architecture to build. (Default: GENERIC_CPU3)"
echo " --branch <LTS|MAIN> - Specify the Xanmod kernel branch to build. (Default: MAIN)"
echo " --no-download - Don't download kernel source, assume it's already in ./linux"
echo " -h|--help - Show this help message."
}

# Parse options with getopt
temp=$(getopt -o 'b:a:h' --long 'branch:,arch:,help,no-download' -n 'setup.sh' -- "$@")
if [ $? -ne 0 ]; then
# unsupported options provided
usage
exit 1
fi
eval set -- "$temp"
unset temp
while true; do
case "$1" in
'-b'|'--branch')
BRANCH="$2"
shift 2
# check if branch is LTS or MAIN
if [ "$BRANCH" != "LTS" ] && [ "$BRANCH" != "MAIN" ]; then
echo "Invalid branch: $BRANCH"
exit 2
fi
continue
;;
'-a'|'--arch')
ARCH="$2"
shift 2
continue
;;
'-h'|'--help')
usage
exit 0
;;
'--no-download')
SKIP_DOWNLOAD="YES"
shift
continue
;;
'--')
shift
break
;;
*)
# should not happen
echo "Unhandled option: $1"
usage
exit 1
;;
esac
done
# Default values
ARCH=${ARCH:-GENERIC_CPU3}
BRANCH=${BRANCH:-MAIN}
SKIP_DOWNLOAD=${SKIP_DOWNLOAD:-NO}

if [ "$SKIP_DOWNLOAD" = "NO" ]; then
CURL_UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0"
VERSION_BRANCH=$(curl -s https://xanmod.org/ -A $CURL_UA | awk "/$BRANCH/{getline; getline; print}" | grep -oP '[0-9]+\.[0-9]+')
XANMOD_REPO="https://gitlab.com/xanmod/linux.git"
echo "Fetching Xanmod $BRANCH($VERSION_BRANCH) source..."
git clone $XANMOD_REPO -b $VERSION_BRANCH --depth 1 linux
fi

if [ ! -d linux ]; then
echo "Xanmod $BRANCH source not found. Probably git clone failed."
exit 1
fi

cd linux
PATCH_DIR=${PATCH_DIR:-"../patches"}

# Determine the patch directory
if [[ $BRANCH == "LTS" ]]; then
SPESIFIC_PATCH_DIR="$PATCH_DIR/LTS"
else
SPESIFIC_PATCH_DIR="$PATCH_DIR/MAIN"
fi

function loop_apply_patch {
for patch_file in "$1/"*.patch; do
git apply "$patch_file"

if [ $? != 0 ]; then
echo -e "Failed to apply $patch_file"
echo -e "Halting build!"
exit 1
fi
done
}

# Apply common patches
loop_apply_patch $PATCH_DIR
# Apply LTS/MAIN specific patches
loop_apply_patch $SPESIFIC_PATCH_DIR

if [ "$BRANCH" = "LTS" ]; then
cp ../wsl2_defconfig.LTS ./arch/x86/configs/wsl2_defconfig
else
cp ../wsl2_defconfig.MAIN ./arch/x86/configs/wsl2_defconfig
fi

make LLVM=1 LLVM_IAS=1 wsl2_defconfig
make LLVM=1 LLVM_IAS=1 oldconfig

if [ "$BRANCH" = "LTS" ]; then
# avoid override warning for duplicate arch flags
scripts/config -d GENERIC_CPU3
scripts/config -e $ARCH
else
# avoid override warning for duplicate arch flags
scripts/config -d CONFIG_GENERIC_CPU
scripts/config -d CONFIG_X86_64_VERSION
# Add graysky's compiler config
case "$ARCH" in
GENERIC_CPU3)
scripts/config -e CONFIG_GENERIC_CPU
scripts/config --set-val CONFIG_X86_64_VERSION 3
;;
GENERIC_CPU2)
scripts/config -e CONFIG_GENERIC_CPU
scripts/config --set-val CONFIG_X86_64_VERSION 2
;;
*)
scripts/config -e $ARCH
;;
esac
fi
File renamed without changes.
Loading
Loading