1
1
#! /bin/sh
2
+ # # Usage
3
+ #
4
+ # COMMANDS
5
+ #
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
9
+ # working directory.
10
+ #
11
+ # ./miri build <flags>:
12
+ # Just build miri. <flags> are passed to `cargo build`.
13
+ #
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.
17
+ #
18
+ # ./miri run <flags>:
19
+ # Build miri, set up a sysroot and then run the driver with the given <flags>.
20
+ #
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.
24
+ #
25
+ # ENVIRONMENT VARIABLES
26
+ #
27
+ # MIRI_SYSROOT:
28
+ # If already set, the "sysroot setup" step is skipped.
29
+ #
30
+ # CARGO_EXTRA_FLAGS:
31
+ # Pass extra flags to all cargo invocations.
32
+
33
+ # # Preparation
2
34
set -e
3
35
# I'd love to use `jq` for parsing the JSON properly, but macOS is totally underequipped for this kind of work.
4
36
TARGET=$( rustc --print target-spec-json -Z unstable-options | grep llvm-target | cut -d ' "' -f 4)
@@ -13,9 +45,9 @@ export RUSTFLAGS="-C link-args=-Wl,-rpath,$SYSROOT/lib/rustlib/$TARGET/lib -C de
13
45
# Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
14
46
build_sysroot () {
15
47
# Build once, for the user to see.
16
- cargo run --release --bin cargo-miri -- miri setup " $@ "
48
+ cargo run $CARGO_BUILD_FLAGS --bin cargo-miri -- miri setup " $@ "
17
49
# Call again, to just set env var.
18
- eval $( cargo run --release -q --bin cargo-miri -- miri setup --env " $@ " )
50
+ eval $( cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --env " $@ " )
19
51
export MIRI_SYSROOT
20
52
}
21
53
@@ -48,23 +80,44 @@ find_sysroot() {
48
80
49
81
# # Main
50
82
83
+ # Determine command.
51
84
COMMAND=" $1 "
52
85
shift
53
86
87
+ # Determine flags passed to all cargo invocations.
54
88
case " $COMMAND " in
55
- install)
89
+ * -debug)
90
+ CARGO_INSTALL_FLAGS=" --debug $CARGO_EXTRA_FLAGS "
91
+ CARGO_BUILD_FLAGS=" $CARGO_EXTRA_FLAGS "
92
+ ;;
93
+ * )
94
+ CARGO_INSTALL_FLAGS=" $CARGO_EXTRA_FLAGS "
95
+ CARGO_BUILD_FLAGS=" --release $CARGO_EXTRA_FLAGS "
96
+ ;;
97
+ esac
98
+
99
+ # Run command.
100
+ case " $COMMAND " in
101
+ install|install-debug)
56
102
# "--locked" to respect the Cargo.lock file if it exists,
57
103
# "--offline" to avoid querying the registry (for yanked packages).
58
- exec cargo " $COMMAND " --path " $( dirname " $0 " ) " --force --locked --offline " $@ "
104
+ exec cargo install --path " $( dirname " $0 " ) " --force --locked --offline " $@ "
59
105
;;
60
- build)
106
+ build|build-debug )
61
107
# Build, and let caller control flags.
62
- exec cargo " $COMMAND " --release " $@ "
108
+ exec cargo build $CARGO_BUILD_FLAGS " $@ "
109
+ ;;
110
+ test|test-debug)
111
+ # First build and get a sysroot.
112
+ cargo build $CARGO_BUILD_FLAGS
113
+ find_sysroot
114
+ # Then test, and let caller control flags.
115
+ exec cargo test $CARGO_BUILD_FLAGS " $@ "
63
116
;;
64
- test |run)
65
- # In "run" mode, scan for "--target" to set the "MIRI_TEST_TARGET" env var so
117
+ run |run-debug )
118
+ # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
66
119
# that we set the MIRI_SYSROOT up the right way.
67
- if [ " $COMMAND " = " run " ] && [ -z " $MIRI_TEST_TARGET " ]; then
120
+ if [ -z " $MIRI_TEST_TARGET " ]; then
68
121
for ARG in " $@ " ; do
69
122
if [ " $LAST_ARG " = " --target" ]; then
70
123
# Found it!
@@ -75,9 +128,9 @@ test|run)
75
128
done
76
129
fi
77
130
# First build and get a sysroot.
78
- cargo build --release
131
+ cargo build $CARGO_BUILD_FLAGS
79
132
find_sysroot
80
133
# Then run the actual command.
81
- exec cargo " $COMMAND " --release " $@ "
134
+ exec cargo run $CARGO_BUILD_FLAGS " $@ "
82
135
;;
83
136
esac
0 commit comments