Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ before_script:
if [ "$TRAVIS_EVENT_TYPE" = cron ]; then
RUST_TOOLCHAIN=nightly
else
RUST_TOOLCHAIN=$(cat rust-toolchain)
RUST_TOOLCHAIN=$(cat rust-version)
fi
- rm rust-toolchain
# install Rust
- curl https://build.travis-ci.org/files/rustup-init.sh -sSf | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN"
- export PATH=$HOME/.cargo/bin:$PATH
Expand Down
56 changes: 42 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ undergraduate research course at the [University of Saskatchewan][usask].
## Building Miri

I recommend that you install [rustup][rustup] to obtain Rust. Miri comes with a
`rust-toolchain` file so rustup will automatically pick a suitable nightly
version. Then all you have to do is:
`rust-version` file describing the latest supported nightly version of the Rust
compiler toolchain. Then all you have to do is:

```sh
cargo build
cargo +nightly build
```

with `+nightly` replaced with the appropriate nightly version of Rust.

## Running Miri

```sh
cargo run tests/run-pass/vecs.rs # Or whatever test you like.
cargo +nightly run tests/run-pass/vecs.rs # Or whatever test you like.
```

## Running Miri with full libstd
Expand All @@ -28,15 +30,15 @@ Miri hits a call to such a function, execution terminates. To fix this, it is
possible to compile libstd with full MIR:

```sh
rustup component add rust-src
cargo install xargo
xargo/build.sh
rustup component add --toolchain nightly rust-src
cargo +nightly install xargo
rustup run nightly xargo/build.sh
```

Now you can run Miri against the libstd compiled by xargo:

```sh
MIRI_SYSROOT=~/.xargo/HOST cargo run tests/run-pass-fullmir/hashmap.rs
MIRI_SYSROOT=~/.xargo/HOST cargo +nightly run tests/run-pass-fullmir/hashmap.rs
```

Notice that you will have to re-run the last step of the preparations above when
Expand All @@ -47,13 +49,39 @@ You can also set `-Zmiri-start-fn` to make Miri start evaluation with the

## Running Miri on your own project('s test suite)

Install Miri as a cargo subcommand with `cargo install --all-features`, and install
a full libstd as described above.
Install Miri as a cargo subcommand with `cargo install +nightly --all-features --path .`.

Compile your project and its dependencies against a MIR-enabled libstd as described
above:

1. Run `cargo clean` to eliminate any cached dependencies that were built against
the non-MIR `libstd`.
2. To run all tests in your project through, Miri, use
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test`.
3. If you have a binary project, you can run it through Miri using
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri`.

### Common Problems

When using the above instructions, you may encounter a number of confusing compiler
errors.

#### "constant evaluation error: no mir for `<function>`"

You may have forgotten to set `MIRI_SYSROOT` when calling `cargo miri`, and
your program called into `std` or `core`. Be sure to set `MIRI_SYSROOT=~/.xargo/HOST`.

#### "found possibly newer version of crate `std` which `<dependency>` depends on"

Your build directory may contain artifacts from an earlier build that did/did not
have `MIRI_SYSROOT` set. Run `cargo clean` before switching from non-Miri to Miri
builds and vice-versa.

#### "found crate `std` compiled by an incompatible version of rustc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand how/why this is different from the one right before. Seems to me both are caused by "sysroot confusion", and both are solved the same way. Why should we give different advise for these two?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. They have different causes and different solutions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the difference is "deps were built without MIRI_SYSROOT vs MIRI_SYSROOT was built with the wrong toolchain, I see. Makes sense.

I think what threw me off was specifically mentioning cargo miri test. The same applies to cargo miri, right? So maybe just say cargo miri then.


Then, inside your own project, use `MIRI_SYSROOT=~/.xargo/HOST cargo +nightly
miri` to run your project, if it is a bin project, or run
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test` to run all tests in your
project through Miri.
You may be running `cargo miri` with a different compiler version than the one
used to build the MIR-enabled `std`. Be sure to consistently use the same toolchain,
which should be the toolchain specified in the `rust-version` file.

## Miri `-Z` flags

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ branches:
install:
# install Rust
- set PATH=C:\Program Files\Git\mingw64\bin;C:\msys64\mingw%MSYS2_BITS%\bin;%PATH%
- set /p RUST_TOOLCHAIN=<rust-toolchain
- set /p RUST_TOOLCHAIN=<rust-version
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
- rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_TOOLCHAIN%
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
Expand Down
File renamed without changes.