@@ -568,6 +568,15 @@ impl Library {
568568 }
569569
570570 fn parse_libs_cflags ( & mut self , name : & str , output : & [ u8 ] , config : & Config ) {
571+ #[ cfg( windows) ]
572+ lazy_static:: lazy_static!{
573+ static ref LIB_BASENAME : regex:: Regex = regex:: Regex :: new( r"^(.*)(\.(lib|dll)$" ) . unwrap( ) ;
574+ }
575+ #[ cfg( not( windows) ) ]
576+ lazy_static:: lazy_static! {
577+ static ref LIB_BASENAME : regex:: Regex = regex:: Regex :: new( r"^lib(.*)\.(a|so|dylib)" ) . unwrap( ) ;
578+ }
579+
571580 let mut is_msvc = false ;
572581 if let Ok ( target) = env:: var ( "TARGET" ) {
573582 if target. contains ( "msvc" ) {
@@ -669,7 +678,26 @@ impl Library {
669678 self . include_paths . push ( PathBuf :: from ( inc) ) ;
670679 }
671680 }
672- _ => ( ) ,
681+ _ => {
682+ let path = std:: path:: Path :: new ( part) ;
683+ if path. is_file ( ) {
684+ // Cargo doesn't have a means to directly specify a file path to link,
685+ // so split up the path into the parent directory and library name.
686+ if let Some ( dir) = path. parent ( ) {
687+ let link_search = format ! ( "rustc-link-search={}" , dir. display( ) ) ;
688+ config. print_metadata ( & link_search) ;
689+ }
690+ if let Some ( file_name) = path. file_name ( ) {
691+ // libQt5Core.a becomes Qt5Core
692+ // libQt5Core.so.5 becomes Qt5Core
693+ if let Some ( captures) = LIB_BASENAME . captures ( & file_name. to_string_lossy ( ) ) {
694+ let lib_basename = captures. get ( 1 ) . unwrap ( ) . as_str ( ) ;
695+ let link_lib = format ! ( "rustc-link-lib={}" , lib_basename) ;
696+ config. print_metadata ( & link_lib) ;
697+ }
698+ }
699+ }
700+ }
673701 }
674702 }
675703
0 commit comments