Skip to content

Commit 1fca246

Browse files
committed
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
1 parent 10f4ce3 commit 1fca246

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

src/bootstrap/cc_detect.rs

+27-30
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
6161
}
6262
}
6363

64+
fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
65+
let mut cfg = cc::Build::new();
66+
cfg.cargo_metadata(false)
67+
.opt_level(2)
68+
.warnings(false)
69+
.debug(false)
70+
.target(&target.triple)
71+
.host(&build.build.triple);
72+
match build.crt_static(target) {
73+
Some(a) => {
74+
cfg.static_crt(a);
75+
}
76+
None => {
77+
if target.contains("msvc") {
78+
cfg.static_crt(true);
79+
}
80+
if target.contains("musl") {
81+
cfg.static_flag(true);
82+
}
83+
}
84+
}
85+
cfg
86+
}
87+
6488
pub fn find(build: &mut Build) {
6589
// For all targets we're going to need a C compiler for building some shims
6690
// and such as well as for being a linker for Rust code.
@@ -72,27 +96,7 @@ pub fn find(build: &mut Build) {
7296
.chain(iter::once(build.build))
7397
.collect::<HashSet<_>>();
7498
for target in targets.into_iter() {
75-
let mut cfg = cc::Build::new();
76-
cfg.cargo_metadata(false)
77-
.opt_level(2)
78-
.warnings(false)
79-
.debug(false)
80-
.target(&target.triple)
81-
.host(&build.build.triple);
82-
match build.crt_static(target) {
83-
Some(a) => {
84-
cfg.static_crt(a);
85-
}
86-
None => {
87-
if target.contains("msvc") {
88-
cfg.static_crt(true);
89-
}
90-
if target.contains("musl") {
91-
cfg.static_flag(true);
92-
}
93-
}
94-
}
95-
99+
let mut cfg = new_cc_build(build, target);
96100
let config = build.config.target_config.get(&target);
97101
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
98102
cfg.compiler(cc);
@@ -112,15 +116,8 @@ pub fn find(build: &mut Build) {
112116

113117
// If we use llvm-libunwind, we will need a C++ compiler as well for all targets
114118
// We'll need one anyways if the target triple is also a host triple
115-
let mut cfg = cc::Build::new();
116-
cfg.cargo_metadata(false)
117-
.opt_level(2)
118-
.warnings(false)
119-
.debug(false)
120-
.cpp(true)
121-
.target(&target.triple)
122-
.host(&build.build.triple);
123-
119+
let mut cfg = new_cc_build(build, target);
120+
cfg.cpp(true);
124121
let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
125122
cfg.compiler(cxx);
126123
true

0 commit comments

Comments
 (0)