Skip to content

Commit

Permalink
avoid spurious 'Preparing a sysroot for Miri...' in 'cargo miri setup…
Browse files Browse the repository at this point in the history
… --print-sysroot'

also clean up sysroot building printing logic a bit
  • Loading branch information
RalfJung committed Jul 23, 2022
1 parent e14df05 commit b93fcd9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 18 additions & 10 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ The cargo options are exactly the same as for `cargo run` and `cargo test`, resp
Examples:
cargo miri run
cargo miri test -- test-suite-filter
cargo miri setup --print sysroot
This will print the path to the generated sysroot (and nothing else) on stdout.
stderr will still contain progress information about how the build is doing.
"#;

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

// Subcommands other than `setup` will do a setup if necessary, but
// interactively confirm first.
let ask_user = !only_setup;

// First, we need xargo.
if xargo_version().map_or(true, |v| v < XARGO_MIN_VERSION) {
if std::env::var_os("XARGO_CHECK").is_some() {
Expand Down Expand Up @@ -507,8 +510,14 @@ path = "lib.rs"
command.env("RUSTFLAGS", "-Cdebug-assertions=off -Coverflow-checks=on");
// Manage the output the user sees.
if only_setup {
// We want to be explicit.
eprintln!("Preparing a sysroot for Miri...");
if print_sysroot {
// Be extra sure there is no noise on stdout.
command.stdout(process::Stdio::null());
}
} else {
// We want to be quiet, but still let the user know that something is happening.
eprint!("Preparing a sysroot for Miri... ");
command.stdout(process::Stdio::null());
command.stderr(process::Stdio::null());
Expand All @@ -523,22 +532,21 @@ path = "lib.rs"
))
}
}
if !only_setup {
eprintln!("done");
}

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

Expand Down
3 changes: 0 additions & 3 deletions miri
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR $RUSTFLAGS"

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

Expand Down

0 comments on commit b93fcd9

Please sign in to comment.