]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/bin/rustdoc.rs
Add 'compiler/rustc_smir/' from commit '9abcb5c7b574cf316eb23d3f469187bb86ba3019'
[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     // Detect whether or not we're a build script depending on whether --target
19     // is passed (a bit janky...)
20     let target = args.windows(2).find(|w| &*w[0] == "--target").and_then(|w| w[1].to_str());
21
22     use std::str::FromStr;
23
24     let verbose = match env::var("RUSTC_VERBOSE") {
25         Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
26         Err(_) => 0,
27     };
28
29     let mut dylib_path = dylib_path();
30     dylib_path.insert(0, PathBuf::from(libdir.clone()));
31
32     let mut cmd = Command::new(rustdoc);
33
34     // cfg(bootstrap)
35     // NOTE: the `--test` special-casing can be removed when https://github.com/rust-lang/cargo/pull/10594 lands on beta.
36     if target.is_some() || args.iter().any(|x| x == "--test") {
37         // The stage0 compiler has a special sysroot distinct from what we
38         // actually downloaded, so we just always pass the `--sysroot` option,
39         // unless one is already set.
40         if !args.iter().any(|arg| arg == "--sysroot") {
41             cmd.arg("--sysroot").arg(&sysroot);
42         }
43     }
44
45     cmd.args(&args);
46     cmd.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
47
48     // Force all crates compiled by this compiler to (a) be unstable and (b)
49     // allow the `rustc_private` feature to link to other unstable crates
50     // also in the sysroot.
51     if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
52         cmd.arg("-Z").arg("force-unstable-if-unmarked");
53     }
54     if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
55         let mut arg = OsString::from("-Clinker=");
56         arg.push(&linker);
57         cmd.arg(arg);
58     }
59     if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
60         cmd.arg("-Clink-arg=-fuse-ld=lld");
61         if cfg!(windows) {
62             cmd.arg("-Clink-arg=-Wl,/threads:1");
63         } else {
64             cmd.arg("-Clink-arg=-Wl,--threads=1");
65         }
66     }
67
68     if verbose > 1 {
69         eprintln!(
70             "rustdoc command: {:?}={:?} {:?}",
71             dylib_path_var(),
72             env::join_paths(&dylib_path).unwrap(),
73             cmd,
74         );
75         eprintln!("sysroot: {:?}", sysroot);
76         eprintln!("libdir: {:?}", libdir);
77     }
78
79     std::process::exit(match cmd.status() {
80         Ok(s) => s.code().unwrap_or(1),
81         Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
82     })
83 }