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
This commit is contained in:
commit
8567fbb4b5
1 changed files with 4 additions and 16 deletions
|
@ -29,11 +29,8 @@ use crate::core::config::TargetSelection;
|
|||
use crate::utils::exec::{BootstrapCommand, command};
|
||||
use crate::{Build, CLang, GitRepo};
|
||||
|
||||
// The `cc` crate doesn't provide a way to obtain a path to the detected archiver,
|
||||
// so use some simplified logic here. First we respect the environment variable `AR`, then
|
||||
// try to infer the archiver path from the C compiler path.
|
||||
// In the future this logic should be replaced by calling into the `cc` crate.
|
||||
fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
|
||||
/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate.
|
||||
fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<PathBuf> {
|
||||
if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace('-', "_"))) {
|
||||
Some(PathBuf::from(ar))
|
||||
} else if let Some(ar) = env::var_os("AR") {
|
||||
|
@ -57,16 +54,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
|
|||
} else if target.contains("android") || target.contains("-wasi") {
|
||||
Some(cc.parent().unwrap().join(PathBuf::from("llvm-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 Some(parent.join(&file));
|
||||
}
|
||||
}
|
||||
Some(parent.join(file))
|
||||
Some(default_ar)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,7 +126,7 @@ pub fn find_target(build: &Build, target: TargetSelection) {
|
|||
let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
|
||||
ar
|
||||
} else {
|
||||
cc2ar(compiler.path(), target)
|
||||
cc2ar(compiler.path(), target, PathBuf::from(cfg.get_archiver().get_program()))
|
||||
};
|
||||
|
||||
build.cc.borrow_mut().insert(target, compiler.clone());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue