Skip to content

Commit f2858b5

Browse files
committed
Auto merge of #100536 - Alexendoo:bootstrap-tls-model, r=Mark-Simulacrum
bootstrap: don't apply `-Ztls-model=initial-exec` to proc macros Potentially fixes #100530 r? `@bjorn3`
2 parents fb80d2b + 23abd59 commit f2858b5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/bootstrap/bin/rustc.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ use std::time::Instant;
2525

2626
fn main() {
2727
let args = env::args_os().skip(1).collect::<Vec<_>>();
28+
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
2829

2930
// Detect whether or not we're a build script depending on whether --target
3031
// is passed (a bit janky...)
31-
let target = args.windows(2).find(|w| &*w[0] == "--target").and_then(|w| w[1].to_str());
32+
let target = arg("--target");
3233
let version = args.iter().find(|w| &**w == "-vV");
3334

3435
let verbose = match env::var("RUSTC_VERBOSE") {
@@ -59,8 +60,7 @@ fn main() {
5960
cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
6061

6162
// Get the name of the crate we're compiling, if any.
62-
let crate_name =
63-
args.windows(2).find(|args| args[0] == "--crate-name").and_then(|args| args[1].to_str());
63+
let crate_name = arg("--crate-name");
6464

6565
if let Some(crate_name) = crate_name {
6666
if let Some(target) = env::var_os("RUSTC_TIME") {
@@ -106,6 +106,15 @@ fn main() {
106106
{
107107
cmd.arg("-C").arg("panic=abort");
108108
}
109+
110+
// `-Ztls-model=initial-exec` must not be applied to proc-macros, see
111+
// issue https://github.com/rust-lang/rust/issues/100530
112+
if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok()
113+
&& arg("--crate-type") != Some("proc-macro")
114+
&& !matches!(crate_name, Some("proc_macro2" | "quote" | "syn" | "synstructure"))
115+
{
116+
cmd.arg("-Ztls-model=initial-exec");
117+
}
109118
} else {
110119
// FIXME(rust-lang/cargo#5754) we shouldn't be using special env vars
111120
// here, but rather Cargo should know what flags to pass rustc itself.

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ impl<'a> Builder<'a> {
18501850
// so we can't use it by default in general, but we can use it for tools
18511851
// and our own internal libraries.
18521852
if !mode.must_support_dlopen() && !target.triple.starts_with("powerpc-") {
1853-
rustflags.arg("-Ztls-model=initial-exec");
1853+
cargo.env("RUSTC_TLS_MODEL_INITIAL_EXEC", "1");
18541854
}
18551855

18561856
if self.config.incremental {

0 commit comments

Comments
 (0)