Skip to content

Commit

Permalink
Fix bug in cargo miri phase related to choice 3
Browse files Browse the repository at this point in the history
  • Loading branch information
badumbatish committed Sep 10, 2024
1 parent 08668c7 commit 3502a94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
cmd.arg("--target-dir").arg(target_dir);

eprintln!("Getting miri flags in phase_cargo_miri");
cmd.args(get_miriflags());
cmd.args(get_miriflags_cargo_mini());
// Store many-seeds argument.
let mut many_seeds = None;
// *After* we set all the flags that need setting, forward everything else. Make sure to skip
Expand Down Expand Up @@ -644,7 +644,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
}
// Respect miriflags.
eprintln!("Get miri flags in phase_runner");
cmd.args(get_miriflags());
cmd.args(get_miriflags_runner());
// Set the current seed.
if let Some(seed) = seed {
eprintln!("Trying seed: {seed}");
Expand Down
40 changes: 28 additions & 12 deletions cargo-miri/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,7 @@ pub fn flagsplit(flags: &str) -> Vec<String> {
flags.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string).collect()
}

pub fn get_miriflags() -> Vec<String> {
// TODO: I quite not understand what Carl Jung means by Oh and please add a link to https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags.
// I guess we don't support the target.rustflags part yet? (That's okay but should be mentioned in a comment.)
//
// Fetch miri flags from cargo config.
let mut cmd = cargo();
cmd.args(["-Zunstable-options", "config", "get", "miri.flags", "--format=json-value"]);
let output = cmd.output().expect("failed to run `cargo config`");
let config_miriflags =
std::str::from_utf8(&output.stdout).expect("failed to get `cargo config` output");

pub fn get_miriflags_cargo_mini() -> Vec<String> {
// Respect `MIRIFLAGS` and `miri.flags` setting in cargo config.
// If MIRIFLAGS is present, flags from cargo config are ignored.
// This matches cargo behavior for RUSTFLAGS.
Expand All @@ -131,7 +121,33 @@ pub fn get_miriflags() -> Vec<String> {
let miri_flags_string = miri_flags_vec.join(" ");
env::set_var("CARGO_ENCODED_MIRIFLAGS", miri_flags_string);
miri_flags_vec
} else if let Ok(a) = env::var("MIRIFLAGS") {
} else {
Vec::default()
}
}
pub fn get_miriflags_runner() -> Vec<String> {
// TODO: I quite not understand what Carl Jung means by Oh and please add a link to https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags.
// I guess we don't support the target.rustflags part yet? (That's okay but should be mentioned in a comment.)
//
// Fetch miri flags from cargo config.
let mut cmd = cargo();
cmd.args(["-Zunstable-options", "config", "get", "miri.flags", "--format=json-value"]);
let output = cmd.output().expect("failed to run `cargo config`");
let config_miriflags =
std::str::from_utf8(&output.stdout).expect("failed to get `cargo config` output");

// Respect `MIRIFLAGS` and `miri.flags` setting in cargo config.
// If MIRIFLAGS is present, flags from cargo config are ignored.
// This matches cargo behavior for RUSTFLAGS.
//
// Strategy: (1) check pseudo var CARGO_ENCODED_MIRIFLAGS first (this is only set after we check for --config
// in the cargo_dash_dash in the if else)
//
// if CARGO_ENCODED_MIRIFLAGS doesn't exist, we check in --config (2)
// if --config doesn't exist, we check offical env var MIRIFLAGS (3)
//
// if MIRIFLAGS is non-existent, we then check for toml (4)
if let Ok(a) = env::var("MIRIFLAGS") {
// (3)
// This code is taken from `RUSTFLAGS` handling in cargo.
eprintln!("Choice 3");
Expand Down

0 comments on commit 3502a94

Please sign in to comment.