Skip to content

Commit

Permalink
Auto merge of #3000 - RalfJung:no_std, r=oli-obk
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Oct 5, 2023
2 parents f95fb21 + 73e6206 commit 0d6f605
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
17 changes: 5 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion cargo-miri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down

0 comments on commit 0d6f605

Please sign in to comment.