@@ -163,6 +163,13 @@ fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut
163
163
}
164
164
}
165
165
166
+ fn forward_miri_sysroot ( cmd : & mut Command ) {
167
+ let sysroot =
168
+ env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
169
+ cmd. arg ( "--sysroot" ) ;
170
+ cmd. arg ( sysroot) ;
171
+ }
172
+
166
173
/// Returns the path to the `miri` binary
167
174
fn find_miri ( ) -> PathBuf {
168
175
if let Some ( path) = env:: var_os ( "MIRI" ) {
@@ -679,13 +686,6 @@ fn phase_cargo_rustc(mut args: env::Args) {
679
686
return ;
680
687
} ;
681
688
682
- // use our own sysroot
683
- if !has_arg_flag ( "--sysroot" ) {
684
- let sysroot = env:: var_os ( "MIRI_SYSROOT" )
685
- . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
686
- cmd. arg ( "--sysroot" ) . arg ( sysroot) ;
687
- }
688
-
689
689
// ensure --emit argument for a check-only build is present
690
690
if let Some ( i) = env. args . iter ( ) . position ( |arg| arg. starts_with ( "--emit=" ) ) {
691
691
// We need to make sure we're not producing a binary that overwrites the JSON file.
@@ -750,10 +750,7 @@ fn phase_cargo_rustc(mut args: env::Args) {
750
750
}
751
751
752
752
// Use our custom sysroot.
753
- let sysroot =
754
- env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
755
- cmd. arg ( "--sysroot" ) ;
756
- cmd. arg ( sysroot) ;
753
+ forward_miri_sysroot ( & mut cmd) ;
757
754
} else {
758
755
// For host crates or when we are printing, just forward everything.
759
756
cmd. args ( args) ;
@@ -842,11 +839,8 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
842
839
}
843
840
}
844
841
if env:: var_os ( "MIRI_CALLED_FROM_RUSTDOC" ) . is_none ( ) {
845
- // Set sysroot.
846
- let sysroot =
847
- env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
848
- cmd. arg ( "--sysroot" ) ;
849
- cmd. arg ( sysroot) ;
842
+ // Set sysroot (if we are inside rustdoc, we already did that in `phase_cargo_rustdoc`).
843
+ forward_miri_sysroot ( & mut cmd) ;
850
844
}
851
845
// Respect `MIRIFLAGS`.
852
846
if let Ok ( a) = env:: var ( "MIRIFLAGS" ) {
@@ -930,12 +924,10 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
930
924
// which are disabled by default. We first need to enable them explicitly:
931
925
cmd. arg ( "-Z" ) . arg ( "unstable-options" ) ;
932
926
933
- // Use our custom sysroot.
934
- let sysroot =
935
- env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
936
- cmd. arg ( "--sysroot" ) ;
937
- cmd. arg ( sysroot) ;
927
+ // rustdoc needs to know the right sysroot.
928
+ forward_miri_sysroot ( & mut cmd) ;
938
929
930
+ // Make rustdoc call us back.
939
931
let cargo_miri_path = std:: env:: current_exe ( ) . expect ( "current executable path invalid" ) ;
940
932
cmd. arg ( "--test-builder" ) . arg ( & cargo_miri_path) ; // invoked by forwarding most arguments
941
933
cmd. arg ( "--runtool" ) . arg ( & cargo_miri_path) ; // invoked with just a single path argument
0 commit comments