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 eval $(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --env "$@")
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 echo "$SYSROOT" | egrep -q 'build/[^/]+/stage'; then
69 # A local rustc build. Use its source dir.
70 export XARGO_RUST_SRC="$SYSROOT/../../../src"
72 if [ -n "$MIRI_TEST_TARGET" ]; then
73 build_sysroot --target "$MIRI_TEST_TARGET"
86 # Determine flags passed to all cargo invocations.
87 # This is a bit more annoying that one would hope due to
88 # <https://github.com/rust-lang/cargo/issues/6992>.
91 CARGO_INSTALL_FLAGS="--debug $CARGO_EXTRA_FLAGS"
92 CARGO_BUILD_FLAGS="$CARGO_EXTRA_FLAGS"
95 CARGO_INSTALL_FLAGS="$CARGO_EXTRA_FLAGS"
96 CARGO_BUILD_FLAGS="--release $CARGO_EXTRA_FLAGS"
102 install|install-debug)
103 # "--locked" to respect the Cargo.lock file if it exists,
104 # "--offline" to avoid querying the registry (for yanked packages).
105 exec cargo install $CARGO_INSTALL_FLAGS --path "$(dirname "$0")" --force --locked --offline "$@"
108 # Build, and let caller control flags.
109 exec cargo build $CARGO_BUILD_FLAGS "$@"
112 # First build and get a sysroot.
113 cargo build $CARGO_BUILD_FLAGS
115 # Then test, and let caller control flags.
116 exec cargo test $CARGO_BUILD_FLAGS "$@"
119 # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
120 # that we set the MIRI_SYSROOT up the right way.
121 if [ -z "$MIRI_TEST_TARGET" ]; then
123 if [ "$LAST_ARG" = "--target" ]; then
125 export MIRI_TEST_TARGET="$ARG"
131 # First build and get a sysroot.
132 cargo build $CARGO_BUILD_FLAGS
134 # Then run the actual command.
135 exec cargo run $CARGO_BUILD_FLAGS -- --sysroot "$MIRI_SYSROOT" "$@"
138 echo "Unknown command: $COMMAND"