rust/rustup-toolchain

54 lines
1.9 KiB
Plaintext
Raw Normal View History

2019-11-30 03:06:12 -06:00
#!/bin/bash
set -e
# Manages a rustup toolchain called "miri".
#
# All commands set "miri" as the override toolchain for the current directory,
# and make the `rust-version` file match that toolchain.
#
# USAGE:
#
2019-12-01 03:20:16 -06:00
# ./rustup-toolchain: Update "miri" toolchain to match `rust-version` (the known-good version for this commit).
2022-04-30 12:40:35 -05:00
#
2019-12-01 03:20:16 -06:00
# ./rustup-toolchain HEAD: Update "miri" toolchain and `rust-version` file to latest rustc HEAD.
2022-04-30 12:40:35 -05:00
#
2019-12-01 03:20:16 -06:00
# ./rustup-toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit.
2022-06-04 10:48:46 -05:00
#
# Any extra parameters are passed to `rustup-toolchain-install-master`.
2019-11-30 03:06:12 -06:00
# Make sure rustup-toolchain-install-master is installed.
if ! which rustup-toolchain-install-master >/dev/null; then
echo "Please install rustup-toolchain-install-master by running 'cargo install rustup-toolchain-install-master'"
exit 1
fi
2019-11-30 03:06:12 -06:00
# Determine new commit.
if [[ "$1" == "" ]]; then
NEW_COMMIT=$(cat rust-version)
elif [[ "$1" == "HEAD" ]]; then
NEW_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
else
NEW_COMMIT="$1"
fi
echo "$NEW_COMMIT" > rust-version
2022-06-06 10:44:27 -05:00
shift || true # don't fail if shifting fails
2019-11-30 03:06:12 -06:00
# Check if we already are at that commit.
2022-09-15 17:36:33 -05:00
CUR_COMMIT=$(rustc +miri --version -v 2>/dev/null | grep "^commit-hash: " | cut -d " " -f 2)
2019-11-30 03:06:12 -06:00
if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then
echo "miri toolchain is already at commit $CUR_COMMIT."
rustup override set miri
exit 0
fi
# Install and setup new toolchain.
rustup toolchain uninstall miri
2022-06-29 17:14:41 -05:00
rustup-toolchain-install-master -n miri -c cargo -c rust-src -c rustc-dev -c llvm-tools -c rustfmt -c clippy "$@" -- "$NEW_COMMIT"
2019-11-30 03:06:12 -06:00
rustup override set miri
# Cleanup.
cargo clean
# Call 'cargo metadata' on the sources in case that changes the lockfile
2022-05-17 11:59:27 -05:00
# (which fails under some setups when it is done from inside vscode).
cargo metadata --format-version 1 --manifest-path "$(rustc --print sysroot)/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" >/dev/null