@@ -673,7 +673,7 @@ fn phase_cargo_rustc(args: env::Args) {
673
673
. expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
674
674
cmd. arg ( "--sysroot" ) . arg ( sysroot) ;
675
675
}
676
-
676
+
677
677
// ensure --emit argument for a check-only build is present
678
678
if let Some ( i) = env. args . iter ( ) . position ( |arg| arg. starts_with ( "--emit=" ) ) {
679
679
// We need to make sure we're not producing a binary that overwrites the JSON file.
@@ -690,7 +690,7 @@ fn phase_cargo_rustc(args: env::Args) {
690
690
eprintln ! ( "[cargo-miri rustc] captured input:\n {}" , std:: str :: from_utf8( & env. stdin) . unwrap( ) ) ;
691
691
eprintln ! ( "[cargo-miri rustc] {:?}" , cmd) ;
692
692
}
693
-
693
+
694
694
exec_with_pipe ( cmd, & env. stdin ) ;
695
695
}
696
696
@@ -833,11 +833,13 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
833
833
cmd. arg ( arg) ;
834
834
}
835
835
}
836
- // Set sysroot.
837
- let sysroot =
838
- env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
839
- cmd. arg ( "--sysroot" ) ;
840
- cmd. arg ( sysroot) ;
836
+ if env:: var_os ( "MIRI_CALLED_FROM_RUSTDOC" ) . is_none ( ) {
837
+ // Set sysroot.
838
+ let sysroot =
839
+ env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
840
+ cmd. arg ( "--sysroot" ) ;
841
+ cmd. arg ( sysroot) ;
842
+ }
841
843
// Respect `MIRIFLAGS`.
842
844
if let Ok ( a) = env:: var ( "MIRIFLAGS" ) {
843
845
// This code is taken from `RUSTFLAGS` handling in cargo.
@@ -884,7 +886,7 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
884
886
let extern_flag = "--extern" ;
885
887
assert ! ( fst_arg != extern_flag) ;
886
888
cmd. arg ( fst_arg) ;
887
-
889
+
888
890
let runtool_flag = "--runtool" ;
889
891
let mut crossmode = fst_arg == runtool_flag;
890
892
while let Some ( arg) = args. next ( ) {
@@ -910,21 +912,27 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
910
912
// For each doc-test, rustdoc starts two child processes: first the test is compiled,
911
913
// then the produced executable is invoked. We want to reroute both of these to cargo-miri,
912
914
// such that the first time we'll enter phase_cargo_rustc, and phase_cargo_runner second.
913
- //
915
+ //
914
916
// rustdoc invokes the test-builder by forwarding most of its own arguments, which makes
915
917
// it difficult to determine when phase_cargo_rustc should run instead of phase_cargo_rustdoc.
916
918
// Furthermore, the test code is passed via stdin, rather than a temporary file, so we need
917
919
// to let phase_cargo_rustc know to expect that. We'll use this environment variable as a flag:
918
920
cmd. env ( "MIRI_CALLED_FROM_RUSTDOC" , "1" ) ;
919
-
921
+
920
922
// The `--test-builder` and `--runtool` arguments are unstable rustdoc features,
921
923
// which are disabled by default. We first need to enable them explicitly:
922
924
cmd. arg ( "-Z" ) . arg ( "unstable-options" ) ;
923
-
925
+
926
+ // Use our custom sysroot.
927
+ let sysroot =
928
+ env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
929
+ cmd. arg ( "--sysroot" ) ;
930
+ cmd. arg ( sysroot) ;
931
+
924
932
let cargo_miri_path = std:: env:: current_exe ( ) . expect ( "current executable path invalid" ) ;
925
933
cmd. arg ( "--test-builder" ) . arg ( & cargo_miri_path) ; // invoked by forwarding most arguments
926
934
cmd. arg ( "--runtool" ) . arg ( & cargo_miri_path) ; // invoked with just a single path argument
927
-
935
+
928
936
if verbose {
929
937
eprintln ! ( "[cargo-miri rustdoc] {:?}" , cmd) ;
930
938
}
0 commit comments