Skip to content

Commit 53ca86c

Browse files
committed
test
Signed-off-by: onur-ozkan <[email protected]>
1 parent 5027ee2 commit 53ca86c

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/bootstrap/src/utils/cc_detect.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
//! everything.
2323
2424
use std::collections::HashSet;
25-
use std::iter;
2625
use std::path::{Path, PathBuf};
26+
use std::{env, iter};
2727

2828
use crate::core::config::TargetSelection;
2929
use crate::utils::exec::{BootstrapCommand, command};
@@ -56,6 +56,36 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
5656
cfg
5757
}
5858

59+
/// Finds archiver tool for the given target if possible.
60+
/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate.
61+
fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<PathBuf> {
62+
if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace('-', "_"))) {
63+
Some(PathBuf::from(ar))
64+
} else if let Some(ar) = env::var_os("AR") {
65+
Some(PathBuf::from(ar))
66+
} else if target.is_msvc() {
67+
None
68+
} else if target.contains("musl") || target.contains("openbsd") {
69+
Some(PathBuf::from("ar"))
70+
} else if target.contains("vxworks") {
71+
Some(PathBuf::from("wr-ar"))
72+
} else if target.contains("-nto-") {
73+
if target.starts_with("i586") {
74+
Some(PathBuf::from("ntox86-ar"))
75+
} else if target.starts_with("aarch64") {
76+
Some(PathBuf::from("ntoaarch64-ar"))
77+
} else if target.starts_with("x86_64") {
78+
Some(PathBuf::from("ntox86_64-ar"))
79+
} else {
80+
panic!("Unknown architecture, cannot determine archiver for Neutrino QNX");
81+
}
82+
} else if target.contains("android") || target.contains("-wasi") {
83+
Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar")))
84+
} else {
85+
Some(default_ar)
86+
}
87+
}
88+
5989
/// Probes for C and C++ compilers and configures the corresponding entries in the [`Build`]
6090
/// structure.
6191
///
@@ -110,7 +140,13 @@ pub fn find_target(build: &Build, target: TargetSelection) {
110140
let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
111141
ar
112142
} else {
113-
cfg.try_get_archiver().map(|c| PathBuf::from(c.get_program())).ok()
143+
dbg!(compiler.path());
144+
let old = cc2ar(compiler.path(), target, PathBuf::from(cfg.get_archiver().get_program()));
145+
dbg!(old);
146+
let new = cfg.try_get_archiver().map(|c| PathBuf::from(c.get_program())).ok();
147+
dbg!(&new);
148+
149+
new
114150
};
115151

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

0 commit comments

Comments
 (0)