1
1
#! /bin/sh
2
2
set -e
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)
3
+ USAGE=$( cat << "EOF "
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
+ EOF
33
+ )
34
+
35
+ # # Preparation
36
+ TARGET=$( rustc --version --verbose | grep " ^host:" | cut -d ' ' -f 2)
5
37
SYSROOT=$( rustc --print sysroot)
38
+ LIBDIR=$SYSROOT /lib/rustlib/$TARGET /lib
39
+ if ! test -d " $LIBDIR " ; then
40
+ echo " Something went wrong determining the library dir."
41
+ echo " I got $LIBDIR but that does not exist."
42
+ echo " Please report a bug at https://github.com/rust-lang/miri/issues."
43
+ exit 2
44
+ fi
6
45
# We set the rpath so that Miri finds the private rustc libraries it needs.
7
46
# We enable debug-assertions to get tracing.
8
47
# 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"
48
+ export RUSTFLAGS=" -C link-args=-Wl,-rpath,$LIBDIR -C debug-assertions -C debuginfo=1"
10
49
11
50
# # Helper functions
12
51
13
52
# Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
14
53
build_sysroot () {
15
54
# Build once, for the user to see.
16
- cargo run --release --bin cargo-miri -- miri setup " $@ "
55
+ cargo run $CARGO_BUILD_FLAGS --bin cargo-miri -- miri setup " $@ "
17
56
# Call again, to just set env var.
18
- eval $( cargo run --release -q --bin cargo-miri -- miri setup --env " $@ " )
57
+ eval $( cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --env " $@ " )
19
58
export MIRI_SYSROOT
20
59
}
21
60
@@ -48,23 +87,46 @@ find_sysroot() {
48
87
49
88
# # Main
50
89
90
+ # Determine command.
51
91
COMMAND=" $1 "
52
92
shift
53
93
94
+ # Determine flags passed to all cargo invocations.
95
+ # This is a bit more annoying that one would hope due to
96
+ # <https://github.com/rust-lang/cargo/issues/6992>.
54
97
case " $COMMAND " in
55
- install)
98
+ * -debug)
99
+ CARGO_INSTALL_FLAGS=" --debug $CARGO_EXTRA_FLAGS "
100
+ CARGO_BUILD_FLAGS=" $CARGO_EXTRA_FLAGS "
101
+ ;;
102
+ * )
103
+ CARGO_INSTALL_FLAGS=" $CARGO_EXTRA_FLAGS "
104
+ CARGO_BUILD_FLAGS=" --release $CARGO_EXTRA_FLAGS "
105
+ ;;
106
+ esac
107
+
108
+ # Run command.
109
+ case " $COMMAND " in
110
+ install|install-debug)
56
111
# "--locked" to respect the Cargo.lock file if it exists,
57
112
# "--offline" to avoid querying the registry (for yanked packages).
58
- exec cargo " $COMMAND " --path " $( dirname " $0 " ) " --force --locked --offline " $@ "
113
+ exec cargo install $CARGO_INSTALL_FLAGS --path " $( dirname " $0 " ) " --force --locked --offline " $@ "
59
114
;;
60
- build)
115
+ build|build-debug )
61
116
# Build, and let caller control flags.
62
- exec cargo " $COMMAND " --release " $@ "
117
+ exec cargo build $CARGO_BUILD_FLAGS " $@ "
118
+ ;;
119
+ test|test-debug)
120
+ # First build and get a sysroot.
121
+ cargo build $CARGO_BUILD_FLAGS
122
+ find_sysroot
123
+ # Then test, and let caller control flags.
124
+ exec cargo test $CARGO_BUILD_FLAGS " $@ "
63
125
;;
64
- test |run)
65
- # In "run" mode, scan for "--target" to set the "MIRI_TEST_TARGET" env var so
126
+ run |run-debug )
127
+ # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
66
128
# that we set the MIRI_SYSROOT up the right way.
67
- if [ " $COMMAND " = " run " ] && [ -z " $MIRI_TEST_TARGET " ]; then
129
+ if [ -z " $MIRI_TEST_TARGET " ]; then
68
130
for ARG in " $@ " ; do
69
131
if [ " $LAST_ARG " = " --target" ]; then
70
132
# Found it!
@@ -75,9 +137,14 @@ test|run)
75
137
done
76
138
fi
77
139
# First build and get a sysroot.
78
- cargo build --release
140
+ cargo build $CARGO_BUILD_FLAGS
79
141
find_sysroot
80
142
# Then run the actual command.
81
- exec cargo " $COMMAND " --release " $@ "
143
+ exec cargo run $CARGO_BUILD_FLAGS " $@ "
82
144
;;
145
+ * )
146
+ echo " Unknown command: $COMMAND "
147
+ echo
148
+ echo " $USAGE "
149
+ exit 1
83
150
esac
0 commit comments