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 MIRIDIR=$(readlink -e "$(dirname "$0")")
43 if ! test -d "$LIBDIR"; then
44 echo "Something went wrong determining the library dir."
45 echo "I got $LIBDIR but that does not exist."
46 echo "Please report a bug at https://github.com/rust-lang/miri/issues."
49 if [ -z "$CARGO_INCREMENTAL" ]; then
50 # Default CARGO_INCREMENTAL to 1.
51 export CARGO_INCREMENTAL=1
53 if [ -z "$CARGO_TARGET_DIR" ]; then
54 # Share target dir between `miri` and `cargo-miri`.
55 export CARGO_TARGET_DIR="$MIRIDIR/target"
57 # We set the rpath so that Miri finds the private rustc libraries it needs.
58 # We enable debug-assertions to get tracing.
59 # We enable line-only debuginfo for backtraces.
60 export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR -C debug-assertions -C debuginfo=1 $RUSTFLAGS"
64 # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
66 # Build once, for the user to see.
67 cargo run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -- miri setup "$@"
68 # Call again, to just set env var.
69 export MIRI_SYSROOT="$(cargo run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -q -- miri setup --print-sysroot "$@")"
72 # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
73 # locally built vs. distributed rustc.
75 if [ -n "$MIRI_SYSROOT" ]; then
76 # Sysroot already set, use that.
79 # We need to build a sysroot.
80 if [ -n "$MIRI_TEST_TARGET" ]; then
81 build_sysroot --target "$MIRI_TEST_TARGET"
93 # Determine flags passed to all cargo invocations.
94 # This is a bit more annoying that one would hope due to
95 # <https://github.com/rust-lang/cargo/issues/6992>.
98 CARGO_INSTALL_FLAGS="--target $TARGET --debug $CARGO_EXTRA_FLAGS"
99 CARGO_BUILD_FLAGS="--target $TARGET $CARGO_EXTRA_FLAGS"
102 CARGO_INSTALL_FLAGS="--target $TARGET $CARGO_EXTRA_FLAGS"
103 CARGO_BUILD_FLAGS="--target $TARGET --release $CARGO_EXTRA_FLAGS"
109 install|install-debug)
110 # "--locked" to respect the Cargo.lock file if it exists,
111 # "--offline" to avoid querying the registry (for yanked packages).
112 cargo install $CARGO_INSTALL_FLAGS --path "$MIRIDIR" --force --locked --offline "$@"
113 cargo install $CARGO_INSTALL_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked --offline "$@"
116 # Check, and let caller control flags.
117 cargo check $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
118 cargo check $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
121 # Build, and let caller control flags.
122 cargo build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
123 cargo build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
126 # First build and get a sysroot.
127 cargo build $CARGO_BUILD_FLAGS
129 # Then test, and let caller control flags.
130 # Only in root project as `cargo-miri` has no tests.
131 exec cargo test $CARGO_BUILD_FLAGS "$@"
134 # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
135 # that we set the MIRI_SYSROOT up the right way.
136 if [ -z "$MIRI_TEST_TARGET" ]; then
138 if [ "$LAST_ARG" = "--target" ]; then
140 export MIRI_TEST_TARGET="$ARG"
146 # First build and get a sysroot.
147 cargo build $CARGO_BUILD_FLAGS
149 # Then run the actual command.
150 exec cargo run $CARGO_BUILD_FLAGS -- --sysroot "$MIRI_SYSROOT" "$@"
153 if [ -n "$COMMAND" ]; then
154 echo "Unknown command: $COMMAND"