From c9b3b688d5121d155cb29df78d83ce1b9cc19a98 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 30 Nov 2019 10:06:12 +0100 Subject: [PATCH 1/4] add toolchain mgmt script --- CONTRIBUTING.md | 46 +++++++++++++++++++--------------------------- toolchain | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 27 deletions(-) create mode 100755 toolchain diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d6436873938e..9338f0b8dd73 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,6 +12,22 @@ on the [Rust Zulip]. [Rust Zulip]: https://rust-lang.zulipchat.com +## Building Miri with a pre-built rustc + +Miri heavily relies on internal rustc interfaces to execute MIR. Still, some +things (like adding support for a new intrinsic or a shim for an external +function being called) can be done by working just on the Miri side. + +The `rust-version` file contains the commit hash of rustc that Miri is currently +tested against. Other versions will likely not work. After installing +[`rustup-toolchain-install-master`], you can run the following command to +install that exact version of rustc as a toolchain: +``` +./toolchain +``` + +[`rustup-toolchain-install-master`]: https://github.com/kennytm/rustup-toolchain-install-master + ### Fixing Miri when rustc changes 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 rustc API, so reading the rustc PR diff is a good way to get an idea for what is needed. -When submitting a PR against Miri after fixing it for rustc changes, make sure -you update the `rust-version` file. That file always contains the exact rustc -git commit with which Miri works, and it is the version that our CI tests Miri -against. - -## Building Miri with a nightly rustc - -Miri heavily relies on internal rustc interfaces to execute MIR. Still, some -things (like adding support for a new intrinsic or a shim for an external -function being called) can be done by working just on the Miri side. - -To prepare, make sure you are using a nightly Rust compiler. You also need to -have the `rust-src` and `rustc-dev` components installed, which you can add via -`rustup component add rust-src rustc-dev`. Then you should be able to just -`cargo build` Miri. - -In case this fails, your nightly might be incompatible with Miri master. The -`rust-version` file contains the commit hash of rustc that Miri is currently -tested against; you can use that to find a nightly that works or you might have -to wait for the next nightly to get released. You can also use -[`rustup-toolchain-install-master`](https://github.com/kennytm/rustup-toolchain-install-master) -to install that exact version of rustc as a toolchain: +To update the `rustc-version` file and install the latest rustc, you can run: ``` -rustup-toolchain-install-master $(cat rust-version) -c rust-src -c rustc-dev +./toolchain HEAD ``` -Another common problem is outdated dependencies: Miri does not come with a -lockfile (it cannot, due to how it gets embedded into the rustc build). So you -have to run `cargo update` every now and then yourself to make sure you are -using the latest versions of everything (which is what gets tested on CI). +Now try `./miri test`, and submit a PR once that works again. ## Testing the Miri driver [testing-miri]: #testing-the-miri-driver diff --git a/toolchain b/toolchain new file mode 100755 index 000000000000..043b2ee2edd7 --- /dev/null +++ b/toolchain @@ -0,0 +1,40 @@ +#!/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: +# +# ./toolchain: Update "miri" toolchain to match `rust-version` (the known-good version for this commit). +# +# ./toolchain HEAD: Update "miri" toolchain and `rust-version` file to latest rustc HEAD. +# +# ./toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit. + +# 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 + +# Check if we already are at that commit. +CUR_COMMIT=$(rustc +miri --version -v | egrep "^commit-hash: " | cut -d " " -f 2) +if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then + echo "miri toolchain is already at commit $CUR_COMMIT." + rustup override set miri + exit 0 +fi + +# Cleanup. +cargo +nightly clean # Use nightly cargo as miri toolchain might be broken. +rustup toolchain uninstall miri + +# Install and setup new toolchain. +rustup-toolchain-install-master -n miri -c rust-src -c rustc-dev -- "$NEW_COMMIT" +rustup override set miri From f838410f492690e09626e9ae95f110f948235dce Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 1 Dec 2019 10:20:16 +0100 Subject: [PATCH 2/4] toolchain -> rustup-toolchain --- CONTRIBUTING.md | 4 ++-- toolchain => rustup-toolchain | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename toolchain => rustup-toolchain (76%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9338f0b8dd73..c673e107d55d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,7 +23,7 @@ tested against. Other versions will likely not work. After installing [`rustup-toolchain-install-master`], you can run the following command to install that exact version of rustc as a toolchain: ``` -./toolchain +./rustup-toolchain ``` [`rustup-toolchain-install-master`]: https://github.com/kennytm/rustup-toolchain-install-master @@ -38,7 +38,7 @@ needed. To update the `rustc-version` file and install the latest rustc, you can run: ``` -./toolchain HEAD +./rustup-toolchain HEAD ``` Now try `./miri test`, and submit a PR once that works again. diff --git a/toolchain b/rustup-toolchain similarity index 76% rename from toolchain rename to rustup-toolchain index 043b2ee2edd7..a981ec76548a 100755 --- a/toolchain +++ b/rustup-toolchain @@ -7,11 +7,11 @@ set -e # # USAGE: # -# ./toolchain: Update "miri" toolchain to match `rust-version` (the known-good version for this commit). +# ./rustup-toolchain: Update "miri" toolchain to match `rust-version` (the known-good version for this commit). # -# ./toolchain HEAD: Update "miri" toolchain and `rust-version` file to latest rustc HEAD. +# ./rustup-toolchain HEAD: Update "miri" toolchain and `rust-version` file to latest rustc HEAD. # -# ./toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit. +# ./rustup-toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit. # Determine new commit. if [[ "$1" == "" ]]; then From 0a4ec5d34e542ff00ff41110b0fc42072bd1b4aa Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 1 Dec 2019 10:22:16 +0100 Subject: [PATCH 3/4] test for rustup-toolchain-install-master --- rustup-toolchain | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rustup-toolchain b/rustup-toolchain index a981ec76548a..096fa8857bab 100755 --- a/rustup-toolchain +++ b/rustup-toolchain @@ -13,6 +13,12 @@ set -e # # ./rustup-toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit. +# 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 + # Determine new commit. if [[ "$1" == "" ]]; then NEW_COMMIT=$(cat rust-version) From 9501d044c1afcd2c7921e48ef17930977d156dec Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 1 Dec 2019 15:16:55 +0100 Subject: [PATCH 4/4] don't assume a nightly toolchain is installed --- rustup-toolchain | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rustup-toolchain b/rustup-toolchain index 096fa8857bab..4e8e0b01ebc4 100755 --- a/rustup-toolchain +++ b/rustup-toolchain @@ -30,17 +30,17 @@ fi echo "$NEW_COMMIT" > rust-version # Check if we already are at that commit. -CUR_COMMIT=$(rustc +miri --version -v | egrep "^commit-hash: " | cut -d " " -f 2) +CUR_COMMIT=$(rustc +miri --version -v 2>/dev/null | egrep "^commit-hash: " | cut -d " " -f 2) if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then echo "miri toolchain is already at commit $CUR_COMMIT." rustup override set miri exit 0 fi -# Cleanup. -cargo +nightly clean # Use nightly cargo as miri toolchain might be broken. -rustup toolchain uninstall miri - # Install and setup new toolchain. +rustup toolchain uninstall miri rustup-toolchain-install-master -n miri -c rust-src -c rustc-dev -- "$NEW_COMMIT" rustup override set miri + +# Cleanup. +cargo clean