@@ -609,27 +609,12 @@ fn phase_cargo_miri(mut args: env::Args) {
609
609
MiriCommand :: Forward ( s) => s,
610
610
MiriCommand :: Setup => return , // `cargo miri setup` stops here.
611
611
} ;
612
+ let metadata = get_cargo_metadata ( ) ;
612
613
let mut cmd = cargo ( ) ;
613
614
cmd. arg ( cargo_cmd) ;
614
615
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
-
632
616
// Forward all arguments before `--` other than `--target-dir` and its value to Cargo.
617
+ let mut target_dir = None ;
633
618
for arg in ArgSplitFlagValue :: new ( & mut args, "--target-dir" ) {
634
619
match arg {
635
620
Ok ( value) => {
@@ -643,16 +628,27 @@ fn phase_cargo_miri(mut args: env::Args) {
643
628
}
644
629
}
645
630
}
646
-
647
- let metadata = get_cargo_metadata ( ) ;
648
-
649
631
// Detect the target directory if it's not specified via `--target-dir`.
650
632
let target_dir = target_dir. get_or_insert_with ( || metadata. target_directory . clone ( ) ) ;
651
-
652
633
// Set `--target-dir` to `miri` inside the original target directory.
653
634
target_dir. push ( "miri" ) ;
654
635
cmd. arg ( "--target-dir" ) . arg ( target_dir) ;
655
636
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
+
656
652
// Forward all further arguments after `--` to cargo.
657
653
cmd. arg ( "--" ) . args ( args) ;
658
654
0 commit comments