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"
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 "$@")
61 # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
62 # locally built vs. distributed rustc.
64 # Get ourselves a sysroot
65 if [ -n "$MIRI_SYSROOT" ]; then
66 # Sysroot already set, use that.
68 elif echo "$SYSROOT" | egrep -q 'build/[^/]+/stage'; then
69 # A local rustc build.
70 if [ -n "$MIRI_TEST_TARGET" ]; then
71 # Foreign targets still need a build. Use the rustc sources.
72 export XARGO_RUST_SRC="$SYSROOT/../../../src"
73 build_sysroot --target "$MIRI_TEST_TARGET"
75 # Assume we have a proper host libstd in $SYSROOT.
79 # A normal toolchain. We have to build a sysroot either way.
80 if [ -n "$MIRI_TEST_TARGET" ]; then
81 build_sysroot --target "$MIRI_TEST_TARGET"
94 # Determine flags passed to all cargo invocations.
95 # This is a bit more annoying that one would hope due to
96 # <https://github.com/rust-lang/cargo/issues/6992>.
99 CARGO_INSTALL_FLAGS="--debug $CARGO_EXTRA_FLAGS"
100 CARGO_BUILD_FLAGS="$CARGO_EXTRA_FLAGS"
103 CARGO_INSTALL_FLAGS="$CARGO_EXTRA_FLAGS"
104 CARGO_BUILD_FLAGS="--release $CARGO_EXTRA_FLAGS"
110 install|install-debug)
111 # "--locked" to respect the Cargo.lock file if it exists,
112 # "--offline" to avoid querying the registry (for yanked packages).
113 exec cargo install $CARGO_INSTALL_FLAGS --path "$(dirname "$0")" --force --locked --offline "$@"
116 # Build, and let caller control flags.
117 exec cargo build $CARGO_BUILD_FLAGS "$@"
120 # First build and get a sysroot.
121 cargo build $CARGO_BUILD_FLAGS
123 # Then test, and let caller control flags.
124 exec cargo test $CARGO_BUILD_FLAGS "$@"
127 # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
128 # that we set the MIRI_SYSROOT up the right way.
129 if [ -z "$MIRI_TEST_TARGET" ]; then
131 if [ "$LAST_ARG" = "--target" ]; then
133 export MIRI_TEST_TARGET="$ARG"
139 # First build and get a sysroot.
140 cargo build $CARGO_BUILD_FLAGS
142 # Then run the actual command.
143 exec cargo run $CARGO_BUILD_FLAGS "$@"
146 echo "Unknown command: $COMMAND"