Skip to content

Commit

Permalink
rustbuild: detect cxx for all targets
Browse files Browse the repository at this point in the history
Replaces rust-lang#61544
Fixes rust-lang#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 <[email protected]>
  • Loading branch information
Keruspe committed Jun 12, 2019
1 parent 05083c2 commit 59eac97
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
10 changes: 4 additions & 6 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 15 additions & 17 deletions src/bootstrap/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 59eac97

Please sign in to comment.