From 3d13f463045417903364c44a67b0963ececde79f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Sep 2019 10:21:15 -0700 Subject: [PATCH] Move handling of `{MUSL,WASI}_ROOT` to `compile.rs` No longer any need for them to live in `rustc.rs`! --- src/bootstrap/bin/rustc.rs | 20 +------------------- src/bootstrap/builder.rs | 5 +++++ src/bootstrap/compile.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index df7ed48c186..8c460c59f07 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -16,7 +16,6 @@ //! never get replaced. use std::env; -use std::ffi::OsString; use std::io; use std::path::PathBuf; use std::process::Command; @@ -97,7 +96,7 @@ fn main() { cmd.env("RUST_BACKTRACE", "1"); } - if let Some(target) = target { + 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. @@ -112,23 +111,6 @@ fn main() { cmd.arg("-Cprefer-dynamic"); } - // Help the libc crate compile by assisting it in finding various - // sysroot native libraries. - if let Some(s) = env::var_os("MUSL_ROOT") { - if target.contains("musl") { - let mut root = OsString::from("native="); - root.push(&s); - root.push("/lib"); - cmd.arg("-L").arg(&root); - } - } - if let Some(s) = env::var_os("WASI_ROOT") { - let mut root = OsString::from("native="); - root.push(&s); - root.push("/lib/wasm32-wasi"); - cmd.arg("-L").arg(&root); - } - // 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 diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index a039f7b8c85..6a483c1fafd 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1375,6 +1375,11 @@ pub struct Cargo { } impl Cargo { + pub fn rustflag(&mut self, arg: &str) -> &mut Cargo { + self.rustflags.arg(arg); + self + } + pub fn arg(&mut self, arg: impl AsRef) -> &mut Cargo { self.command.arg(arg.as_ref()); self diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index c63856b6f6e..dc0961d16e8 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -220,15 +220,19 @@ pub fn std_cargo(builder: &Builder<'_>, .arg("--manifest-path") .arg(builder.src.join("src/libtest/Cargo.toml")); + // Help the libc crate compile by assisting it in finding various + // sysroot native libraries. if target.contains("musl") { if let Some(p) = builder.musl_root(target) { - cargo.env("MUSL_ROOT", p); + let root = format!("native={}/lib", p.to_str().unwrap()); + cargo.rustflag("-L").rustflag(&root); } } if target.ends_with("-wasi") { if let Some(p) = builder.wasi_root(target) { - cargo.env("WASI_ROOT", p); + let root = format!("native={}/lib/wasm32-wasi", p.to_str().unwrap()); + cargo.rustflag("-L").rustflag(&root); } } }