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: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
This commit is contained in:
Marc-Antoine Perennou 2019-06-05 15:41:44 +02:00
parent 05083c2dee
commit 59eac97869
7 changed files with 26 additions and 35 deletions

View File

@ -1135,12 +1135,10 @@ impl<'a> Builder<'a> {
.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")

View File

@ -95,30 +95,28 @@ pub fn find(build: &mut Build) {
};
build.cc.insert(target, compiler);
let cflags = build.cflags(target, GitRepo::Rustc);
// 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, target, config, build);
}
let compiler = cfg.get_compiler();
build.cxx.insert(target, compiler);
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
build.verbose(&format!("CFLAGS_{} = {:?}", &target, build.cflags(target, GitRepo::Rustc)));
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);
}
}
// 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 let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
} else {
set_compiler(&mut cfg, Language::CPlusPlus, host, config, build);
}
let compiler = cfg.get_compiler();
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
build.cxx.insert(host, compiler);
}
}
fn set_compiler(cfg: &mut cc::Build,

View File

@ -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);

View File

@ -815,13 +815,8 @@ impl Build {
}
/// 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.

View File

@ -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)

View File

@ -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));
}
}

View File

@ -1211,7 +1211,7 @@ impl Step for Compiletest {
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")