Skip to content

Commit 40ab9d2

Browse files
committed
Auto merge of #61765 - Keruspe:rustbuild-cxx, r=alexcrichton
rustbuild: detect cxx for all targets Replaces #61544 Fixes #59917 We need CXX to build llvm-libunwind which can be enabled for alltargets. As we needed it for all hosts anyways, just move the detection so that it is ran for all targets (which contains all hosts) instead.
2 parents 10deeae + 087cd77 commit 40ab9d2

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/bootstrap/cc_detect.rs

+27-17
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,39 @@ pub fn find(build: &mut Build) {
9595
};
9696

9797
build.cc.insert(target, compiler);
98-
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
99-
build.verbose(&format!("CFLAGS_{} = {:?}", &target, build.cflags(target, GitRepo::Rustc)));
100-
if let Some(ar) = ar {
101-
build.verbose(&format!("AR_{} = {:?}", &target, ar));
102-
build.ar.insert(target, ar);
103-
}
104-
}
98+
let cflags = build.cflags(target, GitRepo::Rustc);
10599

106-
// For all host triples we need to find a C++ compiler as well
107-
let hosts = build.hosts.iter().cloned().chain(iter::once(build.build)).collect::<HashSet<_>>();
108-
for host in hosts.into_iter() {
100+
// If we use llvm-libunwind, we will need a C++ compiler as well for all targets
101+
// We'll need one anyways if the target triple is also a host triple
109102
let mut cfg = cc::Build::new();
110103
cfg.cargo_metadata(false).opt_level(2).warnings(false).debug(false).cpp(true)
111-
.target(&host).host(&build.build);
112-
let config = build.config.target_config.get(&host);
113-
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
104+
.target(&target).host(&build.build);
105+
106+
let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
114107
cfg.compiler(cxx);
108+
true
109+
} else if build.hosts.contains(&target) || build.build == target {
110+
set_compiler(&mut cfg, Language::CPlusPlus, target, config, build);
111+
true
115112
} else {
116-
set_compiler(&mut cfg, Language::CPlusPlus, host, config, build);
113+
false
114+
};
115+
116+
if cxx_configured {
117+
let compiler = cfg.get_compiler();
118+
build.cxx.insert(target, compiler);
119+
}
120+
121+
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
122+
build.verbose(&format!("CFLAGS_{} = {:?}", &target, cflags));
123+
if let Ok(cxx) = build.cxx(target) {
124+
build.verbose(&format!("CXX_{} = {:?}", &target, cxx));
125+
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target, cflags));
126+
}
127+
if let Some(ar) = ar {
128+
build.verbose(&format!("AR_{} = {:?}", &target, ar));
129+
build.ar.insert(target, ar);
117130
}
118-
let compiler = cfg.get_compiler();
119-
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
120-
build.cxx.insert(host, compiler);
121131
}
122132
}
123133

0 commit comments

Comments
 (0)