Skip to content

Commit 6559795

Browse files
hyd-devRalfJung
authored andcommitted
Fix sysroot for rustdoc
1 parent 9083e00 commit 6559795

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

cargo-miri/bin.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ fn phase_cargo_rustc(mut args: env::Args) {
685685
.expect("the wrapper should have set MIRI_SYSROOT");
686686
cmd.arg("--sysroot").arg(sysroot);
687687
}
688-
688+
689689
// ensure --emit argument for a check-only build is present
690690
if let Some(i) = env.args.iter().position(|arg| arg.starts_with("--emit=")) {
691691
// 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) {
702702
eprintln!("[cargo-miri rustc] captured input:\n{}", std::str::from_utf8(&env.stdin).unwrap());
703703
eprintln!("[cargo-miri rustc] {:?}", cmd);
704704
}
705-
705+
706706
exec_with_pipe(cmd, &env.stdin);
707707
}
708708

@@ -841,11 +841,13 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
841841
cmd.arg(arg);
842842
}
843843
}
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+
}
849851
// Respect `MIRIFLAGS`.
850852
if let Ok(a) = env::var("MIRIFLAGS") {
851853
// This code is taken from `RUSTFLAGS` handling in cargo.
@@ -892,7 +894,7 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
892894
let extern_flag = "--extern";
893895
assert!(fst_arg != extern_flag);
894896
cmd.arg(fst_arg);
895-
897+
896898
let runtool_flag = "--runtool";
897899
let mut crossmode = fst_arg == runtool_flag;
898900
while let Some(arg) = args.next() {
@@ -917,21 +919,27 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
917919
// For each doc-test, rustdoc starts two child processes: first the test is compiled,
918920
// then the produced executable is invoked. We want to reroute both of these to cargo-miri,
919921
// such that the first time we'll enter phase_cargo_rustc, and phase_cargo_runner second.
920-
//
922+
//
921923
// rustdoc invokes the test-builder by forwarding most of its own arguments, which makes
922924
// it difficult to determine when phase_cargo_rustc should run instead of phase_cargo_rustdoc.
923925
// Furthermore, the test code is passed via stdin, rather than a temporary file, so we need
924926
// to let phase_cargo_rustc know to expect that. We'll use this environment variable as a flag:
925927
cmd.env("MIRI_CALLED_FROM_RUSTDOC", "1");
926-
928+
927929
// The `--test-builder` and `--runtool` arguments are unstable rustdoc features,
928930
// which are disabled by default. We first need to enable them explicitly:
929931
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+
931939
let cargo_miri_path = std::env::current_exe().expect("current executable path invalid");
932940
cmd.arg("--test-builder").arg(&cargo_miri_path); // invoked by forwarding most arguments
933941
cmd.arg("--runtool").arg(&cargo_miri_path); // invoked with just a single path argument
934-
942+
935943
if verbose {
936944
eprintln!("[cargo-miri rustdoc] {:?}", cmd);
937945
}

0 commit comments

Comments
 (0)