@@ -784,6 +784,38 @@ pub struct MsvcLinker<'a> {
784
784
sess : & ' a Session ,
785
785
}
786
786
787
+ impl MsvcLinker < ' _ > {
788
+ // FIXME this duplicates rustc_metadata::find_native_static_library,
789
+ // as the Meson/MinGW suffix for import libraries can differ
790
+ fn find_native_dynamic_library ( name : & str , verbatim : bool , sess : & Session ) -> OsString {
791
+ let formats = if verbatim {
792
+ vec ! [ ( "" . into( ) , "" . into( ) ) ]
793
+ } else {
794
+ // While the official naming convention for MSVC import libraries
795
+ // is foo.lib...
796
+ let os = ( sess. target . staticlib_prefix . clone ( ) , sess. target . staticlib_suffix . clone ( ) ) ;
797
+ // ... Meson follows the libfoo.dll.a convention to
798
+ // disambiguate .a for static libraries
799
+ let meson = ( "lib" . into ( ) , ".dll.a" . into ( ) ) ;
800
+ // and MinGW uses .a altogether
801
+ let mingw = ( "lib" . into ( ) , ".a" . into ( ) ) ;
802
+ vec ! [ os, meson, mingw]
803
+ } ;
804
+
805
+ for path in sess. target_filesearch ( PathKind :: Native ) . search_paths ( ) {
806
+ for ( prefix, suffix) in & formats {
807
+ let test = path. join ( format ! ( "{prefix}{name}{suffix}" ) ) ;
808
+ if test. exists ( ) {
809
+ return OsString :: from ( test) ;
810
+ }
811
+ }
812
+ }
813
+
814
+ // Allow the linker to find CRT libs itself
815
+ OsString :: from ( format ! ( "{}{}" , name, if verbatim { "" } else { ".lib" } ) )
816
+ }
817
+ }
818
+
787
819
impl < ' a > Linker for MsvcLinker < ' a > {
788
820
fn cmd ( & mut self ) -> & mut Command {
789
821
& mut self . cmd
@@ -808,7 +840,8 @@ impl<'a> Linker for MsvcLinker<'a> {
808
840
}
809
841
810
842
fn link_dylib_by_name ( & mut self , name : & str , verbatim : bool , _as_needed : bool ) {
811
- self . cmd . arg ( format ! ( "{}{}" , name, if verbatim { "" } else { ".lib" } ) ) ;
843
+ let path = MsvcLinker :: < ' a > :: find_native_dynamic_library ( name, verbatim, self . sess ) ;
844
+ self . cmd . arg ( path) ;
812
845
}
813
846
814
847
fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
0 commit comments