Skip to content

Commit

Permalink
Rollup merge of rust-lang#34302 - retep998:🐇-sanity-is-overrated-🐇, r…
Browse files Browse the repository at this point in the history
…=alexcrichton

Fix issue where rustbuild expected msvc to have ar

I made `cc2ar` return an `Option`.

r? @alexcrichton
  • Loading branch information
Manishearth authored Jun 16, 2016
2 parents 986bb53 + e0992df commit 51b20bc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/bootstrap/build/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ pub fn find(build: &mut Build) {
let compiler = cfg.get_compiler();
let ar = cc2ar(compiler.path(), target);
build.verbose(&format!("CC_{} = {:?}", target, compiler.path()));
build.verbose(&format!("AR_{} = {:?}", target, ar));
if let Some(ref ar) = ar {
build.verbose(&format!("AR_{} = {:?}", target, ar));
}
build.cc.insert(target.to_string(), (compiler, ar));
}

Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct Build {
lldb_python_dir: Option<String>,

// Runtime state filled in later on
cc: HashMap<String, (gcc::Tool, PathBuf)>,
cc: HashMap<String, (gcc::Tool, Option<PathBuf>)>,
cxx: HashMap<String, gcc::Tool>,
compiler_rt_built: RefCell<HashMap<String, PathBuf>>,
}
Expand Down Expand Up @@ -549,7 +549,7 @@ impl Build {
// FIXME: the guard against msvc shouldn't need to be here
if !target.contains("msvc") {
cargo.env(format!("CC_{}", target), self.cc(target))
.env(format!("AR_{}", target), self.ar(target))
.env(format!("AR_{}", target), self.ar(target).unwrap()) // only msvc is None
.env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
}

Expand Down Expand Up @@ -825,8 +825,8 @@ impl Build {
}

/// Returns the path to the `ar` archive utility for the target specified.
fn ar(&self, target: &str) -> &Path {
&self.cc[target].1
fn ar(&self, target: &str) -> Option<&Path> {
self.cc[target].1.as_ref().map(|p| &**p)
}

/// Returns the path to the C++ compiler for the target specified, may panic
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/build/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ pub fn check(build: &mut Build) {
// also build some C++ shims for LLVM so we need a C++ compiler.
for target in build.config.target.iter() {
need_cmd(build.cc(target).as_ref());
need_cmd(build.ar(target).as_ref());
if let Some(ar) = build.ar(target) {
need_cmd(ar.as_ref());
}
}
for host in build.config.host.iter() {
need_cmd(build.cxx(host).as_ref());
Expand Down
12 changes: 7 additions & 5 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,22 @@ pub fn gnu_target(target: &str) -> String {
}
}

pub fn cc2ar(cc: &Path, target: &str) -> PathBuf {
if target.contains("musl") || target.contains("msvc") {
PathBuf::from("ar")
pub fn cc2ar(cc: &Path, target: &str) -> Option<PathBuf> {
if target.contains("msvc") {
None
} else if target.contains("musl") {
Some(PathBuf::from("ar"))
} else {
let parent = cc.parent().unwrap();
let file = cc.file_name().unwrap().to_str().unwrap();
for suffix in &["gcc", "cc", "clang"] {
if let Some(idx) = file.rfind(suffix) {
let mut file = file[..idx].to_owned();
file.push_str("ar");
return parent.join(&file);
return Some(parent.join(&file));
}
}
parent.join(file)
Some(parent.join(file))
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/liballoc_jemalloc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ fn main() {
}

let compiler = gcc::Config::new().get_compiler();
let ar = build_helper::cc2ar(compiler.path(), &target);
// only msvc returns None for ar so unwrap is okay
let ar = build_helper::cc2ar(compiler.path(), &target).unwrap();
let cflags = compiler.args()
.iter()
.map(|s| s.to_str().unwrap())
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ fn build_libbacktrace(host: &str, target: &str) {
}

let compiler = gcc::Config::new().get_compiler();
let ar = build_helper::cc2ar(compiler.path(), target);
// only msvc returns None for ar so unwrap is okay
let ar = build_helper::cc2ar(compiler.path(), target).unwrap();
let cflags = compiler.args().iter().map(|s| s.to_str().unwrap())
.collect::<Vec<_>>().join(" ");
run(Command::new("sh")
Expand Down

0 comments on commit 51b20bc

Please sign in to comment.