1 //! Shim which is passed to Cargo as "rustdoc" when running the bootstrap.
3 //! See comments in `src/bootstrap/rustc.rs` for more information.
6 use std::ffi::OsString;
7 use std::path::PathBuf;
8 use std::process::Command;
11 let args = env::args_os().skip(1).collect::<Vec<_>>();
12 let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
13 let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
14 let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
16 use std::str::FromStr;
18 let verbose = match env::var("RUSTC_VERBOSE") {
19 Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
23 let mut dylib_path = bootstrap::util::dylib_path();
24 dylib_path.insert(0, PathBuf::from(libdir.clone()));
26 let mut cmd = Command::new(rustdoc);
30 .env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
32 // Force all crates compiled by this compiler to (a) be unstable and (b)
33 // allow the `rustc_private` feature to link to other unstable crates
34 // also in the sysroot.
35 if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
36 cmd.arg("-Z").arg("force-unstable-if-unmarked");
38 if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
39 let mut arg = OsString::from("-Clinker=");
43 if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
44 cmd.arg("-Clink-arg=-fuse-ld=lld");
46 cmd.arg("-Clink-arg=-Wl,/threads:1");
48 cmd.arg("-Clink-arg=-Wl,--threads=1");
52 // Needed to be able to run all rustdoc tests.
53 if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
54 // This "unstable-options" can be removed when `--resource-suffix` is stabilized
55 cmd.arg("-Z").arg("unstable-options");
56 cmd.arg("--resource-suffix").arg(x);
61 "rustdoc command: {:?}={:?} {:?}",
62 bootstrap::util::dylib_path_var(),
63 env::join_paths(&dylib_path).unwrap(),
66 eprintln!("sysroot: {:?}", sysroot);
67 eprintln!("libdir: {:?}", libdir);
70 std::process::exit(match cmd.status() {
71 Ok(s) => s.code().unwrap_or(1),
72 Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),