@@ -6,9 +6,7 @@ use std::{env, io, iter, mem, str};
66
77use cc:: windows_registry;
88use 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} ;
1210use rustc_middle:: bug;
1311use rustc_middle:: middle:: dependency_format:: Linkage ;
1412use rustc_middle:: middle:: exported_symbols;
@@ -615,15 +613,15 @@ impl<'a> Linker for GccLinker<'a> {
615613 }
616614
617615 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+ }
618619 self . hint_static ( ) ;
619620 let colon = if verbatim && self . is_gnu { ":" } else { "" } ;
620621 if !whole_archive {
621622 self . link_or_cc_arg ( format ! ( "-l{colon}{name}" ) ) ;
622623 } 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] ) ;
627625 } else {
628626 self . link_arg ( "--whole-archive" )
629627 . link_or_cc_arg ( format ! ( "-l{colon}{name}" ) )
@@ -956,15 +954,12 @@ impl<'a> Linker for MsvcLinker<'a> {
956954 }
957955
958956 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.
961957 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) ;
967959 }
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}" ) ) ;
968963 }
969964
970965 fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
@@ -1193,7 +1188,10 @@ impl<'a> Linker for EmLinker<'a> {
11931188 self . link_or_cc_arg ( path) ;
11941189 }
11951190
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+ }
11971195 self . link_or_cc_args ( & [ "-l" , name] ) ;
11981196 }
11991197
@@ -1359,7 +1357,10 @@ impl<'a> Linker for WasmLd<'a> {
13591357 self . link_or_cc_arg ( path) ;
13601358 }
13611359
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+ }
13631364 if !whole_archive {
13641365 self . link_or_cc_args ( & [ "-l" , name] ) ;
13651366 } else {
@@ -1493,7 +1494,10 @@ impl<'a> Linker for L4Bender<'a> {
14931494 ) {
14941495 }
14951496
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+ }
14971501 self . hint_static ( ) ;
14981502 if !whole_archive {
14991503 self . link_arg ( format ! ( "-PC{name}" ) ) ;
@@ -1667,12 +1671,15 @@ impl<'a> Linker for AixLinker<'a> {
16671671 }
16681672
16691673 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+ }
16701677 self . hint_static ( ) ;
16711678 if !whole_archive {
16721679 self . link_or_cc_arg ( if verbatim { String :: from ( name) } else { format ! ( "-l{name}" ) } ) ;
16731680 } else {
16741681 let mut arg = OsString :: from ( "-bkeepfile:" ) ;
1675- arg. push ( find_native_static_library ( name, verbatim , self . sess ) ) ;
1682+ arg. push ( name) ;
16761683 self . link_or_cc_arg ( arg) ;
16771684 }
16781685 }
0 commit comments