]> git.proxmox.com Git - rustc.git/blame - src/bootstrap/bin/rustdoc.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / src / bootstrap / bin / rustdoc.rs
CommitLineData
54a0048b
SL
1//! Shim which is passed to Cargo as "rustdoc" when running the bootstrap.
2//!
3//! See comments in `src/bootstrap/rustc.rs` for more information.
4
5use std::env;
e1599b0c 6use std::ffi::OsString;
dfeec247
XL
7use std::path::PathBuf;
8use std::process::Command;
54a0048b
SL
9
10fn main() {
11 let args = env::args_os().skip(1).collect::<Vec<_>>();
9e0c209e 12 let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
2c00a5a8 13 let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
9e0c209e 14 let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
32a655c1 15 let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
a7813a04 16
2c00a5a8
XL
17 use std::str::FromStr;
18
19 let verbose = match env::var("RUSTC_VERBOSE") {
20 Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
21 Err(_) => 0,
22 };
23
5bcae85e 24 let mut dylib_path = bootstrap::util::dylib_path();
8faf50e0 25 dylib_path.insert(0, PathBuf::from(libdir.clone()));
54a0048b 26
60c5eb7d 27 //FIXME(misdreavus): once stdsimd uses cfg(doc) instead of cfg(dox), remove the `--cfg dox`
b7449926 28 //arguments here
54a0048b
SL
29 let mut cmd = Command::new(rustdoc);
30 cmd.args(&args)
c30ab7b3
SL
31 .arg("--cfg")
32 .arg(format!("stage{}", stage))
33 .arg("--cfg")
34 .arg("dox")
32a655c1 35 .arg("--sysroot")
532ac7d7 36 .arg(&sysroot)
dfeec247 37 .env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
cc61c64b 38
041b39d2
XL
39 // Force all crates compiled by this compiler to (a) be unstable and (b)
40 // allow the `rustc_private` feature to link to other unstable crates
41 // also in the sysroot.
42 if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
43 cmd.arg("-Z").arg("force-unstable-if-unmarked");
cc61c64b 44 }
abe05a73 45 if let Some(linker) = env::var_os("RUSTC_TARGET_LINKER") {
e1599b0c
XL
46 let mut arg = OsString::from("-Clinker=");
47 arg.push(&linker);
48 cmd.arg(arg);
abe05a73
XL
49 }
50
51 // Bootstrap's Cargo-command builder sets this variable to the current Rust version; let's pick
52 // it up so we can make rustdoc print this into the docs
53 if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
9fa01778 54 cmd.arg("--crate-version").arg(version);
9fa01778
XL
55 }
56
9fa01778
XL
57 // Needed to be able to run all rustdoc tests.
58 if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
59 // This "unstable-options" can be removed when `--resource-suffix` is stabilized
f035d41b 60 cmd.arg("-Z").arg("unstable-options");
9fa01778 61 cmd.arg("--resource-suffix").arg(x);
abe05a73 62 }
cc61c64b 63
2c00a5a8 64 if verbose > 1 {
532ac7d7
XL
65 eprintln!(
66 "rustdoc command: {:?}={:?} {:?}",
67 bootstrap::util::dylib_path_var(),
68 env::join_paths(&dylib_path).unwrap(),
69 cmd,
70 );
71 eprintln!("sysroot: {:?}", sysroot);
8faf50e0 72 eprintln!("libdir: {:?}", libdir);
2c00a5a8
XL
73 }
74
54a0048b
SL
75 std::process::exit(match cmd.status() {
76 Ok(s) => s.code().unwrap_or(1),
77 Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
78 })
79}