Skip to content

Commit

Permalink
Auto merge of #2402 - RalfJung:cargo-target, r=RalfJung
Browse files Browse the repository at this point in the history
cargo-miri: reorder --target to after the user-defined commands

This should help with #2398.
  • Loading branch information
bors committed Jul 20, 2022
2 parents 1366bf6 + c81cfe2 commit 7975391
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,27 +609,12 @@ fn phase_cargo_miri(mut args: env::Args) {
MiriCommand::Forward(s) => s,
MiriCommand::Setup => return, // `cargo miri setup` stops here.
};
let metadata = get_cargo_metadata();
let mut cmd = cargo();
cmd.arg(cargo_cmd);

// Make sure we know the build target, and cargo does, too.
// This is needed to make the `CARGO_TARGET_*_RUNNER` env var do something,
// and it later helps us detect which crates are proc-macro/build-script
// (host crates) and which crates are needed for the program itself.
let host = version_info().host;
let target = get_arg_flag_value("--target");
let target = if let Some(ref target) = target {
target
} else {
// No target given. Pick default and tell cargo about it.
cmd.arg("--target");
cmd.arg(&host);
&host
};

let mut target_dir = None;

// Forward all arguments before `--` other than `--target-dir` and its value to Cargo.
let mut target_dir = None;
for arg in ArgSplitFlagValue::new(&mut args, "--target-dir") {
match arg {
Ok(value) => {
Expand All @@ -643,16 +628,27 @@ fn phase_cargo_miri(mut args: env::Args) {
}
}
}

let metadata = get_cargo_metadata();

// Detect the target directory if it's not specified via `--target-dir`.
let target_dir = target_dir.get_or_insert_with(|| metadata.target_directory.clone());

// Set `--target-dir` to `miri` inside the original target directory.
target_dir.push("miri");
cmd.arg("--target-dir").arg(target_dir);

// Make sure we know the build target, and cargo does, too.
// This is needed to make the `CARGO_TARGET_*_RUNNER` env var do something,
// and it later helps us detect which crates are proc-macro/build-script
// (host crates) and which crates are needed for the program itself.
let host = version_info().host;
let target = get_arg_flag_value("--target");
let target = if let Some(ref target) = target {
target
} else {
// No target given. Pick default and tell cargo about it.
cmd.arg("--target");
cmd.arg(&host);
&host
};

// Forward all further arguments after `--` to cargo.
cmd.arg("--").args(args);

Expand Down

0 comments on commit 7975391

Please sign in to comment.