Skip to content

Commit b0b082d

Browse files
committed
do not handle MIRI_SYSROOT in the driver at all, rely fully on the --sysroot flag
1 parent 244011a commit b0b082d

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,12 @@ Several `-Z` flags are relevant for Miri:
250250

251251
Moreover, Miri recognizes some environment variables:
252252

253-
* `MIRI_SYSROOT` (recognized by `miri`, `cargo miri` and the test suite)
254-
indicates the sysroot to use.
255-
* `MIRI_TARGET` (recognized by the test suite) indicates which target
253+
* `MIRI_LOG`, `MIRI_BACKTRACE` control logging and backtrace printing during
254+
Miri executions, also [see above][testing-miri].
255+
* `MIRI_SYSROOT` (recognized by `cargo miri` and the test suite)
256+
indicates the sysroot to use. To do the same thing with `miri`
257+
directly, use the `--sysroot` flag.
258+
* `MIRI_TEST_TARGET` (recognized by the test suite) indicates which target
256259
architecture to test against. `miri` and `cargo miri` accept the `--target`
257260
flag for the same purpose.
258261

miri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ run|run-debug)
140140
cargo build $CARGO_BUILD_FLAGS
141141
find_sysroot
142142
# Then run the actual command.
143-
exec cargo run $CARGO_BUILD_FLAGS "$@"
143+
exec cargo run $CARGO_BUILD_FLAGS -- --sysroot "$MIRI_SYSROOT" "$@"
144144
;;
145145
*)
146146
echo "Unknown command: $COMMAND"

src/bin/cargo-miri.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ fn list_targets() -> impl Iterator<Item=cargo_metadata::Target> {
125125
fn test_sysroot_consistency() {
126126
fn get_sysroot(mut cmd: Command) -> PathBuf {
127127
let out = cmd.arg("--print").arg("sysroot")
128-
.env_remove("MIRI_SYSROOT") // We want to test their "native" sysroot, not the manually set one
129128
.output().expect("Failed to run rustc to get sysroot info");
130129
assert!(out.status.success(), "Bad statuc code when getting sysroot info");
131130
let sysroot = out.stdout.lines().nth(0)
@@ -298,7 +297,7 @@ path = "lib.rs"
298297
Some(target) => target == rustc_version::version_meta().unwrap().host,
299298
};
300299
let sysroot = if is_host { dir.join("HOST") } else { PathBuf::from(dir) };
301-
std::env::set_var("MIRI_SYSROOT", &sysroot);
300+
std::env::set_var("MIRI_SYSROOT", &sysroot); // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags
302301
if print_env {
303302
println!("MIRI_SYSROOT={}", sysroot.display());
304303
} else if !ask_user {
@@ -425,9 +424,9 @@ fn inside_cargo_rustc() {
425424

426425
let rustc_args = std::env::args().skip(2); // skip `cargo rustc`
427426
let mut args: Vec<String> = rustc_args
428-
.chain(Some("--sysroot".to_owned()))
429-
.chain(Some(sysroot))
430-
.collect();
427+
.chain(Some("--sysroot".to_owned()))
428+
.chain(Some(sysroot))
429+
.collect();
431430
args.splice(0..0, miri::miri_default_args().iter().map(ToString::to_string));
432431

433432
// See if we can find the `cargo-miri` markers. Those only get added to the binary we want to
@@ -458,7 +457,6 @@ fn inside_cargo_rustc() {
458457
} else {
459458
Command::new("rustc")
460459
};
461-
command.env_remove("MIRI_SYSROOT"); // we already set the --sysroot flag
462460
command.args(&args);
463461
if has_arg_flag("-v") {
464462
eprintln!("+ {:?}", command);

src/bin/miri.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,7 @@ fn main() {
165165

166166
// Determine sysroot.
167167
let sysroot_flag = "--sysroot".to_string();
168-
if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
169-
// MIRI_SYSROOT takes priority. rustc will ensure for us that this errors if there
170-
// already is a "--sysroot" flag (because now there would be two).
171-
rustc_args.push(sysroot_flag);
172-
rustc_args.push(sysroot);
173-
} else if !rustc_args.contains(&sysroot_flag) {
168+
if !rustc_args.contains(&sysroot_flag) {
174169
// We need to *always* set a --sysroot, as the "default" rustc uses is
175170
// somewhere in the directory miri was built in.
176171
// If neither MIRI_SYSROOT nor --sysroot are given, fall back to env

tests/compiletest.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ fn rustc_lib_path() -> PathBuf {
2525
option_env!("RUSTC_LIB_PATH").unwrap().into()
2626
}
2727

28-
fn mk_config(mode: &str) -> compiletest::common::ConfigWithTemp {
28+
fn run_tests(mode: &str, path: &str, target: &str, mut flags: Vec<String>) {
29+
// Some flags we always want.
30+
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
31+
flags.push("--edition 2018".to_owned());
32+
if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
33+
flags.push(format!("--sysroot {}", sysroot));
34+
}
35+
36+
// The rest of the configuration.
2937
let mut config = compiletest::Config::default().tempdir();
3038
config.mode = mode.parse().expect("Invalid mode");
3139
config.rustc_path = miri_path();
@@ -35,7 +43,10 @@ fn mk_config(mode: &str) -> compiletest::common::ConfigWithTemp {
3543
}
3644
config.filter = env::args().nth(1);
3745
config.host = get_host();
38-
config
46+
config.src_base = PathBuf::from(path);
47+
config.target = target.to_owned();
48+
config.target_rustcflags = Some(flags.join(" "));
49+
compiletest::run_tests(&config);
3950
}
4051

4152
fn compile_fail(path: &str, target: &str, opt: bool) {
@@ -48,20 +59,14 @@ fn compile_fail(path: &str, target: &str, opt: bool) {
4859
).green().bold());
4960

5061
let mut flags = Vec::new();
51-
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
52-
flags.push("--edition 2018".to_owned());
5362
if opt {
5463
// Optimizing too aggressivley makes UB detection harder, but test at least
5564
// the default value.
5665
// FIXME: Opt level 3 ICEs during stack trace generation.
5766
flags.push("-Zmir-opt-level=1".to_owned());
5867
}
5968

60-
let mut config = mk_config("compile-fail");
61-
config.src_base = PathBuf::from(path);
62-
config.target = target.to_owned();
63-
config.target_rustcflags = Some(flags.join(" "));
64-
compiletest::run_tests(&config);
69+
run_tests("compile-fail", path, target, flags);
6570
}
6671

6772
fn miri_pass(path: &str, target: &str, opt: bool) {
@@ -74,17 +79,11 @@ fn miri_pass(path: &str, target: &str, opt: bool) {
7479
).green().bold());
7580

7681
let mut flags = Vec::new();
77-
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
78-
flags.push("--edition 2018".to_owned());
7982
if opt {
8083
flags.push("-Zmir-opt-level=3".to_owned());
8184
}
8285

83-
let mut config = mk_config("ui");
84-
config.src_base = PathBuf::from(path);
85-
config.target = target.to_owned();
86-
config.target_rustcflags = Some(flags.join(" "));
87-
compiletest::run_tests(&config);
86+
run_tests("ui", path, target, flags);
8887
}
8988

9089
fn get_host() -> String {

0 commit comments

Comments
 (0)