@@ -365,6 +365,25 @@ impl<'a> CrateLocator<'a> {
365
365
self . find_library_crate ( "" , & mut seen_paths)
366
366
}
367
367
368
+ /// Returns true if `file` has a suffix that could be a valid dylib
369
+ /// Example (assuming target has .so as dll_suffix):
370
+ /// - `libsomecrate.asdf` -> `false`
371
+ /// - `libsomecrate.so` -> `true`
372
+ /// - `libsomecrate.so.0.1` -> `true`
373
+ /// - `libsomecrate.so.a.4` -> `false`
374
+ fn test_dylib_suffix ( & self , file : & str ) -> bool {
375
+ // test if the targets dll_suffix is found within the filename. If it
376
+ // is check if all of the chars following it are either in range 0x30
377
+ // to 0x39 (0-9) or 0x2E (.).
378
+ match file. find ( & self . target . dll_suffix ) {
379
+ Some ( idx) => file
380
+ . chars ( )
381
+ . skip ( idx + self . target . dll_suffix . len ( ) )
382
+ . all ( |c| c as u32 >= 0x30 && c as u32 <= 0x39 || c as u32 == 0x2E ) ,
383
+ None => false ,
384
+ }
385
+ }
386
+
368
387
fn find_library_crate (
369
388
& mut self ,
370
389
extra_prefix : & str ,
@@ -402,7 +421,7 @@ impl<'a> CrateLocator<'a> {
402
421
( & file[ ( rlib_prefix. len ( ) ) ..( file. len ( ) - ".rlib" . len ( ) ) ] , CrateFlavor :: Rlib )
403
422
} else if file. starts_with ( & rlib_prefix) && file. ends_with ( ".rmeta" ) {
404
423
( & file[ ( rlib_prefix. len ( ) ) ..( file. len ( ) - ".rmeta" . len ( ) ) ] , CrateFlavor :: Rmeta )
405
- } else if file. starts_with ( & dylib_prefix) && file . ends_with ( & self . target . dll_suffix ) {
424
+ } else if file. starts_with ( & dylib_prefix) && self . test_dylib_suffix ( file ) {
406
425
(
407
426
& file[ ( dylib_prefix. len ( ) ) ..( file. len ( ) - self . target . dll_suffix . len ( ) ) ] ,
408
427
CrateFlavor :: Dylib ,
@@ -681,8 +700,7 @@ impl<'a> CrateLocator<'a> {
681
700
} ;
682
701
683
702
if file. starts_with ( "lib" ) && ( file. ends_with ( ".rlib" ) || file. ends_with ( ".rmeta" ) )
684
- || file. starts_with ( & self . target . dll_prefix )
685
- && file. ends_with ( & self . target . dll_suffix )
703
+ || file. starts_with ( & self . target . dll_prefix ) && self . test_dylib_suffix ( file)
686
704
{
687
705
// Make sure there's at most one rlib and at most one dylib.
688
706
// Note to take care and match against the non-canonicalized name:
0 commit comments