]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/bin/rustdoc.rs
Rollup merge of #95401 - c410-f3r:moar-tests, r=petrochenkov
[rust.git] / src / bootstrap / bin / rustdoc.rs
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
5 use std::env;
6 use std::ffi::OsString;
7 use std::path::PathBuf;
8 use std::process::Command;
9
10 include!("../dylib_util.rs");
11
12 fn main() {
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 sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
17
18     use std::str::FromStr;
19
20     let verbose = match env::var("RUSTC_VERBOSE") {
21         Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
22         Err(_) => 0,
23     };
24
25     let mut dylib_path = dylib_path();
26     dylib_path.insert(0, PathBuf::from(libdir.clone()));
27
28     let mut cmd = Command::new(rustdoc);
29     cmd.args(&args)
30         .arg("--sysroot")
31         .arg(&sysroot)
32         .env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
33
34     // Force all crates compiled by this compiler to (a) be unstable and (b)
35     // allow the `rustc_private` feature to link to other unstable crates
36     // also in the sysroot.
37     if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
38         cmd.arg("-Z").arg("force-unstable-if-unmarked");
39     }
40     if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
41         let mut arg = OsString::from("-Clinker=");
42         arg.push(&linker);
43         cmd.arg(arg);
44     }
45     if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
46         cmd.arg("-Clink-arg=-fuse-ld=lld");
47         if cfg!(windows) {
48             cmd.arg("-Clink-arg=-Wl,/threads:1");
49         } else {
50             cmd.arg("-Clink-arg=-Wl,--threads=1");
51         }
52     }
53
54     // Needed to be able to run all rustdoc tests.
55     if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
56         // This "unstable-options" can be removed when `--resource-suffix` is stabilized
57         cmd.arg("-Z").arg("unstable-options");
58         cmd.arg("--resource-suffix").arg(x);
59     }
60
61     if verbose > 1 {
62         eprintln!(
63             "rustdoc command: {:?}={:?} {:?}",
64             dylib_path_var(),
65             env::join_paths(&dylib_path).unwrap(),
66             cmd,
67         );
68         eprintln!("sysroot: {:?}", sysroot);
69         eprintln!("libdir: {:?}", libdir);
70     }
71
72     std::process::exit(match cmd.status() {
73         Ok(s) => s.code().unwrap_or(1),
74         Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
75     })
76 }