Skip to content

Commit c81cfe2

Browse files
committed
cargo-miri: reorder --target to after the user-defined commands
1 parent b9c6771 commit c81cfe2

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

cargo-miri/bin.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -584,27 +584,12 @@ fn phase_cargo_miri(mut args: env::Args) {
584584
MiriCommand::Run => "run",
585585
MiriCommand::Setup => return, // `cargo miri setup` stops here.
586586
};
587+
let metadata = get_cargo_metadata();
587588
let mut cmd = cargo();
588589
cmd.arg(cargo_cmd);
589590

590-
// Make sure we know the build target, and cargo does, too.
591-
// This is needed to make the `CARGO_TARGET_*_RUNNER` env var do something,
592-
// and it later helps us detect which crates are proc-macro/build-script
593-
// (host crates) and which crates are needed for the program itself.
594-
let host = version_info().host;
595-
let target = get_arg_flag_value("--target");
596-
let target = if let Some(ref target) = target {
597-
target
598-
} else {
599-
// No target given. Pick default and tell cargo about it.
600-
cmd.arg("--target");
601-
cmd.arg(&host);
602-
&host
603-
};
604-
605-
let mut target_dir = None;
606-
607591
// Forward all arguments before `--` other than `--target-dir` and its value to Cargo.
592+
let mut target_dir = None;
608593
for arg in ArgSplitFlagValue::new(&mut args, "--target-dir") {
609594
match arg {
610595
Ok(value) => {
@@ -618,16 +603,27 @@ fn phase_cargo_miri(mut args: env::Args) {
618603
}
619604
}
620605
}
621-
622-
let metadata = get_cargo_metadata();
623-
624606
// Detect the target directory if it's not specified via `--target-dir`.
625607
let target_dir = target_dir.get_or_insert_with(|| metadata.target_directory.clone());
626-
627608
// Set `--target-dir` to `miri` inside the original target directory.
628609
target_dir.push("miri");
629610
cmd.arg("--target-dir").arg(target_dir);
630611

612+
// Make sure we know the build target, and cargo does, too.
613+
// This is needed to make the `CARGO_TARGET_*_RUNNER` env var do something,
614+
// and it later helps us detect which crates are proc-macro/build-script
615+
// (host crates) and which crates are needed for the program itself.
616+
let host = version_info().host;
617+
let target = get_arg_flag_value("--target");
618+
let target = if let Some(ref target) = target {
619+
target
620+
} else {
621+
// No target given. Pick default and tell cargo about it.
622+
cmd.arg("--target");
623+
cmd.arg(&host);
624+
&host
625+
};
626+
631627
// Forward all further arguments after `--` to cargo.
632628
cmd.arg("--").args(args);
633629

0 commit comments

Comments
 (0)