@@ -5,31 +5,37 @@ USAGE=$(cat <<"EOF"
55
66./miri install <flags>:
77Installs the miri driver and cargo-miri. <flags> are passed to `cargo
8- install`. Sets up the rpath such that the installed binary should work in any
8+ install`. Sets up the rpath such that the installed binary should work in any
99working directory.
1010
1111./miri build <flags>:
12- Just build miri. <flags> are passed to `cargo build`.
12+ Just build miri. <flags> are passed to `cargo build`.
1313
1414./miri check <flags>:
15- Just check miri. <flags> are passed to `cargo check`.
15+ Just check miri. <flags> are passed to `cargo check`.
1616
1717./miri test <flags>:
1818Build miri, set up a sysroot and then run the test suite. <flags> are passed
1919to the final `cargo test` invocation.
2020
2121./miri run <flags>:
2222Build miri, set up a sysroot and then run the driver with the given <flags>.
23+ (Also respects MIRIFLAGS environment variable.)
2324
2425The commands above also exist in a "-debug" variant (e.g. "./miri run-debug
2526<flags>") which uses debug builds instead of release builds, for faster build
2627times and slower execution times.
2728
2829./miri fmt <flags>:
29- Format all sources and tests. <flags> are passed to `rustfmt`.
30+ Format all sources and tests. <flags> are passed to `rustfmt`.
3031
3132./miri clippy <flags>:
32- Format all sources and tests. <flags> are passed to `cargo clippy`.
33+ Format all sources and tests. <flags> are passed to `cargo clippy`.
34+
35+ ./miri many-seeds <command>:
36+ Runs <command> over and over again with different seeds for Miri. The MIRIFLAGS
37+ variable is set to its original value appended with ` -Zmiri-seed=$SEED` for
38+ many different seeds.
3339
3440 ENVIRONMENT VARIABLES
3541
@@ -41,18 +47,39 @@ Pass extra flags to all cargo invocations.
4147EOF
4248)
4349
50+ # Determine command.
51+ COMMAND=" $1 "
52+ [ $# -gt 0 ] && shift
53+
54+ # # Handle some commands early, since they should *not* alter the environment.
55+ case " $COMMAND " in
56+ many-seeds)
57+ for SEED in $( { echo obase=16; seq 0 255; } | bc) ; do
58+ MIRIFLAGS=" $MIRIFLAGS -Zmiri-seed=$SEED " $@ || { echo " Failing seed: $SEED " ; break ; }
59+ done
60+ exit 0
61+ ;;
62+ esac
63+
4464# # Preparation
45- TARGET=$( rustc --version --verbose | grep " ^host:" | cut -d ' ' -f 2)
46- SYSROOT=$( rustc --print sysroot)
47- LIBDIR=$SYSROOT /lib/rustlib/$TARGET /lib
4865# macOS does not have a useful readlink/realpath so we have to use Python instead...
49- MIRIDIR=$( dirname " $( python3 -c ' import os, sys; print(os.path.realpath(sys.argv[1]))' " $0 " ) " )
66+ MIRIDIR=$( python3 -c ' import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' " $0 " )
67+ # Determine toolchain *in the Miri dir* and use that.
68+ TOOLCHAIN=$( cd " $MIRIDIR " ; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
69+
70+ # Determine some toolchain properties
71+ TARGET=$( rustc +$TOOLCHAIN --version --verbose | grep " ^host:" | cut -d ' ' -f 2)
72+ SYSROOT=$( rustc +$TOOLCHAIN --print sysroot)
73+ LIBDIR=$SYSROOT /lib/rustlib/$TARGET /lib
5074if ! test -d " $LIBDIR " ; then
5175 echo " Something went wrong determining the library dir."
5276 echo " I got $LIBDIR but that does not exist."
5377 echo " Please report a bug at https://github.com/rust-lang/miri/issues."
5478 exit 2
5579fi
80+
81+ # Prepare flags for cargo and rustc.
82+ CARGO=" cargo +$TOOLCHAIN "
5683if [ -z " $CARGO_INCREMENTAL " ]; then
5784 # Default CARGO_INCREMENTAL to 1.
5885 export CARGO_INCREMENTAL=1
6592# We enable debug-assertions to get tracing.
6693# We enable line-only debuginfo for backtraces.
6794export RUSTFLAGS=" -C link-args=-Wl,-rpath,$LIBDIR -C debug-assertions -C debuginfo=1 $RUSTFLAGS "
95+ # Determine flags passed to all cargo invocations.
96+ # This is a bit more annoying that one would hope due to
97+ # <https://github.com/rust-lang/cargo/issues/6992>.
98+ case " $COMMAND " in
99+ * -debug)
100+ CARGO_INSTALL_FLAGS=" --target $TARGET --debug $CARGO_EXTRA_FLAGS "
101+ CARGO_BUILD_FLAGS=" --target $TARGET $CARGO_EXTRA_FLAGS "
102+ ;;
103+ * )
104+ CARGO_INSTALL_FLAGS=" --target $TARGET $CARGO_EXTRA_FLAGS "
105+ CARGO_BUILD_FLAGS=" --target $TARGET --release $CARGO_EXTRA_FLAGS "
106+ ;;
107+ esac
68108
69109# # Helper functions
70110
71- # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
111+ # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
72112build_sysroot () {
73113 # Build once, for the user to see.
74- cargo run $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml -- miri setup " $@ "
114+ $CARGO run $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml -- miri setup " $@ "
75115 # Call again, to just set env var.
76- export MIRI_SYSROOT=" $( cargo run $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml -q -- miri setup --print-sysroot " $@ " ) "
116+ export MIRI_SYSROOT=" $( $CARGO run $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml -q -- miri setup --print-sysroot " $@ " ) "
77117}
78118
79- # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
119+ # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
80120# locally built vs. distributed rustc.
81121find_sysroot () {
82122 if [ -n " $MIRI_SYSROOT " ]; then
@@ -93,45 +133,27 @@ find_sysroot() {
93133
94134# # Main
95135
96- # Determine command.
97- COMMAND=" $1 "
98- [ $# -gt 0 ] && shift
99-
100- # Determine flags passed to all cargo invocations.
101- # This is a bit more annoying that one would hope due to
102- # <https://github.com/rust-lang/cargo/issues/6992>.
103- case " $COMMAND " in
104- * -debug)
105- CARGO_INSTALL_FLAGS=" --target $TARGET --debug $CARGO_EXTRA_FLAGS "
106- CARGO_BUILD_FLAGS=" --target $TARGET $CARGO_EXTRA_FLAGS "
107- ;;
108- * )
109- CARGO_INSTALL_FLAGS=" --target $TARGET $CARGO_EXTRA_FLAGS "
110- CARGO_BUILD_FLAGS=" --target $TARGET --release $CARGO_EXTRA_FLAGS "
111- ;;
112- esac
113-
114136# Run command.
115137case " $COMMAND " in
116138install|install-debug)
117139 # "--locked" to respect the Cargo.lock file if it exists,
118140 # "--offline" to avoid querying the registry (for yanked packages).
119- cargo install $CARGO_INSTALL_FLAGS --path " $MIRIDIR " --force --locked --offline " $@ "
120- cargo install $CARGO_INSTALL_FLAGS --path " $MIRIDIR " /cargo-miri --force --locked --offline " $@ "
141+ $CARGO install $CARGO_INSTALL_FLAGS --path " $MIRIDIR " --force --locked --offline " $@ "
142+ $CARGO install $CARGO_INSTALL_FLAGS --path " $MIRIDIR " /cargo-miri --force --locked --offline " $@ "
121143 ;;
122144check|check-debug)
123145 # Check, and let caller control flags.
124- cargo check $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml --all-targets " $@ "
125- cargo check $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml " $@ "
146+ $CARGO check $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml --all-targets " $@ "
147+ $CARGO check $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml " $@ "
126148 ;;
127149build|build-debug)
128150 # Build, and let caller control flags.
129- cargo build $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml " $@ "
130- cargo build $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml " $@ "
151+ $CARGO build $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml " $@ "
152+ $CARGO build $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml " $@ "
131153 ;;
132154test|test-debug|bless|bless-debug)
133155 # First build and get a sysroot.
134- cargo build $CARGO_BUILD_FLAGS
156+ $CARGO build $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml
135157 find_sysroot
136158 case " $COMMAND " in
137159 bless|bless-debug)
@@ -140,8 +162,8 @@ test|test-debug|bless|bless-debug)
140162 esac
141163 # Then test, and let caller control flags.
142164 # Only in root project and ui_test as `cargo-miri` has no tests.
143- cargo test $CARGO_BUILD_FLAGS " $@ "
144- cargo test $CARGO_BUILD_FLAGS --manifest-path ui_test/Cargo.toml " $@ "
165+ $CARGO test $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml " $@ "
166+ $CARGO test $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " / ui_test/Cargo.toml " $@ "
145167 ;;
146168run|run-debug)
147169 # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
@@ -157,19 +179,19 @@ run|run-debug)
157179 done
158180 fi
159181 # First build and get a sysroot.
160- cargo build $CARGO_BUILD_FLAGS
182+ $CARGO build $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml
161183 find_sysroot
162184 # Then run the actual command.
163- exec cargo run $CARGO_BUILD_FLAGS -- -- sysroot " $MIRI_SYSROOT " " $@ "
185+ exec $CARGO run $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml -- -- sysroot " $MIRI_SYSROOT " $MIRIFLAGS " $@ "
164186 ;;
165187fmt)
166188 find " $MIRIDIR " -not \( -name target -prune \) -name ' *.rs' \
167- | xargs rustfmt --edition=2021 --config-path " $MIRIDIR /rustfmt.toml" " $@ "
189+ | xargs rustfmt + $TOOLCHAIN --edition=2021 --config-path " $MIRIDIR /rustfmt.toml" " $@ "
168190 ;;
169191clippy)
170- cargo clippy $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml --all-targets " $@ "
171- cargo clippy $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /ui_test/Cargo.toml --all-targets " $@ "
172- cargo clippy $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml " $@ "
192+ $CARGO clippy $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /Cargo.toml --all-targets " $@ "
193+ $CARGO clippy $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /ui_test/Cargo.toml --all-targets " $@ "
194+ $CARGO clippy $CARGO_BUILD_FLAGS --manifest-path " $MIRIDIR " /cargo-miri/Cargo.toml " $@ "
173195 ;;
174196* )
175197 if [ -n " $COMMAND " ]; then
0 commit comments