Skip to content

Commit 73e6206

Browse files
committed
auto-detect no_std where possible
1 parent 114f814 commit 73e6206

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,12 @@ and you can (cross-)run the entire test suite using:
7171
MIRI_TEST_TARGET=i686-unknown-linux-gnu ./miri test
7272
```
7373

74-
If your target doesn't support libstd, you can run miri with
74+
If your target doesn't support libstd that should usually just work. However, if you are using a
75+
custom target file, you might have to set `MIRI_NO_STD=1`.
7576

76-
```
77-
MIRI_NO_STD=1 MIRI_TEST_TARGET=thumbv7em-none-eabihf ./miri test tests/fail/alloc/no_global_allocator.rs
78-
MIRI_NO_STD=1 ./miri run tests/pass/no_std.rs --target thumbv7em-none-eabihf
79-
```
80-
81-
to avoid attempting (and failing) to build libstd. Note that almost no tests will pass
82-
this way, but you can run individual tests.
83-
84-
`./miri test FILTER` only runs those tests that contain `FILTER` in their
85-
filename (including the base directory, e.g. `./miri test fail` will run all
86-
compile-fail tests).
77+
`./miri test FILTER` only runs those tests that contain `FILTER` in their filename (including the
78+
base directory, e.g. `./miri test fail` will run all compile-fail tests). These filters are passed
79+
to `cargo test`, so for multiple filers you need to use `./miri test -- FILTER1 FILTER2`.
8780

8881
You can get a trace of which MIR statements are being executed by setting the
8982
`MIRI_LOG` environment variable. For example:

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,10 @@ Moreover, Miri recognizes some environment variables:
480480
purpose.
481481
* `MIRI_TEST_THREADS` (recognized by the test suite): set the number of threads to use for running tests.
482482
By default the number of cores is used.
483-
* `MIRI_NO_STD` (recognized by `cargo miri` and the test suite) makes sure that the target's
484-
sysroot is built without libstd. This allows testing and running no_std programs.
483+
* `MIRI_NO_STD` (recognized by `cargo miri`) makes sure that the target's sysroot is built without
484+
libstd. This allows testing and running no_std programs.
485+
(Miri has a heuristic to detect no-std targets based on the target name; this environment variable
486+
is only needed when that heuristic fails.)
485487
* `RUSTC_BLESS` (recognized by the test suite and `cargo-miri-test/run-test.py`): overwrite all
486488
`stderr` and `stdout` files instead of checking whether the output matches.
487489
* `MIRI_SKIP_UI_CHECKS` (recognized by the test suite): don't check whether the

cargo-miri/src/setup.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,17 @@ pub fn setup(
7474
}
7575
};
7676
// Sysroot configuration and build details.
77-
let sysroot_config = if std::env::var_os("MIRI_NO_STD").is_some() {
77+
let no_std = match std::env::var_os("MIRI_NO_STD") {
78+
None =>
79+
// No-std heuristic taken from rust/src/bootstrap/config.rs
80+
// (https://github.com/rust-lang/rust/blob/25b5af1b3a0b9e2c0c57b223b2d0e3e203869b2c/src/bootstrap/config.rs#L549-L555).
81+
target.contains("-none")
82+
|| target.contains("nvptx")
83+
|| target.contains("switch")
84+
|| target.contains("-uefi"),
85+
Some(val) => val != "0",
86+
};
87+
let sysroot_config = if no_std {
7888
SysrootConfig::NoStd
7989
} else {
8090
SysrootConfig::WithStd {

ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ case $HOST_TARGET in
112112
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
113113
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings
114114
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings
115-
MIRI_TEST_TARGET=thumbv7em-none-eabihf MIRI_NO_STD=1 run_tests_minimal no_std # no_std embedded architecture
115+
MIRI_TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std # no_std embedded architecture
116116
MIRI_TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std # JSON target file
117117
;;
118118
x86_64-apple-darwin)

tests/compiletest.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
9393
..Config::rustc(path)
9494
};
9595

96-
let use_std = env::var_os("MIRI_NO_STD").is_none();
97-
98-
if with_dependencies && use_std {
96+
if with_dependencies {
9997
config.dependencies_crate_manifest_path =
10098
Some(Path::new("test_dependencies").join("Cargo.toml"));
10199
let mut builder_args = vec!["run".into()];

0 commit comments

Comments
 (0)