Skip to content

Commit 3502a94

Browse files
committed
Fix bug in cargo miri phase related to choice 3
1 parent 08668c7 commit 3502a94

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

cargo-miri/src/phases.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
182182
cmd.arg("--target-dir").arg(target_dir);
183183

184184
eprintln!("Getting miri flags in phase_cargo_miri");
185-
cmd.args(get_miriflags());
185+
cmd.args(get_miriflags_cargo_mini());
186186
// Store many-seeds argument.
187187
let mut many_seeds = None;
188188
// *After* we set all the flags that need setting, forward everything else. Make sure to skip
@@ -644,7 +644,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
644644
}
645645
// Respect miriflags.
646646
eprintln!("Get miri flags in phase_runner");
647-
cmd.args(get_miriflags());
647+
cmd.args(get_miriflags_runner());
648648
// Set the current seed.
649649
if let Some(seed) = seed {
650650
eprintln!("Trying seed: {seed}");

cargo-miri/src/util.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,7 @@ pub fn flagsplit(flags: &str) -> Vec<String> {
9494
flags.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string).collect()
9595
}
9696

97-
pub fn get_miriflags() -> Vec<String> {
98-
// 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.
99-
// I guess we don't support the target.rustflags part yet? (That's okay but should be mentioned in a comment.)
100-
//
101-
// Fetch miri flags from cargo config.
102-
let mut cmd = cargo();
103-
cmd.args(["-Zunstable-options", "config", "get", "miri.flags", "--format=json-value"]);
104-
let output = cmd.output().expect("failed to run `cargo config`");
105-
let config_miriflags =
106-
std::str::from_utf8(&output.stdout).expect("failed to get `cargo config` output");
107-
97+
pub fn get_miriflags_cargo_mini() -> Vec<String> {
10898
// Respect `MIRIFLAGS` and `miri.flags` setting in cargo config.
10999
// If MIRIFLAGS is present, flags from cargo config are ignored.
110100
// This matches cargo behavior for RUSTFLAGS.
@@ -131,7 +121,33 @@ pub fn get_miriflags() -> Vec<String> {
131121
let miri_flags_string = miri_flags_vec.join(" ");
132122
env::set_var("CARGO_ENCODED_MIRIFLAGS", miri_flags_string);
133123
miri_flags_vec
134-
} else if let Ok(a) = env::var("MIRIFLAGS") {
124+
} else {
125+
Vec::default()
126+
}
127+
}
128+
pub fn get_miriflags_runner() -> Vec<String> {
129+
// 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.
130+
// I guess we don't support the target.rustflags part yet? (That's okay but should be mentioned in a comment.)
131+
//
132+
// Fetch miri flags from cargo config.
133+
let mut cmd = cargo();
134+
cmd.args(["-Zunstable-options", "config", "get", "miri.flags", "--format=json-value"]);
135+
let output = cmd.output().expect("failed to run `cargo config`");
136+
let config_miriflags =
137+
std::str::from_utf8(&output.stdout).expect("failed to get `cargo config` output");
138+
139+
// Respect `MIRIFLAGS` and `miri.flags` setting in cargo config.
140+
// If MIRIFLAGS is present, flags from cargo config are ignored.
141+
// This matches cargo behavior for RUSTFLAGS.
142+
//
143+
// Strategy: (1) check pseudo var CARGO_ENCODED_MIRIFLAGS first (this is only set after we check for --config
144+
// in the cargo_dash_dash in the if else)
145+
//
146+
// if CARGO_ENCODED_MIRIFLAGS doesn't exist, we check in --config (2)
147+
// if --config doesn't exist, we check offical env var MIRIFLAGS (3)
148+
//
149+
// if MIRIFLAGS is non-existent, we then check for toml (4)
150+
if let Ok(a) = env::var("MIRIFLAGS") {
135151
// (3)
136152
// This code is taken from `RUSTFLAGS` handling in cargo.
137153
eprintln!("Choice 3");

0 commit comments

Comments
 (0)