]> git.lizzy.rs Git - rust.git/blob - miri
99ae7c5811eec5a7cf75a81c4d7496f28de4ca02
[rust.git] / miri
1 #!/bin/sh
2 set -e
3 TARGET=$(rustc --print target-spec-json -Z unstable-options | jq '.["llvm-target"]' -r)
4 SYSROOT=$(rustc --print sysroot)
5 # We set the rpath so that Miri finds the private rustc libraries it needs.
6 # We enable debug-assertions to get tracing.
7 # We enable line-only debuginfo for backtraces.
8 export RUSTFLAGS="-C link-args=-Wl,-rpath,$SYSROOT/lib/rustlib/$TARGET/lib -C debug-assertions -C debuginfo=1"
9
10 COMMAND="$1"
11 shift
12
13 case "$COMMAND" in
14 install)
15     exec cargo install --path "$(dirname "$0")" --force --locked --offline
16     ;;
17 build|test|run)
18     # Basic build
19     cargo build --release
20
21     # We we want to just build, we are done.
22     if [ "$COMMAND" = "build" ]; then exit 0; fi
23
24     # Get ourselves a sysroot
25     if [ -n "$MIRI_SYSROOT" ]; then
26         # sysroot already set
27         true
28     elif echo "$SYSROOT" | egrep -q 'build/[^/]+/stage'; then
29         # a local rustc build, assume we have a proper libstd in $SYSROOT
30         true
31     else
32         # we have to build a sysroot
33         cargo run --release --bin cargo-miri -- miri setup
34         export MIRI_SYSROOT=$HOME/.cache/miri/HOST
35     fi
36
37     exec cargo "$COMMAND" --release "$@"
38     ;;
39 esac