mirror of
https://ops.gitlab.net/gitlab-org/gitlab-build-images.git
synced 2025-12-08 17:42:56 +01:00
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.
55 lines
1.5 KiB
Bash
Executable file
55 lines
1.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -xeou pipefail
|
|
|
|
INSTALL_RUST_VERSION=${1}
|
|
|
|
case "$TARGETARCH" in
|
|
"arm64")
|
|
RUST_TARGET="aarch64-unknown-linux-gnu"
|
|
;;
|
|
"amd64")
|
|
RUST_TARGET="x86_64-unknown-linux-gnu"
|
|
;;
|
|
*)
|
|
echo "target architecture not supported"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
RUST_DOWNLOAD_URL="https://static.rust-lang.org/rustup/dist/$RUST_TARGET/rustup-init"
|
|
|
|
RUSTUP_DEFAULT_TOOLCHAIN="$INSTALL_RUST_VERSION"
|
|
|
|
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
|
|
curl --retry 3 --proto '=https' --tlsv1.2 -sSf "$RUST_DOWNLOAD_URL.sha256" > rustup-init.sha256
|
|
# Remove "target/$RUST_TARGET/release/" string from rustup-init.sha256
|
|
sed -i "s:\*target/$RUST_TARGET/release/::" rustup-init.sha256
|
|
sha256sum -c rustup-init.sha256
|
|
chmod +x rustup-init
|
|
|
|
# Need rustfmt for bindgen doc parsing
|
|
./rustup-init --no-modify-path --default-toolchain "$RUSTUP_DEFAULT_TOOLCHAIN" --profile minimal --component rustfmt -y
|
|
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 "$@"
|