@@ -311,7 +311,9 @@ fn link_rlib<'a>(
311311 . collect ( ) ;
312312
313313 let metadata_link_file = if matches ! ( flavor, RlibFlavor :: Normal ) {
314- let metadata_link = rmeta_link:: RmetaLink { rust_object_files } ;
314+ let native_lib_filenames: Vec < Option < String > > =
315+ crate_info. used_libraries_filenames . iter ( ) . map ( |f| f. map ( |s| s. to_string ( ) ) ) . collect ( ) ;
316+ let metadata_link = rmeta_link:: RmetaLink { rust_object_files, native_lib_filenames } ;
315317 let metadata_link_data = metadata_link. encode ( ) ;
316318 let ( wrapper, _) =
317319 create_wrapper_file ( sess, rmeta_link:: SECTION . to_string ( ) , & metadata_link_data) ;
@@ -386,12 +388,12 @@ fn link_rlib<'a>(
386388 // feature then we'll need to figure out how to record what objects were
387389 // loaded from the libraries found here and then encode that into the
388390 // metadata of the rlib we're generating somehow.
389- for lib in crate_info. used_libraries . iter ( ) {
391+ for ( i , lib) in crate_info. used_libraries . iter ( ) . enumerate ( ) {
390392 let NativeLibKind :: Static { bundle : None | Some ( true ) , .. } = lib. kind else {
391393 continue ;
392394 } ;
393395 if flavor == RlibFlavor :: Normal
394- && let Some ( filename) = lib . filename
396+ && let Some ( filename) = crate_info . used_libraries_filenames [ i ]
395397 {
396398 let path = find_native_static_library ( filename. as_str ( ) , true , sess) ;
397399 let src = read ( path)
@@ -504,11 +506,16 @@ fn link_staticlib(
504506 let lto = are_upstream_rust_objects_already_included ( sess)
505507 && !ignored_for_lto ( sess, crate_info, cnum) ;
506508
507- let native_libs = crate_info. native_libraries [ & cnum] . iter ( ) ;
508- let relevant = native_libs. clone ( ) . filter ( |lib| relevant_lib ( sess, lib) ) ;
509- let relevant_libs: FxIndexSet < _ > = relevant. filter_map ( |lib| lib. filename ) . collect ( ) ;
509+ let native_libs = & crate_info. native_libraries [ & cnum] ;
510+ let filenames = & crate_info. native_libraries_filenames [ & cnum] ;
511+ let relevant_libs: FxIndexSet < _ > = native_libs
512+ . iter ( )
513+ . zip ( filenames. iter ( ) )
514+ . filter ( |( lib, _) | relevant_lib ( sess, lib) )
515+ . filter_map ( |( _, f) | * f)
516+ . collect ( ) ;
510517
511- let bundled_libs: FxIndexSet < _ > = native_libs . filter_map ( |lib| lib . filename ) . collect ( ) ;
518+ let bundled_libs: FxIndexSet < _ > = filenames . iter ( ) . filter_map ( |f| * f ) . collect ( ) ;
512519 ab. add_archive (
513520 path,
514521 Some ( Box :: new ( move |fname : & str , metadata_link| {
@@ -2893,13 +2900,13 @@ fn add_native_libs_from_crate(
28932900 . unwrap_or_else ( |e| sess. dcx ( ) . emit_fatal ( e) ) ;
28942901 }
28952902
2896- let native_libs = match cnum {
2897- LOCAL_CRATE => & crate_info. used_libraries ,
2898- _ => & crate_info. native_libraries [ & cnum] ,
2903+ let ( native_libs, filenames ) : ( & Vec < NativeLib > , & Vec < Option < Symbol > > ) = match cnum {
2904+ LOCAL_CRATE => ( & crate_info. used_libraries , & crate_info . used_libraries_filenames ) ,
2905+ _ => ( & crate_info. native_libraries [ & cnum] , & crate_info . native_libraries_filenames [ & cnum ] ) ,
28992906 } ;
29002907
29012908 let mut last = ( None , NativeLibKind :: Unspecified , false ) ;
2902- for lib in native_libs {
2909+ for ( i , lib) in native_libs. iter ( ) . enumerate ( ) {
29032910 if !relevant_lib ( sess, lib) {
29042911 continue ;
29052912 }
@@ -2919,7 +2926,7 @@ fn add_native_libs_from_crate(
29192926 let bundle = bundle. unwrap_or ( true ) ;
29202927 let whole_archive = whole_archive == Some ( true ) ;
29212928 if bundle && cnum != LOCAL_CRATE {
2922- if let Some ( filename) = lib . filename {
2929+ if let Some ( filename) = filenames [ i ] {
29232930 // If rlib contains native libs as archives, they are unpacked to tmpdir.
29242931 let path = tmpdir. join ( filename. as_str ( ) ) ;
29252932 cmd. link_staticlib_by_path ( & path, whole_archive) ;
@@ -3040,9 +3047,9 @@ fn add_upstream_rust_crates(
30403047 match linkage {
30413048 Linkage :: Static | Linkage :: IncludedFromDylib | Linkage :: NotLinked => {
30423049 if link_static_crate {
3043- bundled_libs = crate_info. native_libraries [ & cnum]
3050+ bundled_libs = crate_info. native_libraries_filenames [ & cnum]
30443051 . iter ( )
3045- . filter_map ( |lib| lib . filename )
3052+ . filter_map ( |f| * f )
30463053 . collect ( ) ;
30473054 add_static_crate (
30483055 cmd,
0 commit comments