@@ -568,6 +568,19 @@ impl Library {
568
568
}
569
569
570
570
fn parse_libs_cflags ( & mut self , name : & str , output : & [ u8 ] , config : & Config ) {
571
+ #[ cfg( all( windows, target_env = "msvc" ) ) ]
572
+ lazy_static:: lazy_static! {
573
+ static ref LIB_BASENAME : regex:: Regex = regex:: Regex :: new( r"^(.*)\.(lib|dll)$" ) . unwrap( ) ;
574
+ }
575
+ #[ cfg( all( windows, target_env = "gnu" ) ) ]
576
+ lazy_static:: lazy_static! {
577
+ static ref LIB_BASENAME : regex:: Regex = regex:: Regex :: new( r"^lib(.*)\.(a|dll)$" ) . unwrap( ) ;
578
+ }
579
+ #[ cfg( not( windows) ) ]
580
+ lazy_static:: lazy_static! {
581
+ static ref LIB_BASENAME : regex:: Regex = regex:: Regex :: new( r"^lib(.*)\.(a|so|dylib)" ) . unwrap( ) ;
582
+ }
583
+
571
584
let mut is_msvc = false ;
572
585
if let Ok ( target) = env:: var ( "TARGET" ) {
573
586
if target. contains ( "msvc" ) {
@@ -669,7 +682,28 @@ impl Library {
669
682
self . include_paths . push ( PathBuf :: from ( inc) ) ;
670
683
}
671
684
}
672
- _ => ( ) ,
685
+ _ => {
686
+ let path = std:: path:: Path :: new ( part) ;
687
+ if path. is_file ( ) {
688
+ // Cargo doesn't have a means to directly specify a file path to link,
689
+ // so split up the path into the parent directory and library name.
690
+ if let Some ( dir) = path. parent ( ) {
691
+ let link_search = format ! ( "rustc-link-search={}" , dir. display( ) ) ;
692
+ config. print_metadata ( & link_search) ;
693
+ }
694
+ if let Some ( file_name) = path. file_name ( ) {
695
+ // libQt5Core.a becomes Qt5Core
696
+ // libQt5Core.so.5 becomes Qt5Core
697
+ if let Some ( captures) =
698
+ LIB_BASENAME . captures ( & file_name. to_string_lossy ( ) )
699
+ {
700
+ let lib_basename = captures. get ( 1 ) . unwrap ( ) . as_str ( ) ;
701
+ let link_lib = format ! ( "rustc-link-lib={}" , lib_basename) ;
702
+ config. print_metadata ( & link_lib) ;
703
+ }
704
+ }
705
+ }
706
+ }
673
707
}
674
708
}
675
709
0 commit comments