@@ -7,7 +7,7 @@ use std::{env, iter, mem, str};
77
88use cc:: windows_registry;
99use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
10- use rustc_metadata:: find_native_static_library;
10+ use rustc_metadata:: { find_native_static_library, try_find_native_static_library } ;
1111use rustc_middle:: bug;
1212use rustc_middle:: middle:: dependency_format:: Linkage ;
1313use rustc_middle:: middle:: exported_symbols;
@@ -891,9 +891,15 @@ impl<'a> Linker for MsvcLinker<'a> {
891891 }
892892
893893 fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
894- let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" } ;
895- let suffix = if verbatim { "" } else { ".lib" } ;
896- self . link_arg ( format ! ( "{prefix}{name}{suffix}" ) ) ;
894+ // On MSVC-like targets rustc supports static libraries using alternative naming
895+ // scheme (`libfoo.a`) unsupported by linker, search for such libraries manually.
896+ if let Some ( path) = try_find_native_static_library ( self . sess , name, verbatim) {
897+ self . link_staticlib_by_path ( & path, whole_archive) ;
898+ } else {
899+ let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" } ;
900+ let suffix = if verbatim { "" } else { ".lib" } ;
901+ self . link_arg ( format ! ( "{prefix}{name}{suffix}" ) ) ;
902+ }
897903 }
898904
899905 fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
0 commit comments