@@ -296,6 +296,33 @@ pub struct Dependencies {
296
296
libs : HashMap < String , Library > ,
297
297
}
298
298
299
+ fn library_name ( l : & String , link_paths : & Vec < PathBuf > ) -> Result < ( String , PathBuf ) , String > {
300
+ let libnames = {
301
+ let mut names = vec ! [ format!( "lib{}.a" , l) ] ;
302
+
303
+ if cfg ! ( target_os = "windows" ) {
304
+ names. push ( format ! ( "{}.lib" , l) ) ;
305
+ }
306
+
307
+ names
308
+ } ;
309
+
310
+ for dir in link_paths {
311
+ for libname in & libnames {
312
+ let libpath: PathBuf = dir. join ( libname) ;
313
+ if libpath. exists ( ) {
314
+ if cfg ! ( target_os = "windows" ) {
315
+ return Ok ( ( libname. clone ( ) , libpath) ) ;
316
+ } else {
317
+ return Ok ( ( l. to_owned ( ) , libpath) ) ;
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ Err ( l. to_owned ( ) )
324
+ }
325
+
299
326
impl Dependencies {
300
327
/// Retrieve details about a system dependency.
301
328
///
@@ -405,10 +432,12 @@ impl Dependencies {
405
432
// available and let the linking fail if the user is wrong.
406
433
let is_static_lib_available = should_be_linked_statically;
407
434
408
- lib. libs = split_string ( & value)
409
- . into_iter ( )
410
- . map ( |l| InternalLib :: new ( l, is_static_lib_available) )
411
- . collect ( ) ;
435
+ let library = |l : String | match library_name ( & l, & lib. link_paths ) {
436
+ Ok ( l) => InternalLib :: new ( l. 0 , is_static_lib_available) ,
437
+ Err ( l) => InternalLib :: new ( l, is_static_lib_available) ,
438
+ } ;
439
+
440
+ lib. libs = split_string ( & value) . into_iter ( ) . map ( library) . collect ( ) ;
412
441
}
413
442
if let Some ( value) = env. get ( & EnvVariable :: new_lib_framework ( name) ) {
414
443
lib. frameworks = split_string ( & value) ;
@@ -783,7 +812,6 @@ impl Config {
783
812
let mut config = pkg_config:: Config :: new ( ) ;
784
813
config
785
814
. print_system_libs ( false )
786
- . cargo_metadata ( false )
787
815
. range_version ( metadata:: parse_version ( version) )
788
816
. statik ( statik) ;
789
817
@@ -1007,31 +1035,20 @@ impl Library {
1007
1035
}
1008
1036
} ;
1009
1037
1010
- let is_static_available = |name : & String | -> bool {
1011
- let libnames = {
1012
- let mut names = vec ! [ format!( "lib{}.a" , name) ] ;
1013
-
1014
- if cfg ! ( target_os = "windows" ) {
1015
- names. push ( format ! ( "{}.lib" , name) ) ;
1016
- }
1017
-
1018
- names
1019
- } ;
1020
-
1021
- l. link_paths . iter ( ) . any ( |dir| {
1022
- let library_exists = libnames. iter ( ) . any ( |libname| dir. join ( libname) . exists ( ) ) ;
1023
- library_exists && !system_roots. iter ( ) . any ( |sys| dir. starts_with ( sys) )
1024
- } )
1038
+ let library = |name : & String | match library_name ( name, & l. link_paths ) {
1039
+ Ok ( ( libname, libpath) ) => InternalLib :: new (
1040
+ libname,
1041
+ !system_roots
1042
+ . iter ( )
1043
+ . any ( |sys| libpath. parent ( ) . unwrap ( ) . starts_with ( sys) ) ,
1044
+ ) ,
1045
+ Err ( l) => InternalLib :: new ( l, false ) ,
1025
1046
} ;
1026
1047
1027
1048
Self {
1028
1049
name : name. to_string ( ) ,
1029
1050
source : Source :: PkgConfig ,
1030
- libs : l
1031
- . libs
1032
- . iter ( )
1033
- . map ( |lib| InternalLib :: new ( lib. to_owned ( ) , is_static_available ( lib) ) )
1034
- . collect ( ) ,
1051
+ libs : l. libs . iter ( ) . map ( library) . collect ( ) ,
1035
1052
link_paths : l. link_paths ,
1036
1053
include_paths : l. include_paths ,
1037
1054
frameworks : l. frameworks ,
@@ -1103,7 +1120,6 @@ impl Library {
1103
1120
let pkg_lib = pkg_config:: Config :: new ( )
1104
1121
. atleast_version ( version)
1105
1122
. print_system_libs ( false )
1106
- . cargo_metadata ( false )
1107
1123
. statik ( true )
1108
1124
. probe ( lib) ;
1109
1125
@@ -1178,7 +1194,11 @@ impl fmt::Display for BuildFlag {
1178
1194
BuildFlag :: SearchFramework ( lib) => write ! ( f, "rustc-link-search=framework={}" , lib) ,
1179
1195
BuildFlag :: Lib ( lib, statik) => {
1180
1196
if * statik {
1181
- write ! ( f, "rustc-link-lib=static={}" , lib)
1197
+ if cfg ! ( target_os = "windows" ) {
1198
+ write ! ( f, "rustc-link-lib=static:+verbatim={}" , lib)
1199
+ } else {
1200
+ write ! ( f, "rustc-link-lib=static={}" , lib)
1201
+ }
1182
1202
} else {
1183
1203
write ! ( f, "rustc-link-lib={}" , lib)
1184
1204
}
0 commit comments