summaryrefslogtreecommitdiffstats
path: root/src/bootstrap/bin
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/bootstrap/bin
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bootstrap/bin')
-rw-r--r--src/bootstrap/bin/llvm-config-wrapper.rs24
-rw-r--r--src/bootstrap/bin/main.rs100
-rw-r--r--src/bootstrap/bin/rustc.rs369
-rw-r--r--src/bootstrap/bin/rustdoc.rs81
-rw-r--r--src/bootstrap/bin/sccache-plus-cl.rs38
5 files changed, 612 insertions, 0 deletions
diff --git a/src/bootstrap/bin/llvm-config-wrapper.rs b/src/bootstrap/bin/llvm-config-wrapper.rs
new file mode 100644
index 000000000..89984bb55
--- /dev/null
+++ b/src/bootstrap/bin/llvm-config-wrapper.rs
@@ -0,0 +1,24 @@
+// The sheer existence of this file is an awful hack. See the comments in
+// `src/bootstrap/native.rs` for why this is needed when compiling LLD.
+
+use std::env;
+use std::io::{self, Write};
+use std::process::{self, Command, Stdio};
+
+fn main() {
+ let real_llvm_config = env::var_os("LLVM_CONFIG_REAL").unwrap();
+ let mut cmd = Command::new(real_llvm_config);
+ cmd.args(env::args().skip(1)).stderr(Stdio::piped());
+ let output = cmd.output().expect("failed to spawn llvm-config");
+ let mut stdout = String::from_utf8_lossy(&output.stdout);
+
+ if let Ok(to_replace) = env::var("LLVM_CONFIG_SHIM_REPLACE") {
+ if let Ok(replace_with) = env::var("LLVM_CONFIG_SHIM_REPLACE_WITH") {
+ stdout = stdout.replace(&to_replace, &replace_with).into();
+ }
+ }
+
+ print!("{}", stdout.replace("\\", "/"));
+ io::stdout().flush().unwrap();
+ process::exit(output.status.code().unwrap_or(1));
+}
diff --git a/src/bootstrap/bin/main.rs b/src/bootstrap/bin/main.rs
new file mode 100644
index 000000000..9b4861ccd
--- /dev/null
+++ b/src/bootstrap/bin/main.rs
@@ -0,0 +1,100 @@
+//! rustbuild, the Rust build system
+//!
+//! This is the entry point for the build system used to compile the `rustc`
+//! compiler. Lots of documentation can be found in the `README.md` file in the
+//! parent directory, and otherwise documentation can be found throughout the `build`
+//! directory in each respective module.
+
+use std::env;
+
+use bootstrap::{t, Build, Config, Subcommand, VERSION};
+
+fn main() {
+ let args = env::args().skip(1).collect::<Vec<_>>();
+ let config = Config::parse(&args);
+
+ let mut build_lock;
+ let _build_lock_guard;
+ if cfg!(any(unix, windows)) {
+ build_lock = fd_lock::RwLock::new(t!(std::fs::File::create(config.out.join("lock"))));
+ _build_lock_guard = match build_lock.try_write() {
+ Ok(lock) => lock,
+ err => {
+ println!("warning: build directory locked, waiting for lock");
+ drop(err);
+ t!(build_lock.write())
+ }
+ };
+ } else {
+ println!("warning: file locking not supported for target, not locking build directory");
+ }
+
+ // check_version warnings are not printed during setup
+ let changelog_suggestion =
+ if matches!(config.cmd, Subcommand::Setup { .. }) { None } else { check_version(&config) };
+
+ // NOTE: Since `./configure` generates a `config.toml`, distro maintainers will see the
+ // changelog warning, not the `x.py setup` message.
+ let suggest_setup = !config.config.exists() && !matches!(config.cmd, Subcommand::Setup { .. });
+ if suggest_setup {
+ println!("warning: you have not made a `config.toml`");
+ println!(
+ "help: consider running `./x.py setup` or copying `config.toml.example` by running \
+ `cp config.toml.example config.toml`"
+ );
+ } else if let Some(suggestion) = &changelog_suggestion {
+ println!("{}", suggestion);
+ }
+
+ let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
+ Build::new(config).build();
+
+ if suggest_setup {
+ println!("warning: you have not made a `config.toml`");
+ println!(
+ "help: consider running `./x.py setup` or copying `config.toml.example` by running \
+ `cp config.toml.example config.toml`"
+ );
+ } else if let Some(suggestion) = &changelog_suggestion {
+ println!("{}", suggestion);
+ }
+
+ // Give a warning if the pre-commit script is in pre-commit and not pre-push.
+ // HACK: Since the commit script uses hard links, we can't actually tell if it was installed by x.py setup or not.
+ // We could see if it's identical to src/etc/pre-push.sh, but pre-push may have been modified in the meantime.
+ // Instead, look for this comment, which is almost certainly not in any custom hook.
+ if std::fs::read_to_string(pre_commit).map_or(false, |contents| {
+ contents.contains("https://github.com/rust-lang/rust/issues/77620#issuecomment-705144570")
+ }) {
+ println!(
+ "warning: You have the pre-push script installed to .git/hooks/pre-commit. \
+ Consider moving it to .git/hooks/pre-push instead, which runs less often."
+ );
+ }
+
+ if suggest_setup || changelog_suggestion.is_some() {
+ println!("note: this message was printed twice to make it more likely to be seen");
+ }
+}
+
+fn check_version(config: &Config) -> Option<String> {
+ let mut msg = String::new();
+
+ let suggestion = if let Some(seen) = config.changelog_seen {
+ if seen != VERSION {
+ msg.push_str("warning: there have been changes to x.py since you last updated.\n");
+ format!("update `config.toml` to use `changelog-seen = {}` instead", VERSION)
+ } else {
+ return None;
+ }
+ } else {
+ msg.push_str("warning: x.py has made several changes recently you may want to look at\n");
+ format!("add `changelog-seen = {}` at the top of `config.toml`", VERSION)
+ };
+
+ msg.push_str("help: consider looking at the changes in `src/bootstrap/CHANGELOG.md`\n");
+ msg.push_str("note: to silence this warning, ");
+ msg.push_str(&suggestion);
+
+ Some(msg)
+}
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
new file mode 100644
index 000000000..40a3cc6d1
--- /dev/null
+++ b/src/bootstrap/bin/rustc.rs
@@ -0,0 +1,369 @@
+//! Shim which is passed to Cargo as "rustc" when running the bootstrap.
+//!
+//! This shim will take care of some various tasks that our build process
+//! requires that Cargo can't quite do through normal configuration:
+//!
+//! 1. When compiling build scripts and build dependencies, we need a guaranteed
+//! full standard library available. The only compiler which actually has
+//! this is the snapshot, so we detect this situation and always compile with
+//! the snapshot compiler.
+//! 2. We pass a bunch of `--cfg` and other flags based on what we're compiling
+//! (and this slightly differs based on a whether we're using a snapshot or
+//! not), so we do that all here.
+//!
+//! This may one day be replaced by RUSTFLAGS, but the dynamic nature of
+//! switching compilers for the bootstrap and for build scripts will probably
+//! never get replaced.
+
+include!("../dylib_util.rs");
+
+use std::env;
+use std::path::PathBuf;
+use std::process::{Child, Command};
+use std::str::FromStr;
+use std::time::Instant;
+
+fn main() {
+ let args = env::args_os().skip(1).collect::<Vec<_>>();
+
+ // Detect whether or not we're a build script depending on whether --target
+ // is passed (a bit janky...)
+ let target = args.windows(2).find(|w| &*w[0] == "--target").and_then(|w| w[1].to_str());
+ let version = args.iter().find(|w| &**w == "-vV");
+
+ let verbose = match env::var("RUSTC_VERBOSE") {
+ Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
+ Err(_) => 0,
+ };
+
+ // Use a different compiler for build scripts, since there may not yet be a
+ // libstd for the real compiler to use. However, if Cargo is attempting to
+ // determine the version of the compiler, the real compiler needs to be
+ // used. Currently, these two states are differentiated based on whether
+ // --target and -vV is/isn't passed.
+ let (rustc, libdir) = if target.is_none() && version.is_none() {
+ ("RUSTC_SNAPSHOT", "RUSTC_SNAPSHOT_LIBDIR")
+ } else {
+ ("RUSTC_REAL", "RUSTC_LIBDIR")
+ };
+ let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
+ let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
+ let on_fail = env::var_os("RUSTC_ON_FAIL").map(Command::new);
+
+ let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
+ let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
+ let mut dylib_path = dylib_path();
+ dylib_path.insert(0, PathBuf::from(&libdir));
+
+ let mut cmd = Command::new(rustc);
+ cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
+
+ // Get the name of the crate we're compiling, if any.
+ let crate_name =
+ args.windows(2).find(|args| args[0] == "--crate-name").and_then(|args| args[1].to_str());
+
+ if let Some(crate_name) = crate_name {
+ if let Some(target) = env::var_os("RUSTC_TIME") {
+ if target == "all"
+ || target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name)
+ {
+ cmd.arg("-Ztime");
+ }
+ }
+ }
+
+ // Print backtrace in case of ICE
+ if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() {
+ cmd.env("RUST_BACKTRACE", "1");
+ }
+
+ if let Ok(lint_flags) = env::var("RUSTC_LINT_FLAGS") {
+ cmd.args(lint_flags.split_whitespace());
+ }
+
+ if target.is_some() {
+ // The stage0 compiler has a special sysroot distinct from what we
+ // actually downloaded, so we just always pass the `--sysroot` option,
+ // unless one is already set.
+ if !args.iter().any(|arg| arg == "--sysroot") {
+ cmd.arg("--sysroot").arg(&sysroot);
+ }
+
+ // If we're compiling specifically the `panic_abort` crate then we pass
+ // the `-C panic=abort` option. Note that we do not do this for any
+ // other crate intentionally as this is the only crate for now that we
+ // ship with panic=abort.
+ //
+ // This... is a bit of a hack how we detect this. Ideally this
+ // information should be encoded in the crate I guess? Would likely
+ // require an RFC amendment to RFC 1513, however.
+ //
+ // `compiler_builtins` are unconditionally compiled with panic=abort to
+ // workaround undefined references to `rust_eh_unwind_resume` generated
+ // otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
+ if crate_name == Some("panic_abort")
+ || crate_name == Some("compiler_builtins") && stage != "0"
+ {
+ cmd.arg("-C").arg("panic=abort");
+ }
+ } else {
+ // FIXME(rust-lang/cargo#5754) we shouldn't be using special env vars
+ // here, but rather Cargo should know what flags to pass rustc itself.
+
+ // Override linker if necessary.
+ if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
+ cmd.arg(format!("-Clinker={}", host_linker));
+ }
+ if env::var_os("RUSTC_HOST_FUSE_LD_LLD").is_some() {
+ cmd.arg("-Clink-args=-fuse-ld=lld");
+ }
+
+ if let Ok(s) = env::var("RUSTC_HOST_CRT_STATIC") {
+ if s == "true" {
+ cmd.arg("-C").arg("target-feature=+crt-static");
+ }
+ if s == "false" {
+ cmd.arg("-C").arg("target-feature=-crt-static");
+ }
+ }
+
+ // Cargo doesn't pass RUSTFLAGS to proc_macros:
+ // https://github.com/rust-lang/cargo/issues/4423
+ // Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
+ // We also declare that the flag is expected, which is mainly needed for
+ // later stages so that they don't warn about #[cfg(bootstrap)],
+ // but enabling it for stage 0 too lets any warnings, if they occur,
+ // occur more early on, e.g. about #[cfg(bootstrap = "foo")].
+ if stage == "0" {
+ cmd.arg("--cfg=bootstrap");
+ }
+ cmd.arg("-Zunstable-options");
+ cmd.arg("--check-cfg=values(bootstrap)");
+ }
+
+ if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
+ cmd.arg("--remap-path-prefix").arg(&map);
+ }
+
+ // Force all crates compiled by this compiler to (a) be unstable and (b)
+ // allow the `rustc_private` feature to link to other unstable crates
+ // also in the sysroot. We also do this for host crates, since those
+ // may be proc macros, in which case we might ship them.
+ if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() && (stage != "0" || target.is_some()) {
+ cmd.arg("-Z").arg("force-unstable-if-unmarked");
+ }
+
+ if let Ok(flags) = env::var("MAGIC_EXTRA_RUSTFLAGS") {
+ for flag in flags.split(' ') {
+ cmd.arg(flag);
+ }
+ }
+
+ let is_test = args.iter().any(|a| a == "--test");
+ if verbose > 2 {
+ let rust_env_vars =
+ env::vars().filter(|(k, _)| k.starts_with("RUST") || k.starts_with("CARGO"));
+ let prefix = if is_test { "[RUSTC-SHIM] rustc --test" } else { "[RUSTC-SHIM] rustc" };
+ let prefix = match crate_name {
+ Some(crate_name) => format!("{} {}", prefix, crate_name),
+ None => prefix.to_string(),
+ };
+ for (i, (k, v)) in rust_env_vars.enumerate() {
+ eprintln!("{} env[{}]: {:?}={:?}", prefix, i, k, v);
+ }
+ eprintln!("{} working directory: {}", prefix, env::current_dir().unwrap().display());
+ eprintln!(
+ "{} command: {:?}={:?} {:?}",
+ prefix,
+ dylib_path_var(),
+ env::join_paths(&dylib_path).unwrap(),
+ cmd,
+ );
+ eprintln!("{} sysroot: {:?}", prefix, sysroot);
+ eprintln!("{} libdir: {:?}", prefix, libdir);
+ }
+
+ let start = Instant::now();
+ let (child, status) = {
+ let errmsg = format!("\nFailed to run:\n{:?}\n-------------", cmd);
+ let mut child = cmd.spawn().expect(&errmsg);
+ let status = child.wait().expect(&errmsg);
+ (child, status)
+ };
+
+ if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some()
+ || env::var_os("RUSTC_PRINT_STEP_RUSAGE").is_some()
+ {
+ if let Some(crate_name) = crate_name {
+ let dur = start.elapsed();
+ // If the user requested resource usage data, then
+ // include that in addition to the timing output.
+ let rusage_data =
+ env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data(child));
+ eprintln!(
+ "[RUSTC-TIMING] {} test:{} {}.{:03}{}{}",
+ crate_name,
+ is_test,
+ dur.as_secs(),
+ dur.subsec_millis(),
+ if rusage_data.is_some() { " " } else { "" },
+ rusage_data.unwrap_or(String::new()),
+ );
+ }
+ }
+
+ if status.success() {
+ std::process::exit(0);
+ // note: everything below here is unreachable. do not put code that
+ // should run on success, after this block.
+ }
+ if verbose > 0 {
+ println!("\nDid not run successfully: {}\n{:?}\n-------------", status, cmd);
+ }
+
+ if let Some(mut on_fail) = on_fail {
+ on_fail.status().expect("Could not run the on_fail command");
+ }
+
+ // Preserve the exit code. In case of signal, exit with 0xfe since it's
+ // awkward to preserve this status in a cross-platform way.
+ match status.code() {
+ Some(i) => std::process::exit(i),
+ None => {
+ eprintln!("rustc exited with {}", status);
+ std::process::exit(0xfe);
+ }
+ }
+}
+
+#[cfg(all(not(unix), not(windows)))]
+// In the future we can add this for more platforms
+fn format_rusage_data(_child: Child) -> Option<String> {
+ None
+}
+
+#[cfg(windows)]
+fn format_rusage_data(child: Child) -> Option<String> {
+ use std::os::windows::io::AsRawHandle;
+ use winapi::um::{processthreadsapi, psapi, timezoneapi};
+ let handle = child.as_raw_handle();
+ macro_rules! try_bool {
+ ($e:expr) => {
+ if $e != 1 {
+ return None;
+ }
+ };
+ }
+
+ let mut user_filetime = Default::default();
+ let mut user_time = Default::default();
+ let mut kernel_filetime = Default::default();
+ let mut kernel_time = Default::default();
+ let mut memory_counters = psapi::PROCESS_MEMORY_COUNTERS::default();
+
+ unsafe {
+ try_bool!(processthreadsapi::GetProcessTimes(
+ handle,
+ &mut Default::default(),
+ &mut Default::default(),
+ &mut kernel_filetime,
+ &mut user_filetime,
+ ));
+ try_bool!(timezoneapi::FileTimeToSystemTime(&user_filetime, &mut user_time));
+ try_bool!(timezoneapi::FileTimeToSystemTime(&kernel_filetime, &mut kernel_time));
+
+ // Unlike on Linux with RUSAGE_CHILDREN, this will only return memory information for the process
+ // with the given handle and none of that process's children.
+ try_bool!(psapi::GetProcessMemoryInfo(
+ handle as _,
+ &mut memory_counters as *mut _ as _,
+ std::mem::size_of::<psapi::PROCESS_MEMORY_COUNTERS_EX>() as u32,
+ ));
+ }
+
+ // Guide on interpreting these numbers:
+ // https://docs.microsoft.com/en-us/windows/win32/psapi/process-memory-usage-information
+ let peak_working_set = memory_counters.PeakWorkingSetSize / 1024;
+ let peak_page_file = memory_counters.PeakPagefileUsage / 1024;
+ let peak_paged_pool = memory_counters.QuotaPeakPagedPoolUsage / 1024;
+ let peak_nonpaged_pool = memory_counters.QuotaPeakNonPagedPoolUsage / 1024;
+ Some(format!(
+ "user: {USER_SEC}.{USER_USEC:03} \
+ sys: {SYS_SEC}.{SYS_USEC:03} \
+ peak working set (kb): {PEAK_WORKING_SET} \
+ peak page file usage (kb): {PEAK_PAGE_FILE} \
+ peak paged pool usage (kb): {PEAK_PAGED_POOL} \
+ peak non-paged pool usage (kb): {PEAK_NONPAGED_POOL} \
+ page faults: {PAGE_FAULTS}",
+ USER_SEC = user_time.wSecond + (user_time.wMinute * 60),
+ USER_USEC = user_time.wMilliseconds,
+ SYS_SEC = kernel_time.wSecond + (kernel_time.wMinute * 60),
+ SYS_USEC = kernel_time.wMilliseconds,
+ PEAK_WORKING_SET = peak_working_set,
+ PEAK_PAGE_FILE = peak_page_file,
+ PEAK_PAGED_POOL = peak_paged_pool,
+ PEAK_NONPAGED_POOL = peak_nonpaged_pool,
+ PAGE_FAULTS = memory_counters.PageFaultCount,
+ ))
+}
+
+#[cfg(unix)]
+/// Tries to build a string with human readable data for several of the rusage
+/// fields. Note that we are focusing mainly on data that we believe to be
+/// supplied on Linux (the `rusage` struct has other fields in it but they are
+/// currently unsupported by Linux).
+fn format_rusage_data(_child: Child) -> Option<String> {
+ let rusage: libc::rusage = unsafe {
+ let mut recv = std::mem::zeroed();
+ // -1 is RUSAGE_CHILDREN, which means to get the rusage for all children
+ // (and grandchildren, etc) processes that have respectively terminated
+ // and been waited for.
+ let retval = libc::getrusage(-1, &mut recv);
+ if retval != 0 {
+ return None;
+ }
+ recv
+ };
+ // Mac OS X reports the maxrss in bytes, not kb.
+ let divisor = if env::consts::OS == "macos" { 1024 } else { 1 };
+ let maxrss = (rusage.ru_maxrss + (divisor - 1)) / divisor;
+
+ let mut init_str = format!(
+ "user: {USER_SEC}.{USER_USEC:03} \
+ sys: {SYS_SEC}.{SYS_USEC:03} \
+ max rss (kb): {MAXRSS}",
+ USER_SEC = rusage.ru_utime.tv_sec,
+ USER_USEC = rusage.ru_utime.tv_usec,
+ SYS_SEC = rusage.ru_stime.tv_sec,
+ SYS_USEC = rusage.ru_stime.tv_usec,
+ MAXRSS = maxrss
+ );
+
+ // The remaining rusage stats vary in platform support. So we treat
+ // uniformly zero values in each category as "not worth printing", since it
+ // either means no events of that type occurred, or that the platform
+ // does not support it.
+
+ let minflt = rusage.ru_minflt;
+ let majflt = rusage.ru_majflt;
+ if minflt != 0 || majflt != 0 {
+ init_str.push_str(&format!(" page reclaims: {} page faults: {}", minflt, majflt));
+ }
+
+ let inblock = rusage.ru_inblock;
+ let oublock = rusage.ru_oublock;
+ if inblock != 0 || oublock != 0 {
+ init_str.push_str(&format!(" fs block inputs: {} fs block outputs: {}", inblock, oublock));
+ }
+
+ let nvcsw = rusage.ru_nvcsw;
+ let nivcsw = rusage.ru_nivcsw;
+ if nvcsw != 0 || nivcsw != 0 {
+ init_str.push_str(&format!(
+ " voluntary ctxt switches: {} involuntary ctxt switches: {}",
+ nvcsw, nivcsw
+ ));
+ }
+
+ return Some(init_str);
+}
diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs
new file mode 100644
index 000000000..87c1d22e7
--- /dev/null
+++ b/src/bootstrap/bin/rustdoc.rs
@@ -0,0 +1,81 @@
+//! Shim which is passed to Cargo as "rustdoc" when running the bootstrap.
+//!
+//! See comments in `src/bootstrap/rustc.rs` for more information.
+
+use std::env;
+use std::ffi::OsString;
+use std::path::PathBuf;
+use std::process::Command;
+
+include!("../dylib_util.rs");
+
+fn main() {
+ let args = env::args_os().skip(1).collect::<Vec<_>>();
+ let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
+ let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
+ let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
+
+ // Detect whether or not we're a build script depending on whether --target
+ // is passed (a bit janky...)
+ let target = args.windows(2).find(|w| &*w[0] == "--target").and_then(|w| w[1].to_str());
+
+ use std::str::FromStr;
+
+ let verbose = match env::var("RUSTC_VERBOSE") {
+ Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
+ Err(_) => 0,
+ };
+
+ let mut dylib_path = dylib_path();
+ dylib_path.insert(0, PathBuf::from(libdir.clone()));
+
+ let mut cmd = Command::new(rustdoc);
+
+ if target.is_some() {
+ // The stage0 compiler has a special sysroot distinct from what we
+ // actually downloaded, so we just always pass the `--sysroot` option,
+ // unless one is already set.
+ if !args.iter().any(|arg| arg == "--sysroot") {
+ cmd.arg("--sysroot").arg(&sysroot);
+ }
+ }
+
+ cmd.args(&args);
+ cmd.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
+
+ // Force all crates compiled by this compiler to (a) be unstable and (b)
+ // allow the `rustc_private` feature to link to other unstable crates
+ // also in the sysroot.
+ if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
+ cmd.arg("-Z").arg("force-unstable-if-unmarked");
+ }
+ if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
+ let mut arg = OsString::from("-Clinker=");
+ arg.push(&linker);
+ cmd.arg(arg);
+ }
+ if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
+ cmd.arg("-Clink-arg=-fuse-ld=lld");
+ if cfg!(windows) {
+ cmd.arg("-Clink-arg=-Wl,/threads:1");
+ } else {
+ cmd.arg("-Clink-arg=-Wl,--threads=1");
+ }
+ }
+
+ if verbose > 1 {
+ eprintln!(
+ "rustdoc command: {:?}={:?} {:?}",
+ dylib_path_var(),
+ env::join_paths(&dylib_path).unwrap(),
+ cmd,
+ );
+ eprintln!("sysroot: {:?}", sysroot);
+ eprintln!("libdir: {:?}", libdir);
+ }
+
+ std::process::exit(match cmd.status() {
+ Ok(s) => s.code().unwrap_or(1),
+ Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
+ })
+}
diff --git a/src/bootstrap/bin/sccache-plus-cl.rs b/src/bootstrap/bin/sccache-plus-cl.rs
new file mode 100644
index 000000000..554c2dd4d
--- /dev/null
+++ b/src/bootstrap/bin/sccache-plus-cl.rs
@@ -0,0 +1,38 @@
+use std::env;
+use std::process::{self, Command};
+
+fn main() {
+ let target = env::var("SCCACHE_TARGET").unwrap();
+ // Locate the actual compiler that we're invoking
+ env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
+ env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
+ let mut cfg = cc::Build::new();
+ cfg.cargo_metadata(false)
+ .out_dir("/")
+ .target(&target)
+ .host(&target)
+ .opt_level(0)
+ .warnings(false)
+ .debug(false);
+ let compiler = cfg.get_compiler();
+
+ // Invoke sccache with said compiler
+ let sccache_path = env::var_os("SCCACHE_PATH").unwrap();
+ let mut cmd = Command::new(&sccache_path);
+ cmd.arg(compiler.path());
+ for &(ref k, ref v) in compiler.env() {
+ cmd.env(k, v);
+ }
+ for arg in env::args().skip(1) {
+ cmd.arg(arg);
+ }
+
+ if let Ok(s) = env::var("SCCACHE_EXTRA_ARGS") {
+ for s in s.split_whitespace() {
+ cmd.arg(s);
+ }
+ }
+
+ let status = cmd.status().expect("failed to spawn");
+ process::exit(status.code().unwrap_or(2))
+}