@@ -584,27 +584,12 @@ fn phase_cargo_miri(mut args: env::Args) {
584
584
MiriCommand :: Run => "run" ,
585
585
MiriCommand :: Setup => return , // `cargo miri setup` stops here.
586
586
} ;
587
+ let metadata = get_cargo_metadata ( ) ;
587
588
let mut cmd = cargo ( ) ;
588
589
cmd. arg ( cargo_cmd) ;
589
590
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
-
607
591
// Forward all arguments before `--` other than `--target-dir` and its value to Cargo.
592
+ let mut target_dir = None ;
608
593
for arg in ArgSplitFlagValue :: new ( & mut args, "--target-dir" ) {
609
594
match arg {
610
595
Ok ( value) => {
@@ -618,16 +603,27 @@ fn phase_cargo_miri(mut args: env::Args) {
618
603
}
619
604
}
620
605
}
621
-
622
- let metadata = get_cargo_metadata ( ) ;
623
-
624
606
// Detect the target directory if it's not specified via `--target-dir`.
625
607
let target_dir = target_dir. get_or_insert_with ( || metadata. target_directory . clone ( ) ) ;
626
-
627
608
// Set `--target-dir` to `miri` inside the original target directory.
628
609
target_dir. push ( "miri" ) ;
629
610
cmd. arg ( "--target-dir" ) . arg ( target_dir) ;
630
611
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
+
631
627
// Forward all further arguments after `--` to cargo.
632
628
cmd. arg ( "--" ) . args ( args) ;
633
629
0 commit comments