Fix Rust installation

There were a number of issues:

1. `rustc` wasn't actually installed since the `INSTALL_RUST_VERSION`
argument wasn't set.

2. `rustup` wasn't running properly since the `CARGO_HOME` and
`RUSTUP_HOME`weren't being exported and set by default. We now use the
technique described in https://github.com/rust-lang/rustup/issues/1085
to create a wrapper and link all the binaries in /opt/rust/bin and
link them to /usr/local/bin.

3. `rustc version` is not a valid command. `rustc --version` is valid.
This commit is contained in:
Stan Hu 2023-01-18 15:00:41 -08:00
parent a5ac3f8e7f
commit 9e04d5d21a
No known key found for this signature in database
GPG key ID: 8D3931AD39CC7A20
3 changed files with 19 additions and 6 deletions

View file

@ -17,12 +17,12 @@ RUN /scripts/install-essentials ${BUILD_OS}
ENV PATH $PATH:/usr/local/go/bin
ENV PATH /usr/local/cargo/bin:$PATH
ENV PATH /usr/local/bin:$PATH
# Rust
ARG INSTALL_RUST_VERSION
RUN if [ -n "$INSTALL_RUST_VERSION" ] ; then /scripts/install-rust "${INSTALL_RUST_VERSION}" && rustc version; fi
RUN if [ -n "$INSTALL_RUST_VERSION" ] ; then /scripts/install-rust "${INSTALL_RUST_VERSION}" && rustc --version; fi
# Ruby
ARG RUBY_VERSION

View file

@ -20,9 +20,9 @@ esac
RUST_DOWNLOAD_URL="https://static.rust-lang.org/rustup/dist/$RUST_TARGET/rustup-init"
RUSTUP_DEFAULT_TOOLCHAIN="$INSTALL_RUST_VERSION"
RUSTUP_HOME="/usr/local/rustup"
CARGO_HOME="/usr/local/cargo"
export RUSTUP_HOME="/opt/rust"
export CARGO_HOME="/opt/rust"
function build() {
curl --retry 3 --proto '=https' --tlsv1.2 -sSf "$RUST_DOWNLOAD_URL" > rustup-init
@ -37,6 +37,19 @@ function build() {
rm rustup-init && rm rustup-init.sha256
chmod -R a+w "$RUSTUP_HOME" "$CARGO_HOME"
# https://github.com/rust-lang/rustup/issues/1085
cat <<EOF > /usr/local/bin/rust-wrapper
#!/bin/sh
RUSTUP_HOME=/opt/rust exec /opt/rust/bin/\${0##*/} "\$@"
EOF
chmod +x /usr/local/bin/rust-wrapper
for bin in /opt/rust/bin/*
do
ln -sf /usr/local/bin/rust-wrapper /usr/local/bin/$(basename $bin)
done
}
build "$@"

View file

@ -64,13 +64,13 @@ function print_golang_args() {
function print_rust_args() {
case "$1" in
1.65.0)
RUST_VERSION="1.65.0"
INSTALL_RUST_VERSION="1.65.0"
;;
*) fail "Unknown rust version $1" ;;
esac
printf -- "--build-arg RUST_VERSION=%s " "$RUST_VERSION"
printf -- "--build-arg INSTALL_RUST_VERSION=%s " "$INSTALL_RUST_VERSION"
}
# If you add a new minor version here, be sure to check that the