build: Allow users to build the go, rust, or both runtimes

Let's add a RUNTIME_CHOICE env var that can be passed to be build
scripts, which allows the user to select whether they bulld the go
runtime, the rust runtime, or both.

Signed-off-by: Fabiano Fidêncio <fidencio@northflank.com>
This commit is contained in:
Fabiano Fidêncio 2025-04-15 11:40:31 +02:00
parent 8b49564c01
commit 7e9e9263d1
3 changed files with 52 additions and 29 deletions

View File

@ -108,6 +108,7 @@ KBUILD_SIGN_PIN=${KBUILD_SIGN_PIN:-}
GUEST_HOOKS_TARBALL_NAME="${GUEST_HOOKS_TARBALL_NAME:-}"
EXTRA_PKGS="${EXTRA_PKGS:-}"
AGENT_POLICY="${AGENT_POLICY:-yes}"
RUNTIME_CHOICE="${RUNTIME_CHOICE:-both}"
docker run \
-v $HOME/.docker:/root/.docker \
@ -143,6 +144,7 @@ docker run \
--env GUEST_HOOKS_TARBALL_NAME="${GUEST_HOOKS_TARBALL_NAME}" \
--env EXTRA_PKGS="${EXTRA_PKGS}" \
--env AGENT_POLICY="${AGENT_POLICY}" \
--env RUNTIME_CHOICE="${RUNTIME_CHOICE}" \
--env AA_KBC="${AA_KBC:-}" \
--env HKD_PATH="$(realpath "${HKD_PATH:-}" 2> /dev/null || true)" \
--env SE_KERNEL_PARAMS="${SE_KERNEL_PARAMS:-}" \

View File

@ -57,6 +57,7 @@ PUSH_TO_REGISTRY="${PUSH_TO_REGISTRY:-}"
KERNEL_HEADERS_PKG_TYPE="${KERNEL_HEADERS_PKG_TYPE:-deb}"
RELEASE="${RELEASE:-"no"}"
KBUILD_SIGN_PIN="${KBUILD_SIGN_PIN:-}"
RUNTIME_CHOICE="${RUNTIME_CHOICE:-both}"
workdir="${WORKDIR:-$PWD}"
@ -897,6 +898,7 @@ install_shimv2() {
export GO_VERSION
export RUST_VERSION
export MEASURED_ROOTFS
export RUNTIME_CHOICE
DESTDIR="${destdir}" PREFIX="${prefix}" "${shimv2_builder}"
}

View File

@ -18,12 +18,23 @@ GO_VERSION=${GO_VERSION}
RUST_VERSION=${RUST_VERSION}
CC=""
RUNTIME_CHOICE="${RUNTIME_CHOICE:-both}"
DESTDIR=${DESTDIR:-${PWD}}
PREFIX=${PREFIX:-/opt/kata}
container_image="${SHIM_V2_CONTAINER_BUILDER:-$(get_shim_v2_image_name)}"
EXTRA_OPTS="${EXTRA_OPTS:-""}"
case "${RUNTIME_CHOICE}" in
"go"|"rust"|"both")
echo "Building ${RUNTIME_CHOICE} runtime(s)"
;;
*)
echo "Invalid option for RUNTIME_CHOICE: ${RUNTIME_CHOICE}"
exit 1
;;
esac
[ "${CROSS_BUILD}" == "true" ] && container_image_bk="${container_image}" && container_image="${container_image}-cross-build"
if [ "${MEASURED_ROOTFS}" == "yes" ]; then
info "Enable rootfs measurement config"
@ -53,40 +64,48 @@ if [ ${arch} = "ppc64le" ]; then
arch="ppc64"
fi
#Build rust project using cross build musl image to speed up
[[ "${CROSS_BUILD}" == "true" && ${ARCH} != "s390x" ]] && container_image="messense/rust-musl-cross:${GCC_ARCH}-musl" && CC=${GCC_ARCH}-unknown-linux-musl-gcc
case "${RUNTIME_CHOICE}" in
"rust"|"both")
#Build rust project using cross build musl image to speed up
[[ "${CROSS_BUILD}" == "true" && ${ARCH} != "s390x" ]] && container_image="messense/rust-musl-cross:${GCC_ARCH}-musl" && CC=${GCC_ARCH}-unknown-linux-musl-gcc
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
--env CROSS_BUILD=${CROSS_BUILD} \
--env ARCH=${ARCH} \
--env CC="${CC}" \
-w "${repo_root_dir}/src/runtime-rs" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make clean-generated-files && make PREFIX=${PREFIX} QEMUCMD=qemu-system-${arch}"
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
--env CROSS_BUILD=${CROSS_BUILD} \
--env ARCH=${ARCH} \
--env CC="${CC}" \
-w "${repo_root_dir}/src/runtime-rs" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make clean-generated-files && make PREFIX=${PREFIX} QEMUCMD=qemu-system-${arch}"
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
--env CROSS_BUILD=${CROSS_BUILD} \
--env ARCH=${ARCH} \
--env CC="${CC}" \
-w "${repo_root_dir}/src/runtime-rs" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make PREFIX="${PREFIX}" DESTDIR="${DESTDIR}" install"
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
--env CROSS_BUILD=${CROSS_BUILD} \
--env ARCH=${ARCH} \
--env CC="${CC}" \
-w "${repo_root_dir}/src/runtime-rs" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make PREFIX="${PREFIX}" DESTDIR="${DESTDIR}" install"
;;
esac
[ "${CROSS_BUILD}" == "true" ] && container_image="${container_image_bk}-cross-build"
case "${RUNTIME_CHOICE}" in
"go"|"both")
[ "${CROSS_BUILD}" == "true" ] && container_image="${container_image_bk}-cross-build"
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${repo_root_dir}/src/runtime" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make clean-generated-files && make PREFIX=${PREFIX} QEMUCMD=qemu-system-${arch} ${EXTRA_OPTS}"
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${repo_root_dir}/src/runtime" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make clean-generated-files && make PREFIX=${PREFIX} QEMUCMD=qemu-system-${arch} ${EXTRA_OPTS}"
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${repo_root_dir}/src/runtime" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make PREFIX="${PREFIX}" DESTDIR="${DESTDIR}" ${EXTRA_OPTS} install"
docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${repo_root_dir}/src/runtime" \
--user "$(id -u)":"$(id -g)" \
"${container_image}" \
bash -c "make PREFIX="${PREFIX}" DESTDIR="${DESTDIR}" ${EXTRA_OPTS} install"
;;
esac
for vmm in ${VMM_CONFIGS}; do
config_file="${DESTDIR}/${PREFIX}/share/defaults/kata-containers/configuration-${vmm}.toml"