kata-containers/tools/packaging/static-build/virtiofsd/build-static-virtiofsd.sh
stevenhorsman 1cf1a332a5 packaging: virtiofsd: Allow building a specific commit
#10714 added support for building a specific commit,
but due to the clone only having `--depth=1`, we can only
reset to a commit if it's the latest on the `main` branch,
otherwise we will get:
```
+ git clone --depth 1 --branch main https://gitlab.com/virtio-fs/virtiofsd virtiofsd
Cloning into 'virtiofsd'...
warning: redirecting to https://gitlab.com/virtio-fs/virtiofsd.git/
+ pushd virtiofsd
+ git reset --hard cecc61bca981ab42aae6ec490dfd59965e79025e
...
fatal: Could not parse object 'cecc61bca981ab42aae6ec490dfd59965e79025e'.
```

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
2025-01-31 11:24:23 +00:00

77 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Copyright (c) 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o nounset
set -o pipefail
ARCH=${ARCH:-$(uname -m)}
ARCH_LIBC=""
LIBC=""
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${script_dir}/../../scripts/lib.sh"
virtiofsd_repo="${virtiofsd_repo:-}"
virtiofsd_version="${virtiofsd_version:-}"
virtiofsd_zip="${virtiofsd_zip:-}"
[ -n "$virtiofsd_repo" ] || die "failed to get virtiofsd repo"
[ -n "$virtiofsd_version" ] || die "failed to get virtiofsd version"
[ -d "virtiofsd" ] && rm -r virtiofsd
pull_virtiofsd_released_binary() {
if [ -z "${virtiofsd_zip}" ]; then
info "failed to get virtiofsd binary URL"
return 1
fi
if [ "${ARCH}" != "x86_64" ]; then
info "Only x86_64 binaries are distributed as part of the virtiofsd releases" && return 1
fi
info "Download virtiofsd version: ${virtiofsd_version}"
mkdir -p virtiofsd
pushd virtiofsd
curl --fail -L ${virtiofsd_zip} -o virtiofsd.zip || return 1
unzip virtiofsd.zip
mv -f target/x86_64-unknown-linux-musl/release/virtiofsd virtiofsd
chmod +x virtiofsd
rm -rf target
rm virtiofsd.zip
popd
}
build_virtiofsd_from_source() {
echo "build virtiofsd from source"
. /etc/profile.d/rust.sh
git clone --branch main ${virtiofsd_repo} virtiofsd
pushd virtiofsd
git reset --hard ${virtiofsd_version}
export RUSTFLAGS='-C target-feature=+crt-static'${EXTRA_RUST_FLAGS}
export LIBSECCOMP_LINK_TYPE=static
export LIBSECCOMP_LIB_PATH=/usr/lib/${ARCH_LIBC}
export LIBCAPNG_LINK_TYPE=static
export LIBCAPNG_LIB_PATH=/usr/lib/${ARCH_LIBC}
cargo build --release --target ${RUST_ARCH}-unknown-linux-${LIBC}
binary=$(find ./ -name virtiofsd)
mv -f ${binary} .
chmod +x virtiofsd
popd
}
pull_virtiofsd_released_binary || build_virtiofsd_from_source