Skip to content

Commit

Permalink
build.sh: refactor & fix ccache
Browse files Browse the repository at this point in the history
#102 remove IS_LTS env in *.yml, but not change build.sh accordingly, which makes build.sh always selects to non-ccache branch.

Add option parser like that in setup.sh and modify *.yml, which should fix ccache.

Also remove old SMT detection code. `nproc` itself already respects SMT. Like with 8C,16T processor, `nproc` will return 16.

`nproc --all` basically is same as `nproc` but it will ignore cgroup limitation forced by containers like docker, and also on motherboards supporting hotplug cpus it will return max possible cpu slots instead of the number of installed count. So yeah, sometimes `nproc --all` returns a bigger number than `nproc`, but those "extra" cpus aren't actually available for use. So let's just use `nproc`.

But use 2*nproc might still make sense if compilation is actually IO-bounded. I tested nproc vs 2*nproc on my private repo's action. It seems like no noticable difference though. Maybe we should revisit the thread count decision someday later.

(cherry picked from commit f05d3d5c422738ad90237753b9bd60396ded6238)
  • Loading branch information
Locietta committed Dec 19, 2024
1 parent 00b42d9 commit 2c42685
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-lts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Build kernel
if: ${{ env.REBUILD_FLAG }}
run: |
cd linux && ../build.sh
cd linux && ../build.sh --branch LTS
mv arch/x86/boot/bzImage ../${{ matrix.image-name }}
cd .. && sha256sum ${{ matrix.image-name }} > ${{ matrix.image-name }}.sha256
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- name: Build kernel
if: ${{ env.REBUILD_FLAG }}
run: |
cd linux && ../build.sh
cd linux && ../build.sh --branch MAIN
mv arch/x86/boot/bzImage ../${{ matrix.image-name }}
cd .. && sha256sum ${{ matrix.image-name }} > ${{ matrix.image-name }}.sha256
Expand Down
66 changes: 59 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
#
if [ "$(cat /sys/devices/system/cpu/smt/active)" = "1" ]; then
export LOGICAL_CORES=$(($(nproc --all) * 2))
else
export LOGICAL_CORES=$(nproc --all)
#!/bin/bash

usage() {
echo "Usage: build.sh [options]"
echo "Options:"
echo " -b|--branch <LTS|MAIN> - Specify the Xanmod kernel branch to build. (Default: MAIN)"
echo " -j|--jobs <num> - Specify the number of jobs to use for parallel compilation. (Default: $(nproc))"
echo " -h - Show this help message."
}

# Parse options with getopt
temp=$(getopt -o 'b:j:h' --long 'branch:,jobs:,help' -n 'build.sh' -- "$@")
if [ $? -ne 0 ]; then
# unsupported options provided
# NOTE: error log not needed, will be reported by getopt
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
;;
'-j'|'--jobs')
LOGICAL_CORES="$2"
shift 2
continue
;;
'-h'|'--help')
usage
exit 0
;;
'--')
shift
break
;;
*)
# should not happen
echo "Unhandled option: $1"
exit 1
;;
esac
done
# Default values
BRANCH=${BRANCH:-MAIN}

LOGICAL_CORES=${LOGICAL_CORES:-$(nproc)}

#
# Compile
#
if [ "$IS_LTS" = "NO" ]; then
if [ "$BRANCH" = "MAIN" ]; then
echo -e "Using $LOGICAL_CORES jobs for this non-LTS build..."
make CC='ccache clang -Qunused-arguments -fcolor-diagnostics' LLVM=1 LLVM_IAS=1 -j$LOGICAL_CORES
else
elif [ "$BRANCH" = "LTS" ]; then
echo -e "Using $LOGICAL_CORES jobs for this LTS build..."
make LLVM=1 LLVM_IAS=1 -j$LOGICAL_CORES
fi
6 changes: 3 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ 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
if [ "$BRANCH" = "MAIN" ]; then
cp ../wsl2_defconfig.MAIN ./arch/x86/configs/wsl2_defconfig
elif [ "$BRANCH" = "LTS" ]; then
cp ../wsl2_defconfig.LTS ./arch/x86/configs/wsl2_defconfig
fi

make LLVM=1 LLVM_IAS=1 wsl2_defconfig
Expand Down

0 comments on commit 2c42685

Please sign in to comment.