Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b93fcd9

Browse files
committed
avoid spurious 'Preparing a sysroot for Miri...' in 'cargo miri setup --print-sysroot'
also clean up sysroot building printing logic a bit
1 parent e14df05 commit b93fcd9

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

cargo-miri/bin.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ The cargo options are exactly the same as for `cargo run` and `cargo test`, resp
3535
Examples:
3636
cargo miri run
3737
cargo miri test -- test-suite-filter
38+
39+
cargo miri setup --print sysroot
40+
This will print the path to the generated sysroot (and nothing else) on stdout.
41+
stderr will still contain progress information about how the build is doing.
42+
3843
"#;
3944

4045
#[derive(Clone, Debug)]
@@ -361,17 +366,15 @@ fn write_to_file(filename: &Path, content: &str) {
361366
/// done all this already.
362367
fn setup(subcommand: &MiriCommand) {
363368
let only_setup = matches!(subcommand, MiriCommand::Setup);
369+
let ask_user = !only_setup;
370+
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
364371
if std::env::var_os("MIRI_SYSROOT").is_some() {
365372
if only_setup {
366373
println!("WARNING: MIRI_SYSROOT already set, not doing anything.")
367374
}
368375
return;
369376
}
370377

371-
// Subcommands other than `setup` will do a setup if necessary, but
372-
// interactively confirm first.
373-
let ask_user = !only_setup;
374-
375378
// First, we need xargo.
376379
if xargo_version().map_or(true, |v| v < XARGO_MIN_VERSION) {
377380
if std::env::var_os("XARGO_CHECK").is_some() {
@@ -507,8 +510,14 @@ path = "lib.rs"
507510
command.env("RUSTFLAGS", "-Cdebug-assertions=off -Coverflow-checks=on");
508511
// Manage the output the user sees.
509512
if only_setup {
513+
// We want to be explicit.
510514
eprintln!("Preparing a sysroot for Miri...");
515+
if print_sysroot {
516+
// Be extra sure there is no noise on stdout.
517+
command.stdout(process::Stdio::null());
518+
}
511519
} else {
520+
// We want to be quiet, but still let the user know that something is happening.
512521
eprint!("Preparing a sysroot for Miri... ");
513522
command.stdout(process::Stdio::null());
514523
command.stderr(process::Stdio::null());
@@ -523,22 +532,21 @@ path = "lib.rs"
523532
))
524533
}
525534
}
526-
if !only_setup {
527-
eprintln!("done");
528-
}
529535

530536
// That should be it! But we need to figure out where xargo built stuff.
531537
// Unfortunately, it puts things into a different directory when the
532538
// architecture matches the host.
533539
let sysroot = if target == &host { dir.join("HOST") } else { PathBuf::from(dir) };
534540
std::env::set_var("MIRI_SYSROOT", &sysroot); // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags
535541
// Figure out what to print.
536-
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
542+
if only_setup {
543+
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot.display());
544+
} else {
545+
eprintln!("done");
546+
}
537547
if print_sysroot {
538548
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
539549
println!("{}", sysroot.display());
540-
} else if only_setup {
541-
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot.display());
542550
}
543551
}
544552

miri

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR $RUSTFLAGS"
131131

132132
# Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
133133
build_sysroot() {
134-
# Build once, for the user to see.
135-
$CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -- miri setup "$@"
136-
# Call again, to just set env var.
137134
export MIRI_SYSROOT="$($CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -q -- miri setup --print-sysroot "$@")"
138135
}
139136

0 commit comments

Comments
 (0)