#!/usr/bin/env bash set -euo pipefail # Pin the installer independently of rust-toolchain.toml, which pins rustc/cargo. readonly RUSTUP_VERSION="1.29.0" readonly RUSTUP_TARGET="x86_64-unknown-linux-gnu" readonly RUSTUP_INIT_SHA256="4acc9acc76d5079515b46346a485974457b5a79893cfb01112423c89aeb5aa10" readonly RUSTUP_INIT_URL="https://static.rust-lang.org/rustup/archive/${RUSTUP_VERSION}/${RUSTUP_TARGET}/rustup-init" # Give each Actions job an isolated installation so a host's rustup cannot # silently override the version pinned here. if [[ -n "${RUNNER_TEMP:-}" && -n "${GITHUB_RUN_ID:-}" ]]; then rustup_home="${RUNNER_TEMP}/strata-rustup-${GITHUB_RUN_ID}-${GITHUB_JOB:-job}" export CARGO_HOME="${rustup_home}/cargo" export RUSTUP_HOME="${rustup_home}/rustup" mkdir -p "$CARGO_HOME" if [[ -n "${GITHUB_ENV:-}" ]]; then printf 'CARGO_HOME=%s\nRUSTUP_HOME=%s\n' "$CARGO_HOME" "$RUSTUP_HOME" >> "$GITHUB_ENV" fi fi tmp_dir="$(mktemp -d)" trap 'rm -rf -- "$tmp_dir"' EXIT python3 - "$RUSTUP_INIT_URL" "$tmp_dir/rustup-init" <<'PY' import shutil import sys import urllib.request request = urllib.request.Request( sys.argv[1], headers={"User-Agent": "strata-next-pinned-rustup-bootstrap/1"} ) with urllib.request.urlopen(request, timeout=120) as response: with open(sys.argv[2], "wb") as output: shutil.copyfileobj(response, output) PY printf '%s %s\n' "$RUSTUP_INIT_SHA256" "$tmp_dir/rustup-init" | sha256sum --check --status || { echo "rustup-init ${RUSTUP_VERSION} checksum mismatch" >&2 exit 1 } chmod 0755 "$tmp_dir/rustup-init" "$tmp_dir/rustup-init" -y --no-modify-path \ --default-host "$RUSTUP_TARGET" --default-toolchain none --profile minimal export PATH="${CARGO_HOME:-$HOME/.cargo}/bin:$PATH" if [[ -n "${GITHUB_PATH:-}" ]]; then printf '%s\n' "${CARGO_HOME:-$HOME/.cargo}/bin" >> "$GITHUB_PATH" fi rustup set auto-self-update disable actual_version="$(rustup --version | awk 'NR == 1 { print $2 }')" if [[ "$actual_version" != "$RUSTUP_VERSION" ]]; then echo "expected rustup ${RUSTUP_VERSION}, got ${actual_version:-unknown}" >&2 exit 1 fi if (( $# > 0 )); then "$@" fi