Skip to content

Commit

Permalink
rustbuild: don't set cxx if not configured
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
  • Loading branch information
Keruspe committed Jun 13, 2019
1 parent 00b6015 commit fdecfe4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
10 changes: 6 additions & 4 deletions src/bootstrap/builder.rs
Expand Up @@ -1135,10 +1135,12 @@ impl<'a> Builder<'a> {
.env(format!("RANLIB_{}", target), ranlib);
}

let cxx = ccacheify(&self.cxx(target));
cargo
.env(format!("CXX_{}", target), &cxx)
.env(format!("CXXFLAGS_{}", target), cflags);
if let Ok(cxx) = self.cxx(target) {
let cxx = ccacheify(&cxx);
cargo
.env(format!("CXX_{}", target), &cxx)
.env(format!("CXXFLAGS_{}", target), cflags);
}
}

if (cmd == "build" || cmd == "rustc")
Expand Down
33 changes: 23 additions & 10 deletions src/bootstrap/cc_detect.rs
Expand Up @@ -102,18 +102,25 @@ pub fn find(build: &mut Build) {
let mut cfg = cc::Build::new();
cfg.cargo_metadata(false).opt_level(2).warnings(false).debug(false).cpp(true)
.target(&target).host(&build.build);
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {

let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
true
} else {
set_compiler(&mut cfg, Language::CPlusPlus, target, config, build);
set_compiler(&mut cfg, Language::CPlusPlus, target, config, build)
};

if cxx_configured {
let compiler = cfg.get_compiler();
build.cxx.insert(target, compiler);
}
let compiler = cfg.get_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 Ok(cxx) = build.cxx(target) {
build.verbose(&format!("CXX_{} = {:?}", &target, cxx));
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target, cflags));
}
if let Some(ar) = ar {
build.verbose(&format!("AR_{} = {:?}", &target, ar));
build.ar.insert(target, ar);
Expand All @@ -125,7 +132,7 @@ fn set_compiler(cfg: &mut cc::Build,
compiler: Language,
target: Interned<String>,
config: Option<&Target>,
build: &Build) {
build: &Build) -> bool {
match &*target {
// When compiling for android we may have the NDK configured in the
// config.toml in which case we look there. Otherwise the default
Expand All @@ -138,6 +145,7 @@ fn set_compiler(cfg: &mut cc::Build,
.replace("thumbv7", "arm");
let compiler = format!("{}-{}", target, compiler.clang());
cfg.compiler(ndk.join("bin").join(compiler));
return true;
}
}

Expand All @@ -147,32 +155,35 @@ fn set_compiler(cfg: &mut cc::Build,
let c = cfg.get_compiler();
let gnu_compiler = compiler.gcc();
if !c.path().ends_with(gnu_compiler) {
return
return false;
}

let output = output(c.to_command().arg("--version"));
let i = match output.find(" 4.") {
Some(i) => i,
None => return,
None => return false,
};
match output[i + 3..].chars().next().unwrap() {
'0' ..= '6' => {}
_ => return,
_ => return false,
}
let alternative = format!("e{}", gnu_compiler);
if Command::new(&alternative).output().is_ok() {
cfg.compiler(alternative);
return true;
}
}

"mips-unknown-linux-musl" => {
if cfg.get_compiler().path().to_str() == Some("gcc") {
cfg.compiler("mips-linux-musl-gcc");
return true;
}
}
"mipsel-unknown-linux-musl" => {
if cfg.get_compiler().path().to_str() == Some("gcc") {
cfg.compiler("mipsel-linux-musl-gcc");
return true;
}
}

Expand All @@ -181,12 +192,14 @@ fn set_compiler(cfg: &mut cc::Build,
let guess = root.join("bin/musl-gcc");
if guess.exists() {
cfg.compiler(guess);
return true;
}
}
}

_ => {}
}
false
}

/// The target programming language for a native compiler.
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
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),
builder.cxx(target).unwrap(),
target,
"libstdc++.a");
cargo.env("LLVM_STATIC_STDCPP", file);
Expand Down
9 changes: 7 additions & 2 deletions src/bootstrap/lib.rs
Expand Up @@ -815,8 +815,13 @@ impl Build {
}

/// Returns the path to the C++ compiler for the target specified.
fn cxx(&self, target: Interned<String>) -> &Path {
self.cxx[&target].path()
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))
}
}

/// 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
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)),
None => (builder.cc(target), builder.cxx(target).unwrap()),
};

// Handle msvc + ninja + ccache specially (this is what the bots use)
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/sanity.rs
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));
cmd_finder.must_have(build.cxx(*host).unwrap());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/test.rs
Expand Up @@ -1211,7 +1211,7 @@ impl Step for Compiletest {
cmd.arg("--cc")
.arg(builder.cc(target))
.arg("--cxx")
.arg(builder.cxx(target))
.arg(builder.cxx(target).unwrap())
.arg("--cflags")
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
.arg("--llvm-components")
Expand Down

0 comments on commit fdecfe4

Please sign in to comment.