Skip to content

Commit

Permalink
static-build: enable cross build for shim-v2
Browse files Browse the repository at this point in the history
shim-v2 has go and rust code. For rust code, we use messense/rust-musl-cross
to build for speed up as it doesn't depends on qemu emulation. Build go
code based on docker buildx as it doesn't support cross build now.

Fixes: kata-containers#6557
Signed-off-by: Jianyong Wu <[email protected]>
  • Loading branch information
jongwu authored and fidencio committed Aug 1, 2023
1 parent 7923de8 commit 11631c6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tools/packaging/static-build/shim-v2/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,51 @@ VMM_CONFIGS="qemu fc"

GO_VERSION=${GO_VERSION}
RUST_VERSION=${RUST_VERSION}
CC=""

DESTDIR=${DESTDIR:-${PWD}}
PREFIX=${PREFIX:-/opt/kata}
container_image="${SHIM_V2_CONTAINER_BUILDER:-$(get_shim_v2_image_name)}"

EXTRA_OPTS="${EXTRA_OPTS:-""}"

[ "${CROSS_BUILD}" == "true" ] && container_image_bk="${container_image}" && container_image="${container_image}-cross-build"
sudo docker pull ${container_image} || \
(sudo docker build \
(sudo docker ${BUILDX} build ${PLATFORM} \
--build-arg GO_VERSION="${GO_VERSION}" \
--build-arg RUST_VERSION="${RUST_VERSION}" \
-t "${container_image}" \
"${script_dir}" && \
push_to_registry "${container_image}")

arch=$(uname -m)
arch=${ARCH:-$(uname -m)}
GCC_ARCH=${arch}
if [ ${arch} = "ppc64le" ]; then
GCC_ARCH="powerpc64le"
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

sudo 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" \
"${container_image}" \
bash -c "git config --global --add safe.directory ${repo_root_dir} && make PREFIX=${PREFIX} QEMUCMD=qemu-system-${arch}"

sudo 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" \
"${container_image}" \
bash -c "git config --global --add safe.directory ${repo_root_dir} && make PREFIX="${PREFIX}" DESTDIR="${DESTDIR}" install"


[ "${CROSS_BUILD}" == "true" ] && container_image="${container_image_bk}-cross-build"

sudo docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${repo_root_dir}/src/runtime" \
"${container_image}" \
Expand Down

0 comments on commit 11631c6

Please sign in to comment.