about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/miri/CONTRIBUTING.md17
-rw-r--r--src/tools/miri/README.md6
-rw-r--r--src/tools/miri/cargo-miri/src/setup.rs12
-rwxr-xr-xsrc/tools/miri/ci.sh2
-rw-r--r--src/tools/miri/tests/compiletest.rs4
5 files changed, 22 insertions, 19 deletions
diff --git a/src/tools/miri/CONTRIBUTING.md b/src/tools/miri/CONTRIBUTING.md
index 4e50b8fae81..40a4332cdb9 100644
--- a/src/tools/miri/CONTRIBUTING.md
+++ b/src/tools/miri/CONTRIBUTING.md
@@ -71,19 +71,12 @@ and you can (cross-)run the entire test suite using:
 MIRI_TEST_TARGET=i686-unknown-linux-gnu ./miri test
 ```
 
-If your target doesn't support libstd, you can run miri with
+If your target doesn't support libstd that should usually just work. However, if you are using a
+custom target file, you might have to set `MIRI_NO_STD=1`.
 
-```
-MIRI_NO_STD=1 MIRI_TEST_TARGET=thumbv7em-none-eabihf ./miri test tests/fail/alloc/no_global_allocator.rs
-MIRI_NO_STD=1 ./miri run tests/pass/no_std.rs --target thumbv7em-none-eabihf
-```
-
-to avoid attempting (and failing) to build libstd. Note that almost no tests will pass
-this way, but you can run individual tests.
-
-`./miri test FILTER` only runs those tests that contain `FILTER` in their
-filename (including the base directory, e.g. `./miri test fail` will run all
-compile-fail tests).
+`./miri test FILTER` only runs those tests that contain `FILTER` in their filename (including the
+base directory, e.g. `./miri test fail` will run all compile-fail tests). These filters are passed
+to `cargo test`, so for multiple filers you need to use `./miri test -- FILTER1 FILTER2`.
 
 You can get a trace of which MIR statements are being executed by setting the
 `MIRI_LOG` environment variable.  For example:
diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md
index 6127eada222..ca2bb80bd26 100644
--- a/src/tools/miri/README.md
+++ b/src/tools/miri/README.md
@@ -480,8 +480,10 @@ Moreover, Miri recognizes some environment variables:
   purpose.
 * `MIRI_TEST_THREADS` (recognized by the test suite): set the number of threads to use for running tests.
   By default the number of cores is used.
-* `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_NO_STD` (recognized by `cargo miri`) makes sure that the target's sysroot is built without
+  libstd. This allows testing and running no_std programs.
+  (Miri has a heuristic to detect no-std targets based on the target name; this environment variable
+  is only needed when that heuristic fails.)
 * `RUSTC_BLESS` (recognized by the test suite and `cargo-miri-test/run-test.py`): overwrite all
   `stderr` and `stdout` files instead of checking whether the output matches.
 * `MIRI_SKIP_UI_CHECKS` (recognized by the test suite): don't check whether the
diff --git a/src/tools/miri/cargo-miri/src/setup.rs b/src/tools/miri/cargo-miri/src/setup.rs
index 77cecddcb8b..d921741d5de 100644
--- a/src/tools/miri/cargo-miri/src/setup.rs
+++ b/src/tools/miri/cargo-miri/src/setup.rs
@@ -74,7 +74,17 @@ pub fn setup(
         }
     };
     // Sysroot configuration and build details.
-    let sysroot_config = if std::env::var_os("MIRI_NO_STD").is_some() {
+    let no_std = match std::env::var_os("MIRI_NO_STD") {
+        None =>
+        // No-std heuristic taken from rust/src/bootstrap/config.rs
+        // (https://github.com/rust-lang/rust/blob/25b5af1b3a0b9e2c0c57b223b2d0e3e203869b2c/src/bootstrap/config.rs#L549-L555).
+            target.contains("-none")
+                || target.contains("nvptx")
+                || target.contains("switch")
+                || target.contains("-uefi"),
+        Some(val) => val != "0",
+    };
+    let sysroot_config = if no_std {
         SysrootConfig::NoStd
     } else {
         SysrootConfig::WithStd {
diff --git a/src/tools/miri/ci.sh b/src/tools/miri/ci.sh
index 9e7779e3513..1b3ed796c66 100755
--- a/src/tools/miri/ci.sh
+++ b/src/tools/miri/ci.sh
@@ -112,7 +112,7 @@ case $HOST_TARGET in
     MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
     MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings
     MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings
-    MIRI_TEST_TARGET=thumbv7em-none-eabihf MIRI_NO_STD=1 run_tests_minimal no_std # no_std embedded architecture
+    MIRI_TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std # no_std embedded architecture
     MIRI_TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std # JSON target file
     ;;
   x86_64-apple-darwin)
diff --git a/src/tools/miri/tests/compiletest.rs b/src/tools/miri/tests/compiletest.rs
index 035846f0ef9..c2dccf81377 100644
--- a/src/tools/miri/tests/compiletest.rs
+++ b/src/tools/miri/tests/compiletest.rs
@@ -93,9 +93,7 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
         ..Config::rustc(path)
     };
 
-    let use_std = env::var_os("MIRI_NO_STD").is_none();
-
-    if with_dependencies && use_std {
+    if with_dependencies {
         config.dependencies_crate_manifest_path =
             Some(Path::new("test_dependencies").join("Cargo.toml"));
         let mut builder_args = vec!["run".into()];