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

use ARM_MCS_verified.cmake for MCS build #295

Merged
merged 5 commits into from
Jan 9, 2024
Merged
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
161 changes: 94 additions & 67 deletions standalone-kernel/compile_kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,111 @@
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"
;;
RISCV32)
gcc_cfg="RISCV32"
# the 64-bit toolchain can build for 32-bit also.
llvm_triple="riscv64-unknown-elf"
;;
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
IA32|X64)
# 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})"
# Use a dedicated config file if available, otherwise just use
# the default config and enable MCS.
try_config_file="configs/${INPUT_ARCH}_MCS_verified.cmake"
if [ -f "${try_config_file}" ]; then
config_file=${try_config_file}
else
extra_params="${extra_params} -DKernelIsMCS=TRUE"
fi
;;
*)
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"