@@ -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;
@@ -614,15 +612,15 @@ impl<'a> Linker for GccLinker<'a> {
614
612
}
615
613
616
614
fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
615
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
616
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
617
+ }
617
618
self . hint_static ( ) ;
618
619
let colon = if verbatim && self . is_gnu { ":" } else { "" } ;
619
620
if !whole_archive {
620
621
self . link_or_cc_arg ( format ! ( "-l{colon}{name}" ) ) ;
621
622
} else if self . sess . target . is_like_osx {
622
- // -force_load is the macOS equivalent of --whole-archive, but it
623
- // involves passing the full path to the library to link.
624
- self . link_arg ( "-force_load" ) ;
625
- self . link_arg ( find_native_static_library ( name, verbatim, self . sess ) ) ;
623
+ self . link_args ( & [ "-force_load" , name] ) ;
626
624
} else {
627
625
self . link_arg ( "--whole-archive" )
628
626
. link_or_cc_arg ( format ! ( "-l{colon}{name}" ) )
@@ -953,15 +951,12 @@ impl<'a> Linker for MsvcLinker<'a> {
953
951
}
954
952
955
953
fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
956
- // On MSVC-like targets rustc supports static libraries using alternative naming
957
- // scheme (`libfoo.a`) unsupported by linker, search for such libraries manually.
958
954
if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
959
- self . link_staticlib_by_path ( & path, whole_archive) ;
960
- } else {
961
- let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" } ;
962
- let suffix = if verbatim { "" } else { ".lib" } ;
963
- self . link_arg ( format ! ( "{prefix}{name}{suffix}" ) ) ;
955
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
964
956
}
957
+ let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" } ;
958
+ let suffix = if verbatim { "" } else { ".lib" } ;
959
+ self . link_arg ( format ! ( "{prefix}{name}{suffix}" ) ) ;
965
960
}
966
961
967
962
fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
@@ -1190,7 +1185,10 @@ impl<'a> Linker for EmLinker<'a> {
1190
1185
self . link_or_cc_arg ( path) ;
1191
1186
}
1192
1187
1193
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , _whole_archive : bool ) {
1188
+ fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1189
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1190
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1191
+ }
1194
1192
self . link_or_cc_args ( & [ "-l" , name] ) ;
1195
1193
}
1196
1194
@@ -1356,7 +1354,10 @@ impl<'a> Linker for WasmLd<'a> {
1356
1354
self . link_or_cc_arg ( path) ;
1357
1355
}
1358
1356
1359
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , whole_archive : bool ) {
1357
+ fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1358
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1359
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1360
+ }
1360
1361
if !whole_archive {
1361
1362
self . link_or_cc_args ( & [ "-l" , name] ) ;
1362
1363
} else {
@@ -1490,7 +1491,10 @@ impl<'a> Linker for L4Bender<'a> {
1490
1491
) {
1491
1492
}
1492
1493
1493
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , whole_archive : bool ) {
1494
+ fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1495
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1496
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1497
+ }
1494
1498
self . hint_static ( ) ;
1495
1499
if !whole_archive {
1496
1500
self . link_arg ( format ! ( "-PC{name}" ) ) ;
@@ -1664,12 +1668,15 @@ impl<'a> Linker for AixLinker<'a> {
1664
1668
}
1665
1669
1666
1670
fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
1671
+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
1672
+ return self . link_staticlib_by_path ( & path, whole_archive) ;
1673
+ }
1667
1674
self . hint_static ( ) ;
1668
1675
if !whole_archive {
1669
1676
self . link_or_cc_arg ( if verbatim { String :: from ( name) } else { format ! ( "-l{name}" ) } ) ;
1670
1677
} else {
1671
1678
let mut arg = OsString :: from ( "-bkeepfile:" ) ;
1672
- arg. push ( find_native_static_library ( name, verbatim , self . sess ) ) ;
1679
+ arg. push ( name) ;
1673
1680
self . link_or_cc_arg ( arg) ;
1674
1681
}
1675
1682
}
0 commit comments