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>.
24 All commands also exist in a "-debug" variant (e.g. "./miri run-debug
25 <flags>") which uses debug builds instead of release builds, for faster build
26 times and slower execution times.
31 If already set, the "sysroot setup" step is skipped.
34 Pass extra flags to all cargo invocations.
39 TARGET=$(rustc --version --verbose | grep "^host:" | cut -d ' ' -f 2)
40 SYSROOT=$(rustc --print sysroot)
41 LIBDIR=$SYSROOT/lib/rustlib/$TARGET/lib
42 if ! test -d "$LIBDIR"; then
43 echo "Something went wrong determining the library dir."
44 echo "I got $LIBDIR but that does not exist."
45 echo "Please report a bug at https://github.com/rust-lang/miri/issues."
48 # We set the rpath so that Miri finds the private rustc libraries it needs.
49 # We enable debug-assertions to get tracing.
50 # We enable line-only debuginfo for backtraces.
51 export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR -C debug-assertions -C debuginfo=1 $RUSTC_EXTRA_FLAGS"
52 if [ -z "$CARGO_INCREMENTAL" ]; then
53 # Default CARGO_INCREMENTAL to 1.
54 export CARGO_INCREMENTAL=1
59 # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
61 # Build once, for the user to see.
62 cargo run $CARGO_BUILD_FLAGS --bin cargo-miri -- miri setup "$@"
63 # Call again, to just set env var.
64 export MIRI_SYSROOT="$(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --print-sysroot "$@")"
67 # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
68 # locally built vs. distributed rustc.
70 if [ -n "$MIRI_SYSROOT" ]; then
71 # Sysroot already set, use that.
74 # We need to build a sysroot.
75 if [ -n "$MIRI_TEST_TARGET" ]; then
76 build_sysroot --target "$MIRI_TEST_TARGET"
88 # Determine flags passed to all cargo invocations.
89 # This is a bit more annoying that one would hope due to
90 # <https://github.com/rust-lang/cargo/issues/6992>.
93 CARGO_INSTALL_FLAGS="--debug $CARGO_EXTRA_FLAGS"
94 CARGO_BUILD_FLAGS="$CARGO_EXTRA_FLAGS"
97 CARGO_INSTALL_FLAGS="$CARGO_EXTRA_FLAGS"
98 CARGO_BUILD_FLAGS="--release $CARGO_EXTRA_FLAGS"
104 install|install-debug)
105 # "--locked" to respect the Cargo.lock file if it exists,
106 # "--offline" to avoid querying the registry (for yanked packages).
107 exec cargo install $CARGO_INSTALL_FLAGS --path "$(dirname "$0")" --force --locked --offline "$@"
110 # Check, and let caller control flags.
111 exec cargo check $CARGO_BUILD_FLAGS "$@"
114 # Build, and let caller control flags.
115 exec cargo build $CARGO_BUILD_FLAGS "$@"
118 # First build and get a sysroot.
119 cargo build $CARGO_BUILD_FLAGS
121 # Then test, and let caller control flags.
122 exec cargo test $CARGO_BUILD_FLAGS "$@"
125 # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
126 # that we set the MIRI_SYSROOT up the right way.
127 if [ -z "$MIRI_TEST_TARGET" ]; then
129 if [ "$LAST_ARG" = "--target" ]; then
131 export MIRI_TEST_TARGET="$ARG"
137 # First build and get a sysroot.
138 cargo build $CARGO_BUILD_FLAGS
140 # Then run the actual command.
141 exec cargo run $CARGO_BUILD_FLAGS -- --sysroot "$MIRI_SYSROOT" "$@"
144 if [ -n "$COMMAND" ]; then
145 echo "Unknown command: $COMMAND"