From 59eac97869eed3a7aa41a96c92021194ddca99f9 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Wed, 5 Jun 2019 15:41:44 +0200 Subject: [PATCH] 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 --- src/bootstrap/builder.rs | 10 ++++------ src/bootstrap/cc_detect.rs | 32 +++++++++++++++----------------- src/bootstrap/compile.rs | 2 +- src/bootstrap/lib.rs | 9 ++------- src/bootstrap/native.rs | 2 +- src/bootstrap/sanity.rs | 2 +- src/bootstrap/test.rs | 2 +- 7 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 2281a45e014a9..ebe03596b8a1a 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -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") diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs index dfc243b7054ab..7cdc835f2281b 100644 --- a/src/bootstrap/cc_detect.rs +++ b/src/bootstrap/cc_detect.rs @@ -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::>(); - 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); + } } } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index c7fa8e788b573..e2c741a064ffe 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -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); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index b9d287abb0c7e..42fbecd8e1c72 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -815,13 +815,8 @@ impl Build { } /// Returns the path to the C++ compiler for the target specified. - fn cxx(&self, target: Interned) -> 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) -> &Path { + self.cxx[&target].path() } /// Returns the path to the linker for the given target if it needs to be overridden. diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index bf3601cb312fd..9df1870751f6a 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -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) diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index dc65fb9b79706..5bf08a45b2901 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -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)); } } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 74caaae2840c5..095ba146caa6e 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -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")