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 #![deny(warnings, rust_2018_idioms, unused_lifetimes)]
9 use std::process::Command;
10 use std::path::PathBuf;
13 let args = env::args_os().skip(1).collect::<Vec<_>>();
14 let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
15 let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
16 let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
17 let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
18 let mut has_unstable = false;
20 use std::str::FromStr;
22 let verbose = match env::var("RUSTC_VERBOSE") {
23 Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
27 let mut dylib_path = bootstrap::util::dylib_path();
28 dylib_path.insert(0, PathBuf::from(libdir.clone()));
30 //FIXME(misdreavus): once stdsimd uses cfg(rustdoc) instead of cfg(dox), remove the `--cfg dox`
32 let mut cmd = Command::new(rustdoc);
35 .arg(format!("stage{}", stage))
40 .env(bootstrap::util::dylib_path_var(),
41 env::join_paths(&dylib_path).unwrap());
43 // Force all crates compiled by this compiler to (a) be unstable and (b)
44 // allow the `rustc_private` feature to link to other unstable crates
45 // also in the sysroot.
46 if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
47 cmd.arg("-Z").arg("force-unstable-if-unmarked");
49 if let Some(linker) = env::var_os("RUSTC_TARGET_LINKER") {
50 cmd.arg("--linker").arg(linker).arg("-Z").arg("unstable-options");
53 // Bootstrap's Cargo-command builder sets this variable to the current Rust version; let's pick
54 // it up so we can make rustdoc print this into the docs
55 if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
56 // This "unstable-options" can be removed when `--crate-version` is stabilized
59 .arg("unstable-options");
61 cmd.arg("--crate-version").arg(version);
65 // Needed to be able to run all rustdoc tests.
66 if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") {
67 // This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized
70 .arg("unstable-options");
72 cmd.arg("--generate-redirect-pages");
76 // Needed to be able to run all rustdoc tests.
77 if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
78 // This "unstable-options" can be removed when `--resource-suffix` is stabilized
81 .arg("unstable-options");
83 cmd.arg("--resource-suffix").arg(x);
88 "rustdoc command: {:?}={:?} {:?}",
89 bootstrap::util::dylib_path_var(),
90 env::join_paths(&dylib_path).unwrap(),
93 eprintln!("sysroot: {:?}", sysroot);
94 eprintln!("libdir: {:?}", libdir);
97 std::process::exit(match cmd.status() {
98 Ok(s) => s.code().unwrap_or(1),
99 Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),