Skip to content

Commit 289a7fd

Browse files
author
hyd-dev
committed
Fix sysroot for rustdoc
1 parent 23fd3ce commit 289a7fd

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
@@ -673,7 +673,7 @@ fn phase_cargo_rustc(args: env::Args) {
673673
.expect("the wrapper should have set MIRI_SYSROOT");
674674
cmd.arg("--sysroot").arg(sysroot);
675675
}
676-
676+
677677
// ensure --emit argument for a check-only build is present
678678
if let Some(i) = env.args.iter().position(|arg| arg.starts_with("--emit=")) {
679679
// 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) {
690690
eprintln!("[cargo-miri rustc] captured input:\n{}", std::str::from_utf8(&env.stdin).unwrap());
691691
eprintln!("[cargo-miri rustc] {:?}", cmd);
692692
}
693-
693+
694694
exec_with_pipe(cmd, &env.stdin);
695695
}
696696

@@ -833,11 +833,13 @@ fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
833833
cmd.arg(arg);
834834
}
835835
}
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+
}
841843
// Respect `MIRIFLAGS`.
842844
if let Ok(a) = env::var("MIRIFLAGS") {
843845
// This code is taken from `RUSTFLAGS` handling in cargo.
@@ -884,7 +886,7 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
884886
let extern_flag = "--extern";
885887
assert!(fst_arg != extern_flag);
886888
cmd.arg(fst_arg);
887-
889+
888890
let runtool_flag = "--runtool";
889891
let mut crossmode = fst_arg == runtool_flag;
890892
while let Some(arg) = args.next() {
@@ -910,21 +912,27 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {
910912
// For each doc-test, rustdoc starts two child processes: first the test is compiled,
911913
// then the produced executable is invoked. We want to reroute both of these to cargo-miri,
912914
// such that the first time we'll enter phase_cargo_rustc, and phase_cargo_runner second.
913-
//
915+
//
914916
// rustdoc invokes the test-builder by forwarding most of its own arguments, which makes
915917
// it difficult to determine when phase_cargo_rustc should run instead of phase_cargo_rustdoc.
916918
// Furthermore, the test code is passed via stdin, rather than a temporary file, so we need
917919
// to let phase_cargo_rustc know to expect that. We'll use this environment variable as a flag:
918920
cmd.env("MIRI_CALLED_FROM_RUSTDOC", "1");
919-
921+
920922
// The `--test-builder` and `--runtool` arguments are unstable rustdoc features,
921923
// which are disabled by default. We first need to enable them explicitly:
922924
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+
924932
let cargo_miri_path = std::env::current_exe().expect("current executable path invalid");
925933
cmd.arg("--test-builder").arg(&cargo_miri_path); // invoked by forwarding most arguments
926934
cmd.arg("--runtool").arg(&cargo_miri_path); // invoked with just a single path argument
927-
935+
928936
if verbose {
929937
eprintln!("[cargo-miri rustdoc] {:?}", cmd);
930938
}

0 commit comments

Comments
 (0)