Skip to content

Commit ed0c6e8

Browse files
committed
miri build script: support building miri in debug mode
1 parent 3c930e4 commit ed0c6e8

File tree

1 file changed

+64
-11
lines changed

1 file changed

+64
-11
lines changed

miri

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
#!/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
234
set -e
335
# I'd love to use `jq` for parsing the JSON properly, but macOS is totally underequipped for this kind of work.
436
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
1345
# Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
1446
build_sysroot() {
1547
# 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 "$@"
1749
# 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 "$@")
1951
export MIRI_SYSROOT
2052
}
2153

@@ -48,23 +80,44 @@ find_sysroot() {
4880

4981
## Main
5082

83+
# Determine command.
5184
COMMAND="$1"
5285
shift
5386

87+
# Determine flags passed to all cargo invocations.
5488
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)
56102
# "--locked" to respect the Cargo.lock file if it exists,
57103
# "--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 "$@"
59105
;;
60-
build)
106+
build|build-debug)
61107
# 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 "$@"
63116
;;
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
66119
# 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
68121
for ARG in "$@"; do
69122
if [ "$LAST_ARG" = "--target" ]; then
70123
# Found it!
@@ -75,9 +128,9 @@ test|run)
75128
done
76129
fi
77130
# First build and get a sysroot.
78-
cargo build --release
131+
cargo build $CARGO_BUILD_FLAGS
79132
find_sysroot
80133
# Then run the actual command.
81-
exec cargo "$COMMAND" --release "$@"
134+
exec cargo run $CARGO_BUILD_FLAGS "$@"
82135
;;
83136
esac

0 commit comments

Comments
 (0)