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 Build miri, set up a sysroot and then run the test suite. <flags> are passed
16 to the final `cargo test` invocation.
19 Build miri, set up a sysroot and then run the driver with the given <flags>.
21 All commands also exist in a "-debug" variant (e.g. "./miri run-debug
22 <flags>") which uses debug builds instead of release builds, for faster build
23 times and slower execution times.
28 If already set, the "sysroot setup" step is skipped.
31 Pass extra flags to all cargo invocations.
36 TARGET=$(rustc --version --verbose | grep "^host:" | cut -d ' ' -f 2)
37 SYSROOT=$(rustc --print sysroot)
38 LIBDIR=$SYSROOT/lib/rustlib/$TARGET/lib
39 if ! test -d "$LIBDIR"; then
40 echo "Something went wrong determining the library dir."
41 echo "I got $LIBDIR but that does not exist."
42 echo "Please report a bug at https://github.com/rust-lang/miri/issues."
45 # We set the rpath so that Miri finds the private rustc libraries it needs.
46 # We enable debug-assertions to get tracing.
47 # We enable line-only debuginfo for backtraces.
48 export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR -C debug-assertions -C debuginfo=1 $RUSTC_EXTRA_FLAGS"
52 # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
54 # Build once, for the user to see.
55 cargo run $CARGO_BUILD_FLAGS --bin cargo-miri -- miri setup "$@"
56 # Call again, to just set env var.
57 export MIRI_SYSROOT="$(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --print-sysroot "$@")"
60 # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
61 # locally built vs. distributed rustc.
63 if [ -n "$MIRI_SYSROOT" ]; then
64 # Sysroot already set, use that.
67 # We need to build a sysroot.
68 if [ -n "$MIRI_TEST_TARGET" ]; then
69 build_sysroot --target "$MIRI_TEST_TARGET"
81 # Determine flags passed to all cargo invocations.
82 # This is a bit more annoying that one would hope due to
83 # <https://github.com/rust-lang/cargo/issues/6992>.
86 CARGO_INSTALL_FLAGS="--debug $CARGO_EXTRA_FLAGS"
87 CARGO_BUILD_FLAGS="$CARGO_EXTRA_FLAGS"
90 CARGO_INSTALL_FLAGS="$CARGO_EXTRA_FLAGS"
91 CARGO_BUILD_FLAGS="--release $CARGO_EXTRA_FLAGS"
97 install|install-debug)
98 # "--locked" to respect the Cargo.lock file if it exists,
99 # "--offline" to avoid querying the registry (for yanked packages).
100 exec cargo install $CARGO_INSTALL_FLAGS --path "$(dirname "$0")" --force --locked --offline "$@"
103 # Build, and let caller control flags.
104 exec cargo build $CARGO_BUILD_FLAGS "$@"
107 # First build and get a sysroot.
108 cargo build $CARGO_BUILD_FLAGS
110 # Then test, and let caller control flags.
111 exec cargo test $CARGO_BUILD_FLAGS "$@"
114 # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
115 # that we set the MIRI_SYSROOT up the right way.
116 if [ -z "$MIRI_TEST_TARGET" ]; then
118 if [ "$LAST_ARG" = "--target" ]; then
120 export MIRI_TEST_TARGET="$ARG"
126 # First build and get a sysroot.
127 cargo build $CARGO_BUILD_FLAGS
129 # Then run the actual command.
130 exec cargo run $CARGO_BUILD_FLAGS -- --sysroot "$MIRI_SYSROOT" "$@"
133 echo "Unknown command: $COMMAND"