From e0992df35f7827fe09b1a54558e396511bcba12a Mon Sep 17 00:00:00 2001 From: Peter Atashian Date: Thu, 16 Jun 2016 08:38:06 -0400 Subject: [PATCH] Fix issue where rustbuild expected msvc to have ar Signed-off-by: Peter Atashian --- src/bootstrap/build/cc.rs | 4 +++- src/bootstrap/build/mod.rs | 8 ++++---- src/bootstrap/build/sanity.rs | 4 +++- src/build_helper/lib.rs | 12 +++++++----- src/liballoc_jemalloc/build.rs | 3 ++- src/libstd/build.rs | 3 ++- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/bootstrap/build/cc.rs b/src/bootstrap/build/cc.rs index d0b0f1007c6a0..7eb50b8b86dac 100644 --- a/src/bootstrap/build/cc.rs +++ b/src/bootstrap/build/cc.rs @@ -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)); } diff --git a/src/bootstrap/build/mod.rs b/src/bootstrap/build/mod.rs index 21d12d27d92e1..dadb0ffa6c98d 100644 --- a/src/bootstrap/build/mod.rs +++ b/src/bootstrap/build/mod.rs @@ -119,7 +119,7 @@ pub struct Build { lldb_python_dir: Option, // Runtime state filled in later on - cc: HashMap, + cc: HashMap)>, cxx: HashMap, compiler_rt_built: RefCell>, } @@ -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(" ")); } @@ -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 diff --git a/src/bootstrap/build/sanity.rs b/src/bootstrap/build/sanity.rs index a290527742982..fd6cdc702cc3b 100644 --- a/src/bootstrap/build/sanity.rs +++ b/src/bootstrap/build/sanity.rs @@ -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()); diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index 8e1da69cf02e7..838cc4f07a9a1 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -39,9 +39,11 @@ 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 { + 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(); @@ -49,10 +51,10 @@ pub fn cc2ar(cc: &Path, target: &str) -> PathBuf { 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)) } } diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index e43b9a9df1b84..d1b3583d256b6 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -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()) diff --git a/src/libstd/build.rs b/src/libstd/build.rs index ff9dacbb6799b..9c408366f8b48 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -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::>().join(" "); run(Command::new("sh")