3 # I'd love to use `jq` for parsing the JSON properly, but macOS is totally underequipped for this kind of work.
4 TARGET=$(rustc --print target-spec-json -Z unstable-options | grep llvm-target | cut -d '"' -f 4)
5 SYSROOT=$(rustc --print sysroot)
6 # We set the rpath so that Miri finds the private rustc libraries it needs.
7 # We enable debug-assertions to get tracing.
8 # We enable line-only debuginfo for backtraces.
9 export RUSTFLAGS="-C link-args=-Wl,-rpath,$SYSROOT/lib/rustlib/$TARGET/lib -C debug-assertions -C debuginfo=1"
13 # Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
15 # Build once, for the user to see.
16 cargo run --release --bin cargo-miri -- miri setup "$@"
17 # Call again, to just set env var.
18 eval $(cargo run --release -q --bin cargo-miri -- miri setup --env "$@")
22 # Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
23 # locally built vs. distributed rustc.
25 # Get ourselves a sysroot
26 if [ -n "$MIRI_SYSROOT" ]; then
27 # Sysroot already set, use that.
29 elif echo "$SYSROOT" | egrep -q 'build/[^/]+/stage'; then
30 # A local rustc build.
31 if [ -n "$MIRI_TEST_TARGET" ]; then
32 # Foreign targets still need a build. Use the rustc sources.
33 export XARGO_RUST_SRC="$SYSROOT/../../../src"
34 build_sysroot --target "$MIRI_TEST_TARGET"
36 # Assume we have a proper host libstd in $SYSROOT.
40 # We have to build a sysroot either way.
41 if [ -n "$MIRI_TEST_TARGET" ]; then
42 build_sysroot --target "$MIRI_TEST_TARGET"
56 # "--locked" to respect the Cargo.lock file if it exists,
57 # "--offline" to avoid querying the registry (for yanked packages).
58 exec cargo "$COMMAND" --path "$(dirname "$0")" --force --locked --offline "$@"
61 # Build, and let caller control flags.
62 exec cargo "$COMMAND" --release "$@"
65 # In "run" mode, scan for "--target" to set the "MIRI_TEST_TARGET" env var so
66 # that we set the MIRI_SYSROOT up the right way.
67 if [ "$COMMAND" = "run" ] && [ -z "$MIRI_TEST_TARGET" ]; then
69 if [ "$LAST_ARG" = "--target" ]; then
71 export MIRI_TEST_TARGET="$ARG"
77 # First build and get a sysroot.
80 # Then run the actual command.
81 exec cargo "$COMMAND" --release "$@"