]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/bin/rustdoc.rs
build doctests with lld if use-lld = true
[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 fn main() {
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");
15
16     use std::str::FromStr;
17
18     let verbose = match env::var("RUSTC_VERBOSE") {
19         Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
20         Err(_) => 0,
21     };
22
23     let mut dylib_path = bootstrap::util::dylib_path();
24     dylib_path.insert(0, PathBuf::from(libdir.clone()));
25
26     let mut cmd = Command::new(rustdoc);
27     cmd.args(&args)
28         .arg("--sysroot")
29         .arg(&sysroot)
30         .env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
31
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");
37     }
38     if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
39         let mut arg = OsString::from("-Clinker=");
40         arg.push(&linker);
41         cmd.arg(arg);
42     }
43     if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
44         cmd.arg("-Clink-arg=-fuse-ld=lld");
45         if cfg!(windows) {
46             cmd.arg("-Clink-arg=-Wl,/threads:1");
47         } else {
48             cmd.arg("-Clink-arg=-Wl,--threads=1");
49         }
50     }
51
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);
57     }
58
59     if verbose > 1 {
60         eprintln!(
61             "rustdoc command: {:?}={:?} {:?}",
62             bootstrap::util::dylib_path_var(),
63             env::join_paths(&dylib_path).unwrap(),
64             cmd,
65         );
66         eprintln!("sysroot: {:?}", sysroot);
67         eprintln!("libdir: {:?}", libdir);
68     }
69
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),
73     })
74 }