Skip to content

Commit 8567fbb

Browse files
Rollup merge of #136916 - onur-ozkan:fix-cc2ar, r=jieyouxu
use cc archiver as default in `cc2ar` We should remove entire `cc2ar` but `cc` doesn't seem to cover all the conditions that `cc2ar` handles. For now, I replaced the `else` logic only, which is a bit hacky and unstable. Fixes #136759
2 parents 54b4b1c + 8a70219 commit 8567fbb

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/bootstrap/src/utils/cc_detect.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ use crate::core::config::TargetSelection;
2929
use crate::utils::exec::{BootstrapCommand, command};
3030
use crate::{Build, CLang, GitRepo};
3131

32-
// The `cc` crate doesn't provide a way to obtain a path to the detected archiver,
33-
// so use some simplified logic here. First we respect the environment variable `AR`, then
34-
// try to infer the archiver path from the C compiler path.
35-
// In the future this logic should be replaced by calling into the `cc` crate.
36-
fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
32+
/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate.
33+
fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<PathBuf> {
3734
if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace('-', "_"))) {
3835
Some(PathBuf::from(ar))
3936
} else if let Some(ar) = env::var_os("AR") {
@@ -57,16 +54,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
5754
} else if target.contains("android") || target.contains("-wasi") {
5855
Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar")))
5956
} else {
60-
let parent = cc.parent().unwrap();
61-
let file = cc.file_name().unwrap().to_str().unwrap();
62-
for suffix in &["gcc", "cc", "clang"] {
63-
if let Some(idx) = file.rfind(suffix) {
64-
let mut file = file[..idx].to_owned();
65-
file.push_str("ar");
66-
return Some(parent.join(&file));
67-
}
68-
}
69-
Some(parent.join(file))
57+
Some(default_ar)
7058
}
7159
}
7260

@@ -138,7 +126,7 @@ pub fn find_target(build: &Build, target: TargetSelection) {
138126
let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
139127
ar
140128
} else {
141-
cc2ar(compiler.path(), target)
129+
cc2ar(compiler.path(), target, PathBuf::from(cfg.get_archiver().get_program()))
142130
};
143131

144132
build.cc.borrow_mut().insert(target, compiler.clone());

0 commit comments

Comments
 (0)