@@ -6,9 +6,7 @@ use std::{env, io, iter, mem, str};
6
6
7
7
use cc:: windows_registry;
8
8
use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
9
- use rustc_metadata:: {
10
- find_native_static_library, try_find_native_dynamic_library, try_find_native_static_library,
11
- } ;
9
+ use rustc_metadata:: { try_find_native_dynamic_library, try_find_native_static_library} ;
12
10
use rustc_middle:: bug;
13
11
use rustc_middle:: middle:: dependency_format:: Linkage ;
14
12
use rustc_middle:: middle:: exported_symbols;
@@ -615,15 +613,15 @@ impl<'a> Linker for GccLinker<'a> {
615
613
}
616
614
617
615
fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
616
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
617
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
618
+ }
618
619
self . hint_static ( ) ;
619
620
let colon = if verbatim && self . is_gnu { ":" } else { "" } ;
620
621
if !whole_archive {
621
622
self . link_or_cc_arg ( format ! ( "-l{colon}{name}" ) ) ;
622
623
} else if self . sess . target . is_like_darwin {
623
- // -force_load is the macOS equivalent of --whole-archive, but it
624
- // involves passing the full path to the library to link.
625
- self . link_arg ( "-force_load" ) ;
626
- self . link_arg ( find_native_static_library ( name, verbatim, self . sess ) ) ;
624
+ self . link_args ( & [ "-force_load" , name] ) ;
627
625
} else {
628
626
self . link_arg ( "--whole-archive" )
629
627
. link_or_cc_arg ( format ! ( "-l{colon}{name}" ) )
@@ -956,15 +954,12 @@ impl<'a> Linker for MsvcLinker<'a> {
956
954
}
957
955
958
956
fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
959
- // On MSVC-like targets rustc supports static libraries using alternative naming
960
- // scheme (`libfoo.a`) unsupported by linker, search for such libraries manually.
961
957
if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
962
- self . link_staticlib_by_path ( & path, whole_archive) ;
963
- } else {
964
- let opts = if whole_archive { "/WHOLEARCHIVE:" } else { "" } ;
965
- let ( prefix, suffix) = self . sess . staticlib_components ( verbatim) ;
966
- self . link_arg ( format ! ( "{opts}{prefix}{name}{suffix}" ) ) ;
958
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
967
959
}
960
+ let opts = if whole_archive { "/WHOLEARCHIVE:" } else { "" } ;
961
+ let ( prefix, suffix) = self . sess . staticlib_components ( verbatim) ;
962
+ self . link_arg ( format ! ( "{opts}{prefix}{name}{suffix}" ) ) ;
968
963
}
969
964
970
965
fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
@@ -1193,7 +1188,10 @@ impl<'a> Linker for EmLinker<'a> {
1193
1188
self . link_or_cc_arg ( path) ;
1194
1189
}
1195
1190
1196
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , _whole_archive : bool ) {
1191
+ fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1192
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1193
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1194
+ }
1197
1195
self . link_or_cc_args ( & [ "-l" , name] ) ;
1198
1196
}
1199
1197
@@ -1359,7 +1357,10 @@ impl<'a> Linker for WasmLd<'a> {
1359
1357
self . link_or_cc_arg ( path) ;
1360
1358
}
1361
1359
1362
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , whole_archive : bool ) {
1360
+ fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1361
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1362
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1363
+ }
1363
1364
if !whole_archive {
1364
1365
self . link_or_cc_args ( & [ "-l" , name] ) ;
1365
1366
} else {
@@ -1493,7 +1494,10 @@ impl<'a> Linker for L4Bender<'a> {
1493
1494
) {
1494
1495
}
1495
1496
1496
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , whole_archive : bool ) {
1497
+ fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1498
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1499
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1500
+ }
1497
1501
self . hint_static ( ) ;
1498
1502
if !whole_archive {
1499
1503
self . link_arg ( format ! ( "-PC{name}" ) ) ;
@@ -1667,12 +1671,15 @@ impl<'a> Linker for AixLinker<'a> {
1667
1671
}
1668
1672
1669
1673
fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1674
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1675
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1676
+ }
1670
1677
self . hint_static ( ) ;
1671
1678
if !whole_archive {
1672
1679
self . link_or_cc_arg ( if verbatim { String :: from ( name) } else { format ! ( "-l{name}" ) } ) ;
1673
1680
} else {
1674
1681
let mut arg = OsString :: from ( "-bkeepfile:" ) ;
1675
- arg. push ( find_native_static_library ( name, verbatim , self . sess ) ) ;
1682
+ arg. push ( name) ;
1676
1683
self . link_or_cc_arg ( arg) ;
1677
1684
}
1678
1685
}
0 commit comments