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
11 # ./miri build <flags>:
12 # Just build miri. <flags> are passed to `cargo build`.
14 # ./miri test <flags>:
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.
25 # ENVIRONMENT VARIABLES
28 # If already set, the "sysroot setup" step is skipped.
31 # Pass extra flags to all cargo invocations.
35 # I'd love to use `jq` for parsing the JSON properly, but macOS is totally underequipped for this kind of work.
36 TARGET=$(rustc --print target-spec-json -Z unstable-options | grep llvm-target | cut -d '"' -f 4)
37 SYSROOT=$(rustc --print sysroot)
38 # We set the rpath so that Miri finds the private rustc libraries it needs.
39 # We enable debug-assertions to get tracing.
40 # We enable line-only debuginfo for backtraces.
41 export RUSTFLAGS="-C link-args=-Wl,-rpath,$SYSROOT/lib/rustlib/$TARGET/lib -C debug-assertions -C debuginfo=1"
45 # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
47 # Build once, for the user to see.
48 cargo run $CARGO_BUILD_FLAGS --bin cargo-miri -- miri setup "$@"
49 # Call again, to just set env var.
50 eval $(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --env "$@")
54 # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
55 # locally built vs. distributed rustc.
57 # Get ourselves a sysroot
58 if [ -n "$MIRI_SYSROOT" ]; then
59 # Sysroot already set, use that.
61 elif echo "$SYSROOT" | egrep -q 'build/[^/]+/stage'; then
62 # A local rustc build.
63 if [ -n "$MIRI_TEST_TARGET" ]; then
64 # Foreign targets still need a build. Use the rustc sources.
65 export XARGO_RUST_SRC="$SYSROOT/../../../src"
66 build_sysroot --target "$MIRI_TEST_TARGET"
68 # Assume we have a proper host libstd in $SYSROOT.
72 # A normal toolchain. We have to build a sysroot either way.
73 if [ -n "$MIRI_TEST_TARGET" ]; then
74 build_sysroot --target "$MIRI_TEST_TARGET"
87 # Determine flags passed to all cargo invocations.
90 CARGO_INSTALL_FLAGS="--debug $CARGO_EXTRA_FLAGS"
91 CARGO_BUILD_FLAGS="$CARGO_EXTRA_FLAGS"
94 CARGO_INSTALL_FLAGS="$CARGO_EXTRA_FLAGS"
95 CARGO_BUILD_FLAGS="--release $CARGO_EXTRA_FLAGS"
101 install|install-debug)
102 # "--locked" to respect the Cargo.lock file if it exists,
103 # "--offline" to avoid querying the registry (for yanked packages).
104 exec cargo install --path "$(dirname "$0")" --force --locked --offline "$@"
107 # Build, and let caller control flags.
108 exec cargo build $CARGO_BUILD_FLAGS "$@"
111 # First build and get a sysroot.
112 cargo build $CARGO_BUILD_FLAGS
114 # Then test, and let caller control flags.
115 exec cargo test $CARGO_BUILD_FLAGS "$@"
118 # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
119 # that we set the MIRI_SYSROOT up the right way.
120 if [ -z "$MIRI_TEST_TARGET" ]; then
122 if [ "$LAST_ARG" = "--target" ]; then
124 export MIRI_TEST_TARGET="$ARG"
130 # First build and get a sysroot.
131 cargo build $CARGO_BUILD_FLAGS
133 # Then run the actual command.
134 exec cargo run $CARGO_BUILD_FLAGS "$@"