Skip to content

Commit 59eac97

Browse files
committed
rustbuild: detect cxx for all targets
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 <Marc-Antoine@Perennou.com>
1 parent 05083c2 commit 59eac97

File tree

7 files changed

+25
-34
lines changed

7 files changed

+25
-34
lines changed

src/bootstrap/builder.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1135,12 +1135,10 @@ impl<'a> Builder<'a> {
11351135
.env(format!("RANLIB_{}", target), ranlib);
11361136
}
11371137

1138-
if let Ok(cxx) = self.cxx(target) {
1139-
let cxx = ccacheify(&cxx);
1140-
cargo
1141-
.env(format!("CXX_{}", target), &cxx)
1142-
.env(format!("CXXFLAGS_{}", target), cflags);
1143-
}
1138+
let cxx = ccacheify(&self.cxx(target));
1139+
cargo
1140+
.env(format!("CXX_{}", target), &cxx)
1141+
.env(format!("CXXFLAGS_{}", target), cflags);
11441142
}
11451143

11461144
if (cmd == "build" || cmd == "rustc")

src/bootstrap/cc_detect.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,27 @@ 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() {
109-
let mut cfg = cc::Build::new();
110-
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);
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
102+
cfg.cpp(true);
113103
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
114104
cfg.compiler(cxx);
115105
} else {
116-
set_compiler(&mut cfg, Language::CPlusPlus, host, config, build);
106+
set_compiler(&mut cfg, Language::CPlusPlus, target, config, build);
117107
}
118108
let compiler = cfg.get_compiler();
119-
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
120-
build.cxx.insert(host, compiler);
109+
build.cxx.insert(target, compiler);
110+
111+
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
112+
build.verbose(&format!("CFLAGS_{} = {:?}", &target, cflags));
113+
build.verbose(&format!("CXX_{} = {:?}", &target, build.cxx(target)));
114+
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target, cflags));
115+
if let Some(ar) = ar {
116+
build.verbose(&format!("AR_{} = {:?}", &target, ar));
117+
build.ar.insert(target, ar);
118+
}
121119
}
122120
}
123121

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
782782
!target.contains("windows") &&
783783
!target.contains("apple") {
784784
let file = compiler_file(builder,
785-
builder.cxx(target).unwrap(),
785+
builder.cxx(target),
786786
target,
787787
"libstdc++.a");
788788
cargo.env("LLVM_STATIC_STDCPP", file);

src/bootstrap/lib.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,8 @@ impl Build {
815815
}
816816

817817
/// Returns the path to the C++ compiler for the target specified.
818-
fn cxx(&self, target: Interned<String>) -> Result<&Path, String> {
819-
match self.cxx.get(&target) {
820-
Some(p) => Ok(p.path()),
821-
None => Err(format!(
822-
"target `{}` is not configured as a host, only as a target",
823-
target))
824-
}
818+
fn cxx(&self, target: Interned<String>) -> &Path {
819+
self.cxx[&target].path()
825820
}
826821

827822
/// Returns the path to the linker for the given target if it needs to be overridden.

src/bootstrap/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ fn configure_cmake(builder: &Builder<'_>,
358358

359359
let (cc, cxx) = match builder.config.llvm_clang_cl {
360360
Some(ref cl) => (cl.as_ref(), cl.as_ref()),
361-
None => (builder.cc(target), builder.cxx(target).unwrap()),
361+
None => (builder.cc(target), builder.cxx(target)),
362362
};
363363

364364
// Handle msvc + ninja + ccache specially (this is what the bots use)

src/bootstrap/sanity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn check(build: &mut Build) {
146146

147147
for host in &build.hosts {
148148
if !build.config.dry_run {
149-
cmd_finder.must_have(build.cxx(*host).unwrap());
149+
cmd_finder.must_have(build.cxx(*host));
150150
}
151151
}
152152

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ impl Step for Compiletest {
12111211
cmd.arg("--cc")
12121212
.arg(builder.cc(target))
12131213
.arg("--cxx")
1214-
.arg(builder.cxx(target).unwrap())
1214+
.arg(builder.cxx(target))
12151215
.arg("--cflags")
12161216
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
12171217
.arg("--llvm-components")

0 commit comments

Comments
 (0)