Skip to content

Commit 6602e21

Browse files
committed
bootstrap: pass crt-{static,included} for the compiler host if needed
1 parent 058f5b4 commit 6602e21

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

src/bootstrap/bin/rustc.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ use std::process::Command;
3737
use std::str::FromStr;
3838
use std::time::Instant;
3939

40+
fn target_feature_from_env(var: &str, name: &str, target_features: &mut Vec<String>) {
41+
if let Ok(s) = env::var(var) {
42+
if s == "true" {
43+
target_features.push(format!("+{}", name));
44+
}
45+
if s == "false" {
46+
target_features.push(format!("-{}", name));
47+
}
48+
}
49+
}
50+
4051
fn main() {
4152
let mut args = env::args_os().skip(1).collect::<Vec<_>>();
4253

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

121+
let mut target_features = Vec::new();
122+
110123
if let Some(target) = target {
111124
// The stage0 compiler has a special sysroot distinct from what we
112125
// actually downloaded, so we just always pass the `--sysroot` option.
@@ -235,29 +248,12 @@ fn main() {
235248
}
236249
}
237250

238-
let mut target_features = Vec::new();
239-
240-
if let Ok(s) = env::var("RUSTC_CRT_STATIC") {
241-
if s == "true" {
242-
target_features.push("+crt-static");
243-
}
244-
if s == "false" {
245-
target_features.push("-crt-static");
246-
}
247-
}
248-
249-
if let Ok(s) = env::var("RUSTC_CRT_INCLUDED") {
250-
if s == "true" {
251-
target_features.push("+crt-included");
252-
}
253-
if s == "false" {
254-
target_features.push("-crt-included");
255-
}
256-
}
257-
258-
if !target_features.is_empty() {
259-
cmd.arg("-C").arg(format!("target-feature={}", target_features.join(",")));
260-
}
251+
target_feature_from_env("RUSTC_CRT_STATIC",
252+
"crt-static",
253+
&mut target_features);
254+
target_feature_from_env("RUSTC_CRT_INCLUDED",
255+
"crt-included",
256+
&mut target_features);
261257

262258
// When running miri tests, we need to generate MIR for all libraries
263259
if env::var("TEST_MIRI").ok().map_or(false, |val| val == "true") {
@@ -276,6 +272,17 @@ fn main() {
276272
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
277273
cmd.arg(format!("-Clinker={}", host_linker));
278274
}
275+
276+
target_feature_from_env("RUSTC_HOST_CRT_STATIC",
277+
"crt-static",
278+
&mut target_features);
279+
target_feature_from_env("RUSTC_HOST_CRT_INCLUDED",
280+
"crt-included",
281+
&mut target_features);
282+
}
283+
284+
if !target_features.is_empty() {
285+
cmd.arg("-C").arg(format!("target-feature={}", target_features.join(",")));
279286
}
280287

281288
if env::var_os("RUSTC_PARALLEL_QUERIES").is_some() {

src/bootstrap/builder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,18 @@ impl<'a> Builder<'a> {
663663
cargo.env("RUSTC_CRT_STATIC", x.to_string());
664664
}
665665

666+
if let Some(x) = self.crt_static(compiler.host) {
667+
cargo.env("RUSTC_HOST_CRT_STATIC", x.to_string());
668+
}
669+
666670
if let Some(x) = self.crt_included(target) {
667671
cargo.env("RUSTC_CRT_INCLUDED", x.to_string());
668672
}
669673

674+
if let Some(x) = self.crt_included(compiler.host) {
675+
cargo.env("RUSTC_HOST_CRT_INCLUDED", x.to_string());
676+
}
677+
670678
// Enable usage of unstable features
671679
cargo.env("RUSTC_BOOTSTRAP", "1");
672680
self.add_rust_test_threads(&mut cargo);

0 commit comments

Comments
 (0)