Skip to content

Commit

Permalink
bootstrap: pass crt-{static,included} for the compiler host if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
mixi committed Apr 27, 2018
1 parent 058f5b4 commit 6602e21
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ use std::process::Command;
use std::str::FromStr;
use std::time::Instant;

fn target_feature_from_env(var: &str, name: &str, target_features: &mut Vec<String>) {
if let Ok(s) = env::var(var) {
if s == "true" {
target_features.push(format!("+{}", name));
}
if s == "false" {
target_features.push(format!("-{}", name));
}
}
}

fn main() {
let mut args = env::args_os().skip(1).collect::<Vec<_>>();

Expand Down Expand Up @@ -107,6 +118,8 @@ fn main() {
env::join_paths(&dylib_path).unwrap());
let mut maybe_crate = None;

let mut target_features = Vec::new();

if let Some(target) = target {
// The stage0 compiler has a special sysroot distinct from what we
// actually downloaded, so we just always pass the `--sysroot` option.
Expand Down Expand Up @@ -235,29 +248,12 @@ fn main() {
}
}

let mut target_features = Vec::new();

if let Ok(s) = env::var("RUSTC_CRT_STATIC") {
if s == "true" {
target_features.push("+crt-static");
}
if s == "false" {
target_features.push("-crt-static");
}
}

if let Ok(s) = env::var("RUSTC_CRT_INCLUDED") {
if s == "true" {
target_features.push("+crt-included");
}
if s == "false" {
target_features.push("-crt-included");
}
}

if !target_features.is_empty() {
cmd.arg("-C").arg(format!("target-feature={}", target_features.join(",")));
}
target_feature_from_env("RUSTC_CRT_STATIC",
"crt-static",
&mut target_features);
target_feature_from_env("RUSTC_CRT_INCLUDED",
"crt-included",
&mut target_features);

// When running miri tests, we need to generate MIR for all libraries
if env::var("TEST_MIRI").ok().map_or(false, |val| val == "true") {
Expand All @@ -276,6 +272,17 @@ fn main() {
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
cmd.arg(format!("-Clinker={}", host_linker));
}

target_feature_from_env("RUSTC_HOST_CRT_STATIC",
"crt-static",
&mut target_features);
target_feature_from_env("RUSTC_HOST_CRT_INCLUDED",
"crt-included",
&mut target_features);
}

if !target_features.is_empty() {
cmd.arg("-C").arg(format!("target-feature={}", target_features.join(",")));
}

if env::var_os("RUSTC_PARALLEL_QUERIES").is_some() {
Expand Down
8 changes: 8 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,18 @@ impl<'a> Builder<'a> {
cargo.env("RUSTC_CRT_STATIC", x.to_string());
}

if let Some(x) = self.crt_static(compiler.host) {
cargo.env("RUSTC_HOST_CRT_STATIC", x.to_string());
}

if let Some(x) = self.crt_included(target) {
cargo.env("RUSTC_CRT_INCLUDED", x.to_string());
}

if let Some(x) = self.crt_included(compiler.host) {
cargo.env("RUSTC_HOST_CRT_INCLUDED", x.to_string());
}

// Enable usage of unstable features
cargo.env("RUSTC_BOOTSTRAP", "1");
self.add_rust_test_threads(&mut cargo);
Expand Down

0 comments on commit 6602e21

Please sign in to comment.