about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Paoliello <danpao@microsoft.com>2022-06-23 13:05:42 -0700
committerDaniel Paoliello <danpao@microsoft.com>2022-06-27 11:46:57 -0700
commit1fca2468420bb5ac2f6868bddc65e164dd05dbfb (patch)
tree3f837af8e171839ebc38fd4842fcc5587848eaef
parent10f4ce324baf7cfb7ce2b2096662b82b79204944 (diff)
downloadrust-1fca2468420bb5ac2f6868bddc65e164dd05dbfb.tar.gz
rust-1fca2468420bb5ac2f6868bddc65e164dd05dbfb.zip
Ensure that `static_crt` is set in the bootstrapper whenever using `cc` to get a compiler command line.
When attempting to build rustc with LLVM on Windows, I noticed that the CRT flag provided to the C and C++ Compilers was inconsistent:

```
"-DCMAKE_C_FLAGS=-nologo -MT -Brepro" "-DCMAKE_CXX_FLAGS=-nologo -MD -Brepro"
```

Since the bootstrapper also sets the various `LLVM_USE_CRT` variables, this resulted in cl.exe reporting a bunch of warnings:

```
cl : Command line warning D9025 : overriding '/MD' with '/MT'
```

The root cause for this is that `cc_detect::find` was creating a `cc::Build` twice, but didn't set `static_crt` the second time.

It's possible that this what is also causing #81381
-rw-r--r--src/bootstrap/cc_detect.rs57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs
index dca782c29c2..759a99c330c 100644
--- a/src/bootstrap/cc_detect.rs
+++ b/src/bootstrap/cc_detect.rs
@@ -61,6 +61,30 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
     }
 }
 
+fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
+    let mut cfg = cc::Build::new();
+    cfg.cargo_metadata(false)
+        .opt_level(2)
+        .warnings(false)
+        .debug(false)
+        .target(&target.triple)
+        .host(&build.build.triple);
+    match build.crt_static(target) {
+        Some(a) => {
+            cfg.static_crt(a);
+        }
+        None => {
+            if target.contains("msvc") {
+                cfg.static_crt(true);
+            }
+            if target.contains("musl") {
+                cfg.static_flag(true);
+            }
+        }
+    }
+    cfg
+}
+
 pub fn find(build: &mut Build) {
     // For all targets we're going to need a C compiler for building some shims
     // and such as well as for being a linker for Rust code.
@@ -72,27 +96,7 @@ pub fn find(build: &mut Build) {
         .chain(iter::once(build.build))
         .collect::<HashSet<_>>();
     for target in targets.into_iter() {
-        let mut cfg = cc::Build::new();
-        cfg.cargo_metadata(false)
-            .opt_level(2)
-            .warnings(false)
-            .debug(false)
-            .target(&target.triple)
-            .host(&build.build.triple);
-        match build.crt_static(target) {
-            Some(a) => {
-                cfg.static_crt(a);
-            }
-            None => {
-                if target.contains("msvc") {
-                    cfg.static_crt(true);
-                }
-                if target.contains("musl") {
-                    cfg.static_flag(true);
-                }
-            }
-        }
-
+        let mut cfg = new_cc_build(build, target);
         let config = build.config.target_config.get(&target);
         if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
             cfg.compiler(cc);
@@ -112,15 +116,8 @@ pub fn find(build: &mut Build) {
 
         // If we use llvm-libunwind, we will need a C++ compiler as well for all targets
         // We'll need one anyways if the target triple is also a host triple
-        let mut cfg = cc::Build::new();
-        cfg.cargo_metadata(false)
-            .opt_level(2)
-            .warnings(false)
-            .debug(false)
-            .cpp(true)
-            .target(&target.triple)
-            .host(&build.build.triple);
-
+        let mut cfg = new_cc_build(build, target);
+        cfg.cpp(true);
         let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
             cfg.compiler(cxx);
             true