I managed to break this in https://github.com/rust-lang/rust/pull/95449. I am not quite sure why this is the correct fix, but it doesn't break `doc --stage 0` and is strictly closer to the previous behavior. Previously, rustdoc would error with strange issues because of the mismatched sysroot: ``` error[E0460]: found possibly newer version of crate `std` which `rustc_span` depends on --> /home/jnelson/rust-lang/rust/compiler/rustc_lint_defs/src/lib.rs:14:5 | 14 | use rustc_span::{sym, symbol::Ident, Span, Symbol}; | ^^^^^^^^^^ | = note: perhaps that crate needs to be recompiled? = note: the following crate versions were found: crate `std`: /home/jnelson/rust-lang/rust/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-ff9290e971253a38.rlib crate `std`: /home/jnelson/rust-lang/rust/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-ff9290e971253a38.so crate `rustc_span`: /home/jnelson/rust-lang/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_span-ed11dce30c1766f9.rlib ```
90 lines
3.1 KiB
Rust
90 lines
3.1 KiB
Rust
//! Shim which is passed to Cargo as "rustdoc" when running the bootstrap.
|
|
//!
|
|
//! See comments in `src/bootstrap/rustc.rs` for more information.
|
|
|
|
use std::env;
|
|
use std::ffi::OsString;
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
include!("../dylib_util.rs");
|
|
|
|
fn main() {
|
|
let args = env::args_os().skip(1).collect::<Vec<_>>();
|
|
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
|
|
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
|
|
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
|
|
|
|
// Detect whether or not we're a build script depending on whether --target
|
|
// is passed (a bit janky...)
|
|
let target = args.windows(2).find(|w| &*w[0] == "--target").and_then(|w| w[1].to_str());
|
|
|
|
use std::str::FromStr;
|
|
|
|
let verbose = match env::var("RUSTC_VERBOSE") {
|
|
Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
|
|
Err(_) => 0,
|
|
};
|
|
|
|
let mut dylib_path = dylib_path();
|
|
dylib_path.insert(0, PathBuf::from(libdir.clone()));
|
|
|
|
let mut cmd = Command::new(rustdoc);
|
|
|
|
// I am not actually sure why it's necessary to pass the sysroot for `--test`,
|
|
// but `test --doc --stage 0` is broken without it :(
|
|
if target.is_some() || args.iter().any(|x| x == "--test") {
|
|
// The stage0 compiler has a special sysroot distinct from what we
|
|
// actually downloaded, so we just always pass the `--sysroot` option,
|
|
// unless one is already set.
|
|
if !args.iter().any(|arg| arg == "--sysroot") {
|
|
cmd.arg("--sysroot").arg(&sysroot);
|
|
}
|
|
}
|
|
|
|
cmd.args(&args);
|
|
cmd.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
|
|
|
|
// Force all crates compiled by this compiler to (a) be unstable and (b)
|
|
// allow the `rustc_private` feature to link to other unstable crates
|
|
// also in the sysroot.
|
|
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
|
|
cmd.arg("-Z").arg("force-unstable-if-unmarked");
|
|
}
|
|
if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
|
|
let mut arg = OsString::from("-Clinker=");
|
|
arg.push(&linker);
|
|
cmd.arg(arg);
|
|
}
|
|
if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
|
|
cmd.arg("-Clink-arg=-fuse-ld=lld");
|
|
if cfg!(windows) {
|
|
cmd.arg("-Clink-arg=-Wl,/threads:1");
|
|
} else {
|
|
cmd.arg("-Clink-arg=-Wl,--threads=1");
|
|
}
|
|
}
|
|
|
|
// Needed to be able to run all rustdoc tests.
|
|
if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
|
|
// This "unstable-options" can be removed when `--resource-suffix` is stabilized
|
|
cmd.arg("-Z").arg("unstable-options");
|
|
cmd.arg("--resource-suffix").arg(x);
|
|
}
|
|
|
|
if verbose > 1 {
|
|
eprintln!(
|
|
"rustdoc command: {:?}={:?} {:?}",
|
|
dylib_path_var(),
|
|
env::join_paths(&dylib_path).unwrap(),
|
|
cmd,
|
|
);
|
|
eprintln!("sysroot: {:?}", sysroot);
|
|
eprintln!("libdir: {:?}", libdir);
|
|
}
|
|
|
|
std::process::exit(match cmd.status() {
|
|
Ok(s) => s.code().unwrap_or(1),
|
|
Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
|
|
})
|
|
}
|