@@ -685,7 +685,7 @@ fn phase_cargo_rustc(mut args: env::Args) {
685
685
. expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
686
686
cmd. arg ( "--sysroot" ) . arg ( sysroot) ;
687
687
}
688
-
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.
@@ -702,7 +702,7 @@ fn phase_cargo_rustc(mut args: env::Args) {
702
702
eprintln ! ( "[cargo-miri rustc] captured input:\n {}" , std:: str :: from_utf8( & env. stdin) . unwrap( ) ) ;
703
703
eprintln ! ( "[cargo-miri rustc] {:?}" , cmd) ;
704
704
}
705
-
705
+
706
706
exec_with_pipe ( cmd, & env. stdin ) ;
707
707
}
708
708
@@ -841,11 +841,13 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
841
841
cmd. arg ( arg) ;
842
842
}
843
843
}
844
- // Set sysroot.
845
- let sysroot =
846
- env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
847
- cmd. arg ( "--sysroot" ) ;
848
- cmd. arg ( sysroot) ;
844
+ 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) ;
850
+ }
849
851
// Respect `MIRIFLAGS`.
850
852
if let Ok ( a) = env:: var ( "MIRIFLAGS" ) {
851
853
// This code is taken from `RUSTFLAGS` handling in cargo.
@@ -892,7 +894,7 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
892
894
let extern_flag = "--extern" ;
893
895
assert ! ( fst_arg != extern_flag) ;
894
896
cmd. arg ( fst_arg) ;
895
-
897
+
896
898
let runtool_flag = "--runtool" ;
897
899
let mut crossmode = fst_arg == runtool_flag;
898
900
while let Some ( arg) = args. next ( ) {
@@ -917,21 +919,27 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
917
919
// For each doc-test, rustdoc starts two child processes: first the test is compiled,
918
920
// then the produced executable is invoked. We want to reroute both of these to cargo-miri,
919
921
// such that the first time we'll enter phase_cargo_rustc, and phase_cargo_runner second.
920
- //
922
+ //
921
923
// rustdoc invokes the test-builder by forwarding most of its own arguments, which makes
922
924
// it difficult to determine when phase_cargo_rustc should run instead of phase_cargo_rustdoc.
923
925
// Furthermore, the test code is passed via stdin, rather than a temporary file, so we need
924
926
// to let phase_cargo_rustc know to expect that. We'll use this environment variable as a flag:
925
927
cmd. env ( "MIRI_CALLED_FROM_RUSTDOC" , "1" ) ;
926
-
928
+
927
929
// The `--test-builder` and `--runtool` arguments are unstable rustdoc features,
928
930
// which are disabled by default. We first need to enable them explicitly:
929
931
cmd. arg ( "-Z" ) . arg ( "unstable-options" ) ;
930
-
932
+
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) ;
938
+
931
939
let cargo_miri_path = std:: env:: current_exe ( ) . expect ( "current executable path invalid" ) ;
932
940
cmd. arg ( "--test-builder" ) . arg ( & cargo_miri_path) ; // invoked by forwarding most arguments
933
941
cmd. arg ( "--runtool" ) . arg ( & cargo_miri_path) ; // invoked with just a single path argument
934
-
942
+
935
943
if verbose {
936
944
eprintln ! ( "[cargo-miri rustdoc] {:?}" , cmd) ;
937
945
}
0 commit comments