Skip to content

Commit 7975391

Browse files
committed
Auto merge of #2402 - RalfJung:cargo-target, r=RalfJung
cargo-miri: reorder --target to after the user-defined commands This should help with #2398.
2 parents 1366bf6 + c81cfe2 commit 7975391

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
@@ -609,27 +609,12 @@ fn phase_cargo_miri(mut args: env::Args) {
609609
MiriCommand::Forward(s) => s,
610610
MiriCommand::Setup => return, // `cargo miri setup` stops here.
611611
};
612+
let metadata = get_cargo_metadata();
612613
let mut cmd = cargo();
613614
cmd.arg(cargo_cmd);
614615

615-
// Make sure we know the build target, and cargo does, too.
616-
// This is needed to make the `CARGO_TARGET_*_RUNNER` env var do something,
617-
// and it later helps us detect which crates are proc-macro/build-script
618-
// (host crates) and which crates are needed for the program itself.
619-
let host = version_info().host;
620-
let target = get_arg_flag_value("--target");
621-
let target = if let Some(ref target) = target {
622-
target
623-
} else {
624-
// No target given. Pick default and tell cargo about it.
625-
cmd.arg("--target");
626-
cmd.arg(&host);
627-
&host
628-
};
629-
630-
let mut target_dir = None;
631-
632616
// Forward all arguments before `--` other than `--target-dir` and its value to Cargo.
617+
let mut target_dir = None;
633618
for arg in ArgSplitFlagValue::new(&mut args, "--target-dir") {
634619
match arg {
635620
Ok(value) => {
@@ -643,16 +628,27 @@ fn phase_cargo_miri(mut args: env::Args) {
643628
}
644629
}
645630
}
646-
647-
let metadata = get_cargo_metadata();
648-
649631
// Detect the target directory if it's not specified via `--target-dir`.
650632
let target_dir = target_dir.get_or_insert_with(|| metadata.target_directory.clone());
651-
652633
// Set `--target-dir` to `miri` inside the original target directory.
653634
target_dir.push("miri");
654635
cmd.arg("--target-dir").arg(target_dir);
655636

637+
// Make sure we know the build target, and cargo does, too.
638+
// This is needed to make the `CARGO_TARGET_*_RUNNER` env var do something,
639+
// and it later helps us detect which crates are proc-macro/build-script
640+
// (host crates) and which crates are needed for the program itself.
641+
let host = version_info().host;
642+
let target = get_arg_flag_value("--target");
643+
let target = if let Some(ref target) = target {
644+
target
645+
} else {
646+
// No target given. Pick default and tell cargo about it.
647+
cmd.arg("--target");
648+
cmd.arg(&host);
649+
&host
650+
};
651+
656652
// Forward all further arguments after `--` to cargo.
657653
cmd.arg("--").args(args);
658654

0 commit comments

Comments
 (0)