#!/usr/bin/env bash # CI: install the given Rust toolchain (with clippy and rustfmt) through # rustup and make it the default. Installs rustup and a C compiler first when # the job image has none (ring compiles C). # bash .gitea/scripts/rust-toolchain.sh 1.98.1 set -euo pipefail tc=${1:?toolchain, e.g. 1.98.1} need=() command -v cc >/dev/null || need+=(gcc libc6-dev) command -v curl >/dev/null || need+=(curl ca-certificates) if [ ${#need[@]} -gt 0 ]; then SUDO=$(command -v sudo || true) $SUDO apt-get update -qq $SUDO apt-get install -y -qq "${need[@]}" fi if ! command -v rustup >/dev/null && [ ! -x "$HOME/.cargo/bin/rustup" ]; then curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain none fi export PATH="$HOME/.cargo/bin:$PATH" [ -n "${GITHUB_PATH:-}" ] && echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" rustup toolchain install "$tc" --profile minimal -c clippy -c rustfmt rustup default "$tc" rustc --version cargo --version