Skip to content

Commit bcea6be

Browse files
committed
Rollup merge of rust-lang#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.
2 parents 925822a + 0fe1359 commit bcea6be

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/build_helper/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ pub fn cc2ar(cc: &Path, target: &str) -> PathBuf {
4343
if target.contains("musl") || target.contains("msvc") {
4444
PathBuf::from("ar")
4545
} else {
46+
let parent = cc.parent().unwrap();
4647
let file = cc.file_name().unwrap().to_str().unwrap();
47-
cc.parent().unwrap().join(file.replace("gcc", "ar")
48-
.replace("cc", "ar")
49-
.replace("clang", "ar"))
48+
for suffix in &["gcc", "cc", "clang"] {
49+
if let Some(idx) = file.rfind(suffix) {
50+
let mut file = file[..idx].to_owned();
51+
file.push_str("ar");
52+
return parent.join(&file);
53+
}
54+
}
55+
parent.join(file)
5056
}
5157
}
5258

0 commit comments

Comments
 (0)