about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-21 01:34:05 +0000
committerbors <bors@rust-lang.org>2022-08-21 01:34:05 +0000
commitf2858b5cd32f3689ad83de77cacfa1ea2f533793 (patch)
tree9f25eea35cd2ad1894863b53a7c4c34f11e963fe
parentfb80d2bfe4413b2e3228dc76a792744dbc1892be (diff)
parent23abd599e73993f1ab4599f189650141a1cd313e (diff)
downloadrust-f2858b5cd32f3689ad83de77cacfa1ea2f533793.tar.gz
rust-f2858b5cd32f3689ad83de77cacfa1ea2f533793.zip
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`
-rw-r--r--src/bootstrap/bin/rustc.rs15
-rw-r--r--src/bootstrap/builder.rs2
2 files changed, 13 insertions, 4 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 40a3cc6d12c..bd5790d2ea8 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -25,10 +25,11 @@ use std::time::Instant;
 
 fn main() {
     let args = env::args_os().skip(1).collect::<Vec<_>>();
+    let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
 
     // 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 target = arg("--target");
     let version = args.iter().find(|w| &**w == "-vV");
 
     let verbose = match env::var("RUSTC_VERBOSE") {
@@ -59,8 +60,7 @@ fn main() {
     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());
+    let crate_name = arg("--crate-name");
 
     if let Some(crate_name) = crate_name {
         if let Some(target) = env::var_os("RUSTC_TIME") {
@@ -106,6 +106,15 @@ fn main() {
         {
             cmd.arg("-C").arg("panic=abort");
         }
+
+        // `-Ztls-model=initial-exec` must not be applied to proc-macros, see
+        // issue https://github.com/rust-lang/rust/issues/100530
+        if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok()
+            && arg("--crate-type") != Some("proc-macro")
+            && !matches!(crate_name, Some("proc_macro2" | "quote" | "syn" | "synstructure"))
+        {
+            cmd.arg("-Ztls-model=initial-exec");
+        }
     } 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.
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 0ab4824ac0a..945299d2dcd 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -1850,7 +1850,7 @@ impl<'a> Builder<'a> {
         // so we can't use it by default in general, but we can use it for tools
         // and our own internal libraries.
         if !mode.must_support_dlopen() && !target.triple.starts_with("powerpc-") {
-            rustflags.arg("-Ztls-model=initial-exec");
+            cargo.env("RUSTC_TLS_MODEL_INITIAL_EXEC", "1");
         }
 
         if self.config.incremental {