Skip to content

Commit cde718f

Browse files
committed
Auto merge of #1087 - RalfJung:toolchain, r=oli-obk
add toolchain mgmt script I've been using a variant of this script for some time now, and figured others might find it useful as well.
2 parents 41df502 + 9501d04 commit cde718f

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

CONTRIBUTING.md

+19-27
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ on the [Rust Zulip].
1212

1313
[Rust Zulip]: https://rust-lang.zulipchat.com
1414

15+
## Building Miri with a pre-built rustc
16+
17+
Miri heavily relies on internal rustc interfaces to execute MIR. Still, some
18+
things (like adding support for a new intrinsic or a shim for an external
19+
function being called) can be done by working just on the Miri side.
20+
21+
The `rust-version` file contains the commit hash of rustc that Miri is currently
22+
tested against. Other versions will likely not work. After installing
23+
[`rustup-toolchain-install-master`], you can run the following command to
24+
install that exact version of rustc as a toolchain:
25+
```
26+
./rustup-toolchain
27+
```
28+
29+
[`rustup-toolchain-install-master`]: https://github.com/kennytm/rustup-toolchain-install-master
30+
1531
### Fixing Miri when rustc changes
1632

1733
Miri is heavily tied to rustc internals, so it is very common that rustc changes
@@ -20,36 +36,12 @@ Usually, Miri will require changes similar to the other consumers of the changed
2036
rustc API, so reading the rustc PR diff is a good way to get an idea for what is
2137
needed.
2238

23-
When submitting a PR against Miri after fixing it for rustc changes, make sure
24-
you update the `rust-version` file. That file always contains the exact rustc
25-
git commit with which Miri works, and it is the version that our CI tests Miri
26-
against.
27-
28-
## Building Miri with a nightly rustc
29-
30-
Miri heavily relies on internal rustc interfaces to execute MIR. Still, some
31-
things (like adding support for a new intrinsic or a shim for an external
32-
function being called) can be done by working just on the Miri side.
33-
34-
To prepare, make sure you are using a nightly Rust compiler. You also need to
35-
have the `rust-src` and `rustc-dev` components installed, which you can add via
36-
`rustup component add rust-src rustc-dev`. Then you should be able to just
37-
`cargo build` Miri.
38-
39-
In case this fails, your nightly might be incompatible with Miri master. The
40-
`rust-version` file contains the commit hash of rustc that Miri is currently
41-
tested against; you can use that to find a nightly that works or you might have
42-
to wait for the next nightly to get released. You can also use
43-
[`rustup-toolchain-install-master`](https://github.com/kennytm/rustup-toolchain-install-master)
44-
to install that exact version of rustc as a toolchain:
39+
To update the `rustc-version` file and install the latest rustc, you can run:
4540
```
46-
rustup-toolchain-install-master $(cat rust-version) -c rust-src -c rustc-dev
41+
./rustup-toolchain HEAD
4742
```
4843

49-
Another common problem is outdated dependencies: Miri does not come with a
50-
lockfile (it cannot, due to how it gets embedded into the rustc build). So you
51-
have to run `cargo update` every now and then yourself to make sure you are
52-
using the latest versions of everything (which is what gets tested on CI).
44+
Now try `./miri test`, and submit a PR once that works again.
5345

5446
## Testing the Miri driver
5547
[testing-miri]: #testing-the-miri-driver

rustup-toolchain

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e
3+
# Manages a rustup toolchain called "miri".
4+
#
5+
# All commands set "miri" as the override toolchain for the current directory,
6+
# and make the `rust-version` file match that toolchain.
7+
#
8+
# USAGE:
9+
#
10+
# ./rustup-toolchain: Update "miri" toolchain to match `rust-version` (the known-good version for this commit).
11+
#
12+
# ./rustup-toolchain HEAD: Update "miri" toolchain and `rust-version` file to latest rustc HEAD.
13+
#
14+
# ./rustup-toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit.
15+
16+
# Make sure rustup-toolchain-install-master is installed.
17+
if ! which rustup-toolchain-install-master >/dev/null; then
18+
echo "Please install rustup-toolchain-install-master by running 'cargo install rustup-toolchain-install-master'"
19+
exit 1
20+
fi
21+
22+
# Determine new commit.
23+
if [[ "$1" == "" ]]; then
24+
NEW_COMMIT=$(cat rust-version)
25+
elif [[ "$1" == "HEAD" ]]; then
26+
NEW_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
27+
else
28+
NEW_COMMIT="$1"
29+
fi
30+
echo "$NEW_COMMIT" > rust-version
31+
32+
# Check if we already are at that commit.
33+
CUR_COMMIT=$(rustc +miri --version -v 2>/dev/null | egrep "^commit-hash: " | cut -d " " -f 2)
34+
if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then
35+
echo "miri toolchain is already at commit $CUR_COMMIT."
36+
rustup override set miri
37+
exit 0
38+
fi
39+
40+
# Install and setup new toolchain.
41+
rustup toolchain uninstall miri
42+
rustup-toolchain-install-master -n miri -c rust-src -c rustc-dev -- "$NEW_COMMIT"
43+
rustup override set miri
44+
45+
# Cleanup.
46+
cargo clean

0 commit comments

Comments
 (0)