diff --git a/README.md b/README.md index 48bba652860..d831b4979b2 100644 --- a/README.md +++ b/README.md @@ -418,9 +418,9 @@ Moreover, Miri recognizes some environment variables: sysroot to use. Only set this if you do not want to use the automatically created sysroot. (The `miri` driver sysroot is controlled via the `--sysroot` flag instead.) -* `MIRI_TEST_TARGET` (recognized by the test suite) indicates which target - architecture to test against. `miri` and `cargo miri` accept the `--target` - flag for the same purpose. +* `MIRI_TEST_TARGET` (recognized by the test suite and the `./miri` script) indicates which target + architecture to test against. `miri` and `cargo miri` accept the `--target` flag for the same + purpose. * `MIRI_NO_STD` (recognized by `cargo miri` and the test suite) makes sure that the target's sysroot is built without libstd. This allows testing and running no_std programs. * `MIRI_BLESS` (recognized by the test suite) overwrite all `stderr` and `stdout` files diff --git a/miri b/miri index 56e3f303481..da5634d6a95 100755 --- a/miri +++ b/miri @@ -167,17 +167,21 @@ test|test-debug|bless|bless-debug) $CARGO test $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/ui_test/Cargo.toml "$@" ;; run|run-debug) - # Scan for "--target" to set the "MIRI_TEST_TARGET" env var so + # Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so # that we set the MIRI_SYSROOT up the right way. - if [ -z "$MIRI_TEST_TARGET" ]; then - for ARG in "$@"; do - if [ "$LAST_ARG" = "--target" ]; then - # Found it! - export MIRI_TEST_TARGET="$ARG" - break - fi - LAST_ARG="$ARG" - done + FOUND_TARGET_OPT=0 + for ARG in "$@"; do + if [ "$LAST_ARG" = "--target" ]; then + # Found it! + export MIRI_TEST_TARGET="$ARG" + FOUND_TARGET_OPT=1 + break + fi + LAST_ARG="$ARG" + done + if [ "$FOUND_TARGET_OPT" = "0" ] && [ -n "$MIRI_TEST_TARGET" ]; then + # Make sure Miri actually uses this target. + MIRIFLAGS="$MIRIFLAGS --target $MIRI_TEST_TARGET" fi # First build and get a sysroot. $CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml