@@ -29,11 +29,8 @@ use crate::core::config::TargetSelection;
29
29
use crate :: utils:: exec:: { BootstrapCommand , command} ;
30
30
use crate :: { Build , CLang , GitRepo } ;
31
31
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 > {
37
34
if let Some ( ar) = env:: var_os ( format ! ( "AR_{}" , target. triple. replace( '-' , "_" ) ) ) {
38
35
Some ( PathBuf :: from ( ar) )
39
36
} else if let Some ( ar) = env:: var_os ( "AR" ) {
@@ -57,16 +54,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
57
54
} else if target. contains ( "android" ) || target. contains ( "-wasi" ) {
58
55
Some ( cc. parent ( ) . unwrap ( ) . join ( PathBuf :: from ( "llvm-ar" ) ) )
59
56
} 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)
70
58
}
71
59
}
72
60
@@ -138,7 +126,7 @@ pub fn find_target(build: &Build, target: TargetSelection) {
138
126
let ar = if let ar @ Some ( ..) = config. and_then ( |c| c. ar . clone ( ) ) {
139
127
ar
140
128
} else {
141
- cc2ar ( compiler. path ( ) , target)
129
+ cc2ar ( compiler. path ( ) , target, PathBuf :: from ( cfg . get_archiver ( ) . get_program ( ) ) )
142
130
} ;
143
131
144
132
build. cc . borrow_mut ( ) . insert ( target, compiler. clone ( ) ) ;
0 commit comments