Skip to content

Commit

Permalink
make script more generic
Browse files Browse the repository at this point in the history
- remove redundancy
- check if config file exists
- remove unnecessary CMake parameters
- use separate build folder for non-MCS and MCS
- improve comments

Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
axel-h authored and lsf37 committed Jan 9, 2024
1 parent 6775e43 commit 8428265
Showing 1 changed file with 81 additions and 66 deletions.
147 changes: 81 additions & 66 deletions standalone-kernel/compile_kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,99 @@
echo "Arch: $INPUT_ARCH"
echo "Comp: $INPUT_COMPILER"

set -e
set -eu

extra_config=""

case $INPUT_ARCH in
ARM*)
case $INPUT_COMPILER in
gcc)
extra_config="${extra_config} -DAARCH32=TRUE"
;;
llvm)
extra_config="${extra_config} -DTRIPLE=arm-linux-gnueabi"
;;
*)
echo "Unknown input compiler"
exit 1
esac
gcc_cfg=""
llvm_triple=""
case "${INPUT_ARCH}" in
ARM|ARM_HYP)
gcc_cfg="AARCH32"
llvm_triple="arm-linux-gnueabi"
;;
AARCH64)
case $INPUT_COMPILER in
gcc)
extra_config="${extra_config} -DAARCH64=TRUE"
;;
llvm)
extra_config="${extra_config} -DTRIPLE=aarch64-linux-gnu"
;;
*)
echo "Unknown input compiler"
exit 1
esac
gcc_cfg="AARCH64"
llvm_triple="aarch64-linux-gnu"
;;
RISCV64)
case $INPUT_COMPILER in
gcc)
extra_config="${extra_config} -DRISCV64=TRUE"
;;
llvm)
extra_config="${extra_config} -DTRIPLE=riscv64-unknown-elf"
;;
*)
echo "Unknown input compiler"
exit 1
esac
gcc_cfg="RISCV64"
llvm_triple="riscv64-unknown-elf"
;;
X64)
# no config needed
# just use the standard host compiler
;;
*)
echo "Unknown ARCH"
echo "Unknown ARCH '${INPUT_ARCH}'"
exit 1
;;
esac

echo "::group::Run CMake"
mkdir build
cd build
set -x
cmake -DCMAKE_TOOLCHAIN_FILE="$INPUT_COMPILER".cmake -G Ninja -C ../configs/"$INPUT_ARCH"_verified.cmake $extra_config ../
set +x
echo "::endgroup::"
toolchain_flags=""
case "${INPUT_COMPILER}" in
gcc)
if [ ! -z "${gcc_cfg}" ]; then
toolchain_flags="-D${gcc_cfg}=TRUE"
fi
;;
llvm)
if [ ! -z "${llvm_triple}" ]; then
toolchain_flags="-DTRIPLE=${llvm_triple}"
fi
;;
*)
echo "Unknown COMPILER '${INPUT_COMPILER}'"
exit 1
;;
esac
toolchain_flags="-DCMAKE_TOOLCHAIN_FILE=${INPUT_COMPILER}.cmake ${toolchain_flags}"

do_compile_kernel()
{
variant=${1:-}

build_folder="build"
config_file="configs/${INPUT_ARCH}_verified.cmake"
variant_info=""
extra_params=""

if [ ! -z "${variant}" ]; then
case "${variant}" in
MCS)
build_folder="${build_folder}-${variant}"
variant_info=" (${variant})"
extra_params="${extra_params} -DKernelIsMCS=TRUE"
;;
*)
echo "Unknown variant '${variant}'"
exit 1
;;
esac
fi

# Unfortunately, CMake does not halt with a nice and clear error if the
# config file does not exist. Instead, it logs an error that it could not
# process the file and continues as if the file was empty. This causes some
# rather odd errors then, so it's better to fail here with a clear message.
if [ ! -f "${config_file}" ]; then
echo "missing config file '${config_file}'"
exit 1
fi

echo "::group::Run Ninja"
set -x
ninja kernel.elf
set +x
echo "::endgroup::"
echo "::group::Run CMake${variant_info}"
( # run in sub shell
set -x
cmake -G Ninja -B ${build_folder} -C ${config_file} ${toolchain_flags} ${extra_params}
)
echo "::endgroup::"

echo "::group::Run CMake (MCS)"
cd ..
rm -rf build
mkdir build
cd build
set -x
cmake -DCMAKE_TOOLCHAIN_FILE="$INPUT_COMPILER".cmake -G Ninja -C ../configs/"$INPUT_ARCH"_verified.cmake $extra_config -DKernelIsMCS=TRUE ../
set +x
echo "::endgroup::"
echo "::group::Run Ninja${variant_info}"
( # run in sub shell
set -x
ninja -C ${build_folder} kernel.elf
)
echo "::endgroup::"
}

echo "::group::Run Ninja (MCS)"
set -x
ninja kernel.elf
set +x
echo "::endgroup::"
# build standard kernel
do_compile_kernel
# build MCS kernel
do_compile_kernel "MCS"

0 comments on commit 8428265

Please sign in to comment.