about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-04-07 23:26:17 +0530
committerManish Goregaokar <manishsmail@gmail.com>2016-04-07 23:26:17 +0530
commitef8635ec82a100d46ddcb522a9b1cf204ea6b271 (patch)
tree96a794298bc3ec939a450448b10a3baae9c14e55 /src
parent2baa1503c9259c79e583b76090120abbf4bf2890 (diff)
parent0fe1359885288537833d4b8cd6db724b46ea07b7 (diff)
downloadrust-ef8635ec82a100d46ddcb522a9b1cf204ea6b271.tar.gz
rust-ef8635ec82a100d46ddcb522a9b1cf204ea6b271.zip
Rollup merge of #32729 - pierzchalski:build_helper_suffix, r=alexcrichton
Change build helper to modify suffix

The current implementation of [gcc](https://crates.io/crates/gcc) defaults to using the ```CC``` environment variable to determine the compiler. The current global-find-replace in ```build_helper``` causes issues for projects using tools like ```ccache``` if they try to integrate libstd into their build system.

Almost all cross-compiler toolchains have the tool name as a suffix of the filename, so changing this to suffix-replacement instead of global-replacement should be fine.
Diffstat (limited to 'src')
-rw-r--r--src/build_helper/lib.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs
index 092a1cabc74..8e1da69cf02 100644
--- a/src/build_helper/lib.rs
+++ b/src/build_helper/lib.rs
@@ -43,10 +43,16 @@ pub fn cc2ar(cc: &Path, target: &str) -> PathBuf {
     if target.contains("musl") || target.contains("msvc") {
         PathBuf::from("ar")
     } else {
+        let parent = cc.parent().unwrap();
         let file = cc.file_name().unwrap().to_str().unwrap();
-        cc.parent().unwrap().join(file.replace("gcc", "ar")
-                                      .replace("cc", "ar")
-                                      .replace("clang", "ar"))
+        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);
+            }
+        }
+        parent.join(file)
     }
 }