Skip to content

Commit c9b3b68

Browse files
committed
add toolchain mgmt script
1 parent e1b639a commit c9b3b68

File tree

2 files changed

+59
-27
lines changed

2 files changed

+59
-27
lines changed

CONTRIBUTING.md

Lines changed: 19 additions & 27 deletions
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+
./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+
./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

toolchain

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
# ./toolchain: Update "miri" toolchain to match `rust-version` (the known-good version for this commit).
11+
#
12+
# ./toolchain HEAD: Update "miri" toolchain and `rust-version` file to latest rustc HEAD.
13+
#
14+
# ./toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit.
15+
16+
# Determine new commit.
17+
if [[ "$1" == "" ]]; then
18+
NEW_COMMIT=$(cat rust-version)
19+
elif [[ "$1" == "HEAD" ]]; then
20+
NEW_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
21+
else
22+
NEW_COMMIT="$1"
23+
fi
24+
echo "$NEW_COMMIT" > rust-version
25+
26+
# Check if we already are at that commit.
27+
CUR_COMMIT=$(rustc +miri --version -v | egrep "^commit-hash: " | cut -d " " -f 2)
28+
if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then
29+
echo "miri toolchain is already at commit $CUR_COMMIT."
30+
rustup override set miri
31+
exit 0
32+
fi
33+
34+
# Cleanup.
35+
cargo +nightly clean # Use nightly cargo as miri toolchain might be broken.
36+
rustup toolchain uninstall miri
37+
38+
# Install and setup new toolchain.
39+
rustup-toolchain-install-master -n miri -c rust-src -c rustc-dev -- "$NEW_COMMIT"
40+
rustup override set miri

0 commit comments

Comments
 (0)