@@ -7,18 +7,28 @@ undergraduate research course at the [University of Saskatchewan][usask].
7
7
8
8
## Building Miri
9
9
10
- I recommend that you install [ rustup] [ rustup ] to obtain Rust. Miri comes with a
11
- ` rust-toolchain ` file so rustup will automatically pick a suitable nightly
12
- version. Then all you have to do is:
10
+ I recommend that you install [ rustup] [ rustup ] to obtain Rust. Then all you have
11
+ to do is:
13
12
14
13
``` sh
15
- cargo build
14
+ cargo +nightly build
16
15
```
17
16
17
+ This uses the very latest Rust version. If you experience any problem, refer to
18
+ the ` rust-version ` file which contains a particular Rust nightly version that
19
+ has been tested against the version of miri you are using. Make sure to use
20
+ that particular ` nightly-YYYY-MM-DD ` whenever the instructions just say
21
+ ` nightly ` .
22
+
23
+ To avoid repeating the nightly version all the time, you can use
24
+ ` rustup override set nightly ` (or ` rustup override set nightly-YYYY-MM-DD ` ),
25
+ which means ` nightly ` Rust will automatically be used whenever you are working
26
+ in this directory.
27
+
18
28
## Running Miri
19
29
20
30
``` sh
21
- cargo run tests/run-pass/vecs.rs # Or whatever test you like.
31
+ cargo +nightly run tests/run-pass/vecs.rs # Or whatever test you like.
22
32
```
23
33
24
34
## Running Miri with full libstd
@@ -28,40 +38,77 @@ Miri hits a call to such a function, execution terminates. To fix this, it is
28
38
possible to compile libstd with full MIR:
29
39
30
40
``` sh
31
- rustup component add rust-src
32
- cargo install xargo
33
- xargo/build.sh
41
+ rustup component add --toolchain nightly rust-src
42
+ cargo +nightly install xargo
43
+ rustup run nightly xargo/build.sh
34
44
```
35
45
36
46
Now you can run Miri against the libstd compiled by xargo:
37
47
38
48
``` sh
39
- MIRI_SYSROOT=~ /.xargo/HOST cargo run tests/run-pass-fullmir/hashmap.rs
49
+ MIRI_SYSROOT=~ /.xargo/HOST cargo +nightly run tests/run-pass-fullmir/hashmap.rs
40
50
```
41
51
42
- Notice that you will have to re-run the last step of the preparations above when
43
- your toolchain changes (e.g., when you update the nightly).
44
-
45
- You can also set ` -Zmiri-start-fn ` to make Miri start evaluation with the
46
- ` start_fn ` lang item, instead of starting at the ` main ` function.
52
+ Notice that you will have to re-run the last step of the preparations above
53
+ (` xargo/build.sh ` ) when your toolchain changes (e.g., when you update the
54
+ nightly).
47
55
48
56
## Running Miri on your own project('s test suite)
49
57
50
- Install Miri as a cargo subcommand with ` cargo install --all-features ` , and install
51
- a full libstd as described above.
58
+ Install Miri as a cargo subcommand with `cargo install +nightly --all-features
59
+ --path .` . Be aware that if you used ` rustup override set` to fix a particular
60
+ Rust version for the miri directory, that will * not* apply to your own project
61
+ directory! You have to use a consistent Rust version for building miri and your
62
+ project for this to work, so remember to either always specify the nightly
63
+ version manually, overriding it in your project directory as well, or use
64
+ ` rustup default nightly ` (or ` rustup default nightly-YYYY-MM-DD ` ) to globally
65
+ make ` nightly ` the default toolchain.
52
66
53
- Then, inside your own project, use `MIRI_SYSROOT=~ /.xargo/HOST cargo +nightly
54
- miri` to run your project, if it is a bin project, or run
55
- ` MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test ` to run all tests in your
56
- project through Miri.
67
+ We assume that you have prepared a MIR-enabled libstd as described above. Now
68
+ compile your project and its dependencies against that libstd:
57
69
58
- ## Miri ` -Z ` flags
70
+ 1 . Run ` cargo clean ` to eliminate any cached dependencies that were built against
71
+ the non-MIR ` libstd ` .
72
+ 2 . To run all tests in your project through, Miri, use
73
+ ` MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test ` .
74
+ 3 . If you have a binary project, you can run it through Miri using
75
+ ` MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri ` .
76
+
77
+ ### Common Problems
78
+
79
+ When using the above instructions, you may encounter a number of confusing compiler
80
+ errors.
81
+
82
+ #### "constant evaluation error: no mir for ` <function> ` "
59
83
60
- Miri adds some extra ` -Z ` flags to control its behavior:
84
+ You may have forgotten to set ` MIRI_SYSROOT ` when calling ` cargo miri ` , and
85
+ your program called into ` std ` or ` core ` . Be sure to set ` MIRI_SYSROOT=~/.xargo/HOST ` .
86
+
87
+ #### "found possibly newer version of crate ` std ` which ` <dependency> ` depends on"
88
+
89
+ Your build directory may contain artifacts from an earlier build that did/did not
90
+ have ` MIRI_SYSROOT ` set. Run ` cargo clean ` before switching from non-Miri to Miri
91
+ builds and vice-versa.
92
+
93
+ #### "found crate ` std ` compiled by an incompatible version of rustc"
94
+
95
+ You may be running ` cargo miri ` with a different compiler version than the one
96
+ used to build the MIR-enabled ` std ` . Be sure to consistently use the same toolchain,
97
+ which should be the toolchain specified in the ` rust-version ` file.
98
+
99
+ ## Miri ` -Z ` flags
61
100
62
- * ` -Zmiri-start-fn ` : This makes interpretation start with ` lang_start ` (defined
63
- in libstd) instead of starting with ` main ` . Requires full MIR!
64
- * ` -Zmiri-disable-validation ` disables enforcing the validity invariant.
101
+ Several ` -Z ` flags are relevant for miri:
102
+
103
+ * ` -Zmir-opt-level ` controls how many MIR optimizations are performed. miri
104
+ overrides the default to be ` 0 ` ; be advised that using any higher level can
105
+ make miri miss bugs in your program because they got optimized away.
106
+ * ` -Zalways-encode-mir ` makes rustc dump MIR even for completely monomorphic
107
+ functions. This is needed so that miri can execute such functions, so miri
108
+ sets this flag per default.
109
+ * ` -Zmiri-disable-validation ` is a custom ` -Z ` flag added by miri. It disables
110
+ enforcing the validity invariant, which is enforced by default. This is
111
+ mostly useful for debugging; it means miri will miss bugs in your program.
65
112
66
113
## Development and Debugging
67
114
0 commit comments