Auto merge of #3000 - RalfJung:no_std, r=oli-obk

auto-detect no_std where possible

r? `@oli-obk`
Cc https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/restricted_std.20sysroot.3F
This commit is contained in:
bors 2023-10-05 06:07:27 +00:00
commit 6ed502d012
5 changed files with 22 additions and 19 deletions

View File

@ -71,19 +71,12 @@ and you can (cross-)run the entire test suite using:
MIRI_TEST_TARGET=i686-unknown-linux-gnu ./miri test 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 test FILTER` only runs those tests that contain `FILTER` in their filename (including the
MIRI_NO_STD=1 MIRI_TEST_TARGET=thumbv7em-none-eabihf ./miri test tests/fail/alloc/no_global_allocator.rs base directory, e.g. `./miri test fail` will run all compile-fail tests). These filters are passed
MIRI_NO_STD=1 ./miri run tests/pass/no_std.rs --target thumbv7em-none-eabihf to `cargo test`, so for multiple filers you need to use `./miri test -- FILTER1 FILTER2`.
```
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).
You can get a trace of which MIR statements are being executed by setting the You can get a trace of which MIR statements are being executed by setting the
`MIRI_LOG` environment variable. For example: `MIRI_LOG` environment variable. For example:

View File

@ -480,8 +480,10 @@ Moreover, Miri recognizes some environment variables:
purpose. purpose.
* `MIRI_TEST_THREADS` (recognized by the test suite): set the number of threads to use for running tests. * `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. 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 * `MIRI_NO_STD` (recognized by `cargo miri`) makes sure that the target's sysroot is built without
sysroot is built without libstd. This allows testing and running no_std programs. 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 * `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. `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 * `MIRI_SKIP_UI_CHECKS` (recognized by the test suite): don't check whether the

View File

@ -74,7 +74,17 @@ pub fn setup(
} }
}; };
// Sysroot configuration and build details. // 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 SysrootConfig::NoStd
} else { } else {
SysrootConfig::WithStd { SysrootConfig::WithStd {

View File

@ -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=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-wasi run_tests_minimal no_std integer strings
MIRI_TEST_TARGET=wasm32-unknown-unknown 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 MIRI_TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std # JSON target file
;; ;;
x86_64-apple-darwin) x86_64-apple-darwin)

View File

@ -93,9 +93,7 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
..Config::rustc(path) ..Config::rustc(path)
}; };
let use_std = env::var_os("MIRI_NO_STD").is_none(); if with_dependencies {
if with_dependencies && use_std {
config.dependencies_crate_manifest_path = config.dependencies_crate_manifest_path =
Some(Path::new("test_dependencies").join("Cargo.toml")); Some(Path::new("test_dependencies").join("Cargo.toml"));
let mut builder_args = vec!["run".into()]; let mut builder_args = vec!["run".into()];