@@ -247,6 +247,7 @@ pub(crate) struct CrateLocator<'a> {
247
247
248
248
// Immutable per-search configuration.
249
249
crate_name : Symbol ,
250
+ // Dependency paths passed through --extern
250
251
exact_paths : Vec < CanonicalizedPath > ,
251
252
pub hash : Option < Svh > ,
252
253
extra_filename : Option < & ' a str > ,
@@ -511,6 +512,8 @@ impl<'a> CrateLocator<'a> {
511
512
rlib : self . extract_one ( rlibs, CrateFlavor :: Rlib , & mut slot) ?,
512
513
dylib : self . extract_one ( dylibs, CrateFlavor :: Dylib , & mut slot) ?,
513
514
} ;
515
+ // Question: check if we have no rmeta, but rlib/dylib with is_stub, and in that case
516
+ // invoke `find_library`?
514
517
Ok ( slot. map ( |( svh, metadata, _) | ( svh, Library { source, metadata } ) ) )
515
518
}
516
519
@@ -730,6 +733,14 @@ impl<'a> CrateLocator<'a> {
730
733
} ;
731
734
if file. starts_with ( "lib" ) {
732
735
if file. ends_with ( ".rlib" ) {
736
+ // In case the .rlib contains only stub metadata, we will most likely
737
+ // need to load a corresponding .rmeta file. Since it will often be
738
+ // located right next to the .rlib path, directly add it to the candidate
739
+ // paths as a "fast-path".
740
+ let possible_rmeta_path = loc_orig. with_extension ( "rmeta" ) ;
741
+ if let Ok ( rmeta_path) = try_canonicalize ( possible_rmeta_path) {
742
+ rmetas. insert ( rmeta_path, PathKind :: ExternFlag ) ;
743
+ }
733
744
rlibs. insert ( loc_canon. clone ( ) , PathKind :: ExternFlag ) ;
734
745
continue ;
735
746
}
@@ -740,7 +751,15 @@ impl<'a> CrateLocator<'a> {
740
751
}
741
752
let dll_prefix = self . target . dll_prefix . as_ref ( ) ;
742
753
let dll_suffix = self . target . dll_suffix . as_ref ( ) ;
743
- if file. starts_with ( dll_prefix) && file. ends_with ( dll_suffix) {
754
+ if let Some ( stem) =
755
+ file. strip_prefix ( dll_prefix) . and_then ( |name| name. strip_suffix ( dll_suffix) )
756
+ {
757
+ // See comment above about stub metadata, it applies also here for dylibs
758
+ let possible_rmeta_path =
759
+ loc_orig. parent ( ) . unwrap ( ) . join ( format ! ( "lib{stem}.rmeta" ) ) ;
760
+ if let Ok ( rmeta_path) = try_canonicalize ( possible_rmeta_path) {
761
+ rmetas. insert ( rmeta_path, PathKind :: ExternFlag ) ;
762
+ }
744
763
dylibs. insert ( loc_canon. clone ( ) , PathKind :: ExternFlag ) ;
745
764
continue ;
746
765
}
0 commit comments