From 55cdef2295a318d22d63f212085f350f2c2931d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Tue, 15 Feb 2022 13:16:44 +0100 Subject: [PATCH 1/3] tools: clh: Add the possibility to always build from sources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current code will always pull the release binaries in case the version requested by Kata Containers matches with a released version. This, however, has a limitation of preventing users / CIs to build cloud-hypervisor from source for a reason or another, such as passing a specific build flag to cloud-hypervisor. This is a pre-req to solving https://github.com/kata-containers/kata-containers/issues/3671. While here, a small changes were needed in order to improve readability and debugability of why we're building something from the sources rather than simply downloading and using a pre-built binary. Fixes: #3672 Signed-off-by: Fabiano FidĂȘncio --- .../cloud-hypervisor/build-static-clh.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh index f174daac0..e1ceb42f7 100755 --- a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh +++ b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh @@ -15,6 +15,7 @@ ARCH=$(uname -m) script_dir=$(dirname $(readlink -f "$0")) kata_version="${kata_version:-}" +force_build_from_source="${force_build_from_source:-false}" source "${script_dir}/../../scripts/lib.sh" @@ -55,7 +56,15 @@ build_clh_from_source() { popd } -if [ ${ARCH} == "aarch64" ] || ! pull_clh_released_binary; then - info "arch is aarch64 or failed to pull cloud-hypervisor released binary on x86_64, trying to build from source" - build_clh_from_source +if [ "${ARCH}" == "aarch64" ]; then + info "aarch64 binaries are not distributed as part of the Cloud Hypervisor releases, forcing to build from source" + force_build_from_source="true" +fi + +if [ "${force_build_from_source}" == "true" ]; then + info "Build cloud-hypervisor from source as it's been request via the force_build_from_source flag" + build_clh_from_source +else + pull_clh_released_binary || + (info "Failed to pull cloud-hypervisor released binary, trying to build from source" && build_clh_from_source) fi From e07545a23ca24104c2cdcdede6c951fcfd6e1e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Tue, 15 Feb 2022 13:59:24 +0100 Subject: [PATCH 2/3] tools: clh: Allow passing down a build flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's allow passing down a build flag to cargo, when building Cloud Hypervisor. By doing this we allow calling this script with: ``` extra_build_flags="--features tdx" ./build-static-clh.sh ``` Fixes: #3671 Signed-off-by: Fabiano FidĂȘncio --- .../cloud-hypervisor/build-static-clh.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh index e1ceb42f7..8569ac87c 100755 --- a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh +++ b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh @@ -16,6 +16,7 @@ ARCH=$(uname -m) script_dir=$(dirname $(readlink -f "$0")) kata_version="${kata_version:-}" force_build_from_source="${force_build_from_source:-false}" +extra_build_args="${extra_build_args:-}" source "${script_dir}/../../scripts/lib.sh" @@ -50,7 +51,12 @@ build_clh_from_source() { pushd "${repo_dir}" git fetch || true git checkout "${cloud_hypervisor_version}" - ./scripts/dev_cli.sh build --release --libc musl + if [ -n "${extra_build_args}" ]; then + info "Build cloud-hypervisor with extra args: ${extra_build_args}" + ./scripts/dev_cli.sh build --release --libc musl -- ${extra_build_args} + else + ./scripts/dev_cli.sh build --release --libc musl + fi rm -f cloud-hypervisor cp build/cargo_target/$(uname -m)-unknown-linux-musl/release/cloud-hypervisor . popd @@ -61,6 +67,11 @@ if [ "${ARCH}" == "aarch64" ]; then force_build_from_source="true" fi +if [ -n "${extra_build_args}" ]; then + info "As an extra build argument has been passed to the script, forcing to build from source" + force_build_from_source="true" +fi + if [ "${force_build_from_source}" == "true" ]; then info "Build cloud-hypervisor from source as it's been request via the force_build_from_source flag" build_clh_from_source From 948a2b099c6f079688df372cca6005f12c032839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Tue, 15 Feb 2022 15:06:51 +0100 Subject: [PATCH 3/3] tools: clh: Ensure the download binary is executable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're downloading the released cloud-hypervisor binary from GitHub, but we should also ensure we set the binary as executable. Signed-off-by: Fabiano FidĂȘncio --- .../packaging/static-build/cloud-hypervisor/build-static-clh.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh index 8569ac87c..61a0824eb 100755 --- a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh +++ b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh @@ -41,6 +41,7 @@ pull_clh_released_binary() { curl --fail -L ${cloud_hypervisor_binary} -o cloud-hypervisor-static || return 1 mkdir -p cloud-hypervisor mv -f cloud-hypervisor-static cloud-hypervisor/cloud-hypervisor + chmod +x cloud_hypervisor/cloud-hypervisor } build_clh_from_source() {