Skip to content

Commit

Permalink
rootfs: Install Rust only when necessary
Browse files Browse the repository at this point in the history
For docker-based builds only install Rust when necessary.
Further, execute the detect Rust version check only when
intending to install Rust.
As of today, this is the case when we intend to build the
agent during rootfs build.

Signed-off-by: Manuel Huber <[email protected]>
  • Loading branch information
ms-mahuber committed Jul 11, 2024
1 parent a4b4ca2 commit 39ab779
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 0 additions & 6 deletions tools/osbuilder/rootfs-builder/rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,6 @@ build_rootfs_distro()
mkdir -p ${ROOTFS_DIR}
fi

# need to detect rustc's version too?
detect_rust_version ||
die "Could not detect the required rust version for AGENT_VERSION='${AGENT_VERSION:-main}'."

echo "Required rust version: $RUST_VERSION"

if [ "${SELINUX}" == "yes" ]; then
if [ "${AGENT_INIT}" == "yes" ]; then
die "Guest SELinux with the agent init is not supported yet"
Expand Down
13 changes: 11 additions & 2 deletions tools/osbuilder/scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,23 @@ generate_dockerfile()

[ -n "${http_proxy:-}" ] && readonly set_proxy="RUN sed -i '$ a proxy="${http_proxy:-}"' /etc/dnf/dnf.conf /etc/yum.conf; true"

# Rust agent
readonly install_rust="
# Only install Rust if agent needs to be built
local install_rust=""

if [ ! -z "${AGENT_SOURCE_BIN}" ] ; then
if [ "$RUST_VERSION" == "null" ]; then
detect_rust_version || \
die "Could not detect the required rust version for AGENT_VERSION='${AGENT_VERSION:-main}'."
fi
install_rust="
ENV http_proxy=${http_proxy:-}
ENV https_proxy=${http_proxy:-}
RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSLf | \
sh -s -- -y --default-toolchain ${RUST_VERSION} -t ${rustarch}-unknown-linux-${LIBC}
RUN . /root/.cargo/env; cargo install cargo-when
"
fi

pushd "${dir}"

sed \
Expand Down

0 comments on commit 39ab779

Please sign in to comment.