提交 59eac978 编写于 作者: M Marc-Antoine Perennou

rustbuild: detect cxx for all targets

Replaces #61544
Fixes #59917

We need CXX to build llvm-libunwind which can be enabled for all
targets.
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.
Signed-off-by: NMarc-Antoine Perennou <Marc-Antoine@Perennou.com>
上级 05083c2d
......@@ -1135,12 +1135,10 @@ pub fn cargo(
.env(format!("RANLIB_{}", target), ranlib);
}
if let Ok(cxx) = self.cxx(target) {
let cxx = ccacheify(&cxx);
cargo
.env(format!("CXX_{}", target), &cxx)
.env(format!("CXXFLAGS_{}", target), cflags);
}
let cxx = ccacheify(&self.cxx(target));
cargo
.env(format!("CXX_{}", target), &cxx)
.env(format!("CXXFLAGS_{}", target), cflags);
}
if (cmd == "build" || cmd == "rustc")
......
......@@ -95,29 +95,27 @@ pub fn find(build: &mut Build) {
};
build.cc.insert(target, compiler);
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
build.verbose(&format!("CFLAGS_{} = {:?}", &target, build.cflags(target, GitRepo::Rustc)));
if let Some(ar) = ar {
build.verbose(&format!("AR_{} = {:?}", &target, ar));
build.ar.insert(target, ar);
}
}
let cflags = build.cflags(target, GitRepo::Rustc);
// For all host triples we need to find a C++ compiler as well
let hosts = build.hosts.iter().cloned().chain(iter::once(build.build)).collect::<HashSet<_>>();
for host in hosts.into_iter() {
let mut cfg = cc::Build::new();
cfg.cargo_metadata(false).opt_level(2).warnings(false).debug(false).cpp(true)
.target(&host).host(&build.build);
let config = build.config.target_config.get(&host);
// 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
cfg.cpp(true);
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
} else {
set_compiler(&mut cfg, Language::CPlusPlus, host, config, build);
set_compiler(&mut cfg, Language::CPlusPlus, target, config, build);
}
let compiler = cfg.get_compiler();
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
build.cxx.insert(host, compiler);
build.cxx.insert(target, compiler);
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
build.verbose(&format!("CFLAGS_{} = {:?}", &target, cflags));
build.verbose(&format!("CXX_{} = {:?}", &target, build.cxx(target)));
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target, cflags));
if let Some(ar) = ar {
build.verbose(&format!("AR_{} = {:?}", &target, ar));
build.ar.insert(target, ar);
}
}
}
......
......@@ -782,7 +782,7 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
!target.contains("windows") &&
!target.contains("apple") {
let file = compiler_file(builder,
builder.cxx(target).unwrap(),
builder.cxx(target),
target,
"libstdc++.a");
cargo.env("LLVM_STATIC_STDCPP", file);
......
......@@ -815,13 +815,8 @@ fn ranlib(&self, target: Interned<String>) -> Option<&Path> {
}
/// Returns the path to the C++ compiler for the target specified.
fn cxx(&self, target: Interned<String>) -> Result<&Path, String> {
match self.cxx.get(&target) {
Some(p) => Ok(p.path()),
None => Err(format!(
"target `{}` is not configured as a host, only as a target",
target))
}
fn cxx(&self, target: Interned<String>) -> &Path {
self.cxx[&target].path()
}
/// Returns the path to the linker for the given target if it needs to be overridden.
......
......@@ -358,7 +358,7 @@ fn configure_cmake(builder: &Builder<'_>,
let (cc, cxx) = match builder.config.llvm_clang_cl {
Some(ref cl) => (cl.as_ref(), cl.as_ref()),
None => (builder.cc(target), builder.cxx(target).unwrap()),
None => (builder.cc(target), builder.cxx(target)),
};
// Handle msvc + ninja + ccache specially (this is what the bots use)
......
......@@ -146,7 +146,7 @@ pub fn check(build: &mut Build) {
for host in &build.hosts {
if !build.config.dry_run {
cmd_finder.must_have(build.cxx(*host).unwrap());
cmd_finder.must_have(build.cxx(*host));
}
}
......
......@@ -1211,7 +1211,7 @@ fn run(self, builder: &Builder<'_>) {
cmd.arg("--cc")
.arg(builder.cc(target))
.arg("--cxx")
.arg(builder.cxx(target).unwrap())
.arg(builder.cxx(target))
.arg("--cflags")
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
.arg("--llvm-components")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册