6 ./miri install <flags>:
7 Installs 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
12 Just build miri. <flags> are passed to `cargo build`.
15 Just check miri. <flags> are passed to `cargo check`.
18 Build miri, set up a sysroot and then run the test suite. <flags> are passed
19 to the final `cargo test` invocation.
22 Build miri, set up a sysroot and then run the driver with the given <flags>.
23 (Also respects MIRIFLAGS environment variable.)
25 The commands above also exist in a "-debug" variant (e.g. "./miri run-debug
26 <flags>") which uses debug builds instead of release builds, for faster build
27 times and slower execution times.
30 Format all sources and tests. <flags> are passed to `rustfmt`.
32 ./miri clippy <flags>:
33 Format all sources and tests. <flags> are passed to `cargo clippy`.
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
43 If already set, the "sysroot setup" step is skipped.
46 Pass extra flags to all cargo invocations.
54 ## Handle some commands early, since they should *not* alter the environment.
57 for SEED in $({ echo obase=16; seq 0 255; } | bc); do
58 echo "Trying seed: $SEED"
59 MIRIFLAGS="$MIRIFLAGS -Zmiri-seed=$SEED" $@ || { echo "Failing seed: $SEED"; break; }
66 # macOS does not have a useful readlink/realpath so we have to use Python instead...
67 MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0")
68 # Determine toolchain *in the Miri dir* and use that.
69 TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
71 # Determine some toolchain properties
72 TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
73 SYSROOT=$(rustc +$TOOLCHAIN --print sysroot)
74 LIBDIR=$SYSROOT/lib/rustlib/$TARGET/lib
75 if ! test -d "$LIBDIR"; then
76 echo "Something went wrong determining the library dir."
77 echo "I got $LIBDIR but that does not exist."
78 echo "Please report a bug at https://github.com/rust-lang/miri/issues."
82 # Prepare flags for cargo and rustc.
83 CARGO="cargo +$TOOLCHAIN"
84 if [ -z "$CARGO_INCREMENTAL" ]; then
85 # Default CARGO_INCREMENTAL to 1.
86 export CARGO_INCREMENTAL=1
88 if [ -z "$CARGO_TARGET_DIR" ]; then
89 # Share target dir between `miri` and `cargo-miri`.
90 export CARGO_TARGET_DIR="$MIRIDIR/target"
92 # We set the rpath so that Miri finds the private rustc libraries it needs.
93 # We enable debug-assertions to get tracing.
94 # We enable line-only debuginfo for backtraces.
95 export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR -C debug-assertions -C debuginfo=1 $RUSTFLAGS"
96 # Determine flags passed to all cargo invocations.
97 # This is a bit more annoying that one would hope due to
98 # <https://github.com/rust-lang/cargo/issues/6992>.
101 CARGO_INSTALL_FLAGS="--target $TARGET --debug $CARGO_EXTRA_FLAGS"
102 CARGO_BUILD_FLAGS="--target $TARGET $CARGO_EXTRA_FLAGS"
105 CARGO_INSTALL_FLAGS="--target $TARGET $CARGO_EXTRA_FLAGS"
106 CARGO_BUILD_FLAGS="--target $TARGET --release $CARGO_EXTRA_FLAGS"
112 # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
114 # Build once, for the user to see.
115 $CARGO run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -- miri setup "$@"
116 # Call again, to just set env var.
117 export MIRI_SYSROOT="$($CARGO run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -q -- miri setup --print-sysroot "$@")"
120 # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
121 # locally built vs. distributed rustc.
123 if [ -n "$MIRI_SYSROOT" ]; then
124 # Sysroot already set, use that.
127 # We need to build a sysroot.
128 if [ -n "$MIRI_TEST_TARGET" ]; then
129 build_sysroot --target "$MIRI_TEST_TARGET"
139 install|install-debug)
140 # "--locked" to respect the Cargo.lock file if it exists,
141 # "--offline" to avoid querying the registry (for yanked packages).
142 $CARGO install $CARGO_INSTALL_FLAGS --path "$MIRIDIR" --force --locked --offline "$@"
143 $CARGO install $CARGO_INSTALL_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked --offline "$@"
146 # Check, and let caller control flags.
147 $CARGO check $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml --all-targets "$@"
148 $CARGO check $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
151 # Build, and let caller control flags.
152 $CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
153 $CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
155 test|test-debug|bless|bless-debug)
156 # First build and get a sysroot.
157 $CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
161 export MIRI_BLESS="Gesundheit"
164 # Then test, and let caller control flags.
165 # Only in root project and ui_test as `cargo-miri` has no tests.
166 $CARGO test $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
167 $CARGO test $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/ui_test/Cargo.toml "$@"
170 # Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
171 # that we set the MIRI_SYSROOT up the right way.
174 if [ "$LAST_ARG" = "--target" ]; then
176 export MIRI_TEST_TARGET="$ARG"
182 if [ "$FOUND_TARGET_OPT" = "0" ] && [ -n "$MIRI_TEST_TARGET" ]; then
183 # Make sure Miri actually uses this target.
184 MIRIFLAGS="$MIRIFLAGS --target $MIRI_TEST_TARGET"
186 # First build and get a sysroot.
187 $CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
189 # Then run the actual command.
190 exec $CARGO run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- --sysroot "$MIRI_SYSROOT" $MIRIFLAGS "$@"
193 find "$MIRIDIR" -not \( -name target -prune \) -name '*.rs' \
194 | xargs rustfmt +$TOOLCHAIN --edition=2021 --config-path "$MIRIDIR/rustfmt.toml" "$@"
197 $CARGO clippy $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml --all-targets "$@"
198 $CARGO clippy $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/ui_test/Cargo.toml --all-targets "$@"
199 $CARGO clippy $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
202 if [ -n "$COMMAND" ]; then
203 echo "Unknown command: $COMMAND"