@@ -390,17 +390,13 @@ fn link_rlib<'a>(
390390 }
391391 }
392392
393- for ( raw_dylib_name, raw_dylib_imports) in
394- collate_raw_dylibs ( sess, codegen_results. crate_info . used_libraries . iter ( ) ) ?
395- {
396- let output_path = archive_builder_builder. create_dll_import_lib (
397- sess,
398- & raw_dylib_name,
399- & raw_dylib_imports,
400- tmpdir. as_ref ( ) ,
401- true ,
402- ) ;
403-
393+ for output_path in create_dll_import_libs (
394+ sess,
395+ archive_builder_builder,
396+ codegen_results. crate_info . used_libraries . iter ( ) ,
397+ tmpdir. as_ref ( ) ,
398+ true ,
399+ ) ? {
404400 ab. add_archive ( & output_path, Box :: new ( |_| false ) ) . unwrap_or_else ( |error| {
405401 sess. dcx ( ) . emit_fatal ( errors:: AddNativeLibrary { library_path : output_path, error } ) ;
406402 } ) ;
@@ -488,6 +484,27 @@ fn collate_raw_dylibs<'a>(
488484 . collect ( ) )
489485}
490486
487+ fn create_dll_import_libs < ' a > (
488+ sess : & Session ,
489+ archive_builder_builder : & dyn ArchiveBuilderBuilder ,
490+ used_libraries : impl IntoIterator < Item = & ' a NativeLib > ,
491+ tmpdir : & Path ,
492+ is_direct_dependency : bool ,
493+ ) -> Result < Vec < PathBuf > , ErrorGuaranteed > {
494+ Ok ( collate_raw_dylibs ( sess, used_libraries) ?
495+ . into_iter ( )
496+ . map ( |( raw_dylib_name, raw_dylib_imports) | {
497+ archive_builder_builder. create_dll_import_lib (
498+ sess,
499+ & raw_dylib_name,
500+ & raw_dylib_imports,
501+ tmpdir,
502+ is_direct_dependency,
503+ )
504+ } )
505+ . collect ( ) )
506+ }
507+
491508/// Create a static archive.
492509///
493510/// This is essentially the same thing as an rlib, but it also involves adding all of the upstream
@@ -2261,16 +2278,14 @@ fn linker_with_args(
22612278 ) ;
22622279
22632280 // Link with the import library generated for any raw-dylib functions.
2264- for ( raw_dylib_name, raw_dylib_imports) in
2265- collate_raw_dylibs ( sess, codegen_results. crate_info . used_libraries . iter ( ) ) ?
2266- {
2267- cmd. add_object ( & archive_builder_builder. create_dll_import_lib (
2268- sess,
2269- & raw_dylib_name,
2270- & raw_dylib_imports,
2271- tmpdir,
2272- true ,
2273- ) ) ;
2281+ for output_path in create_dll_import_libs (
2282+ sess,
2283+ archive_builder_builder,
2284+ codegen_results. crate_info . used_libraries . iter ( ) ,
2285+ tmpdir,
2286+ true ,
2287+ ) ? {
2288+ cmd. add_object ( & output_path) ;
22742289 }
22752290 // As with add_upstream_native_libraries, we need to add the upstream raw-dylib symbols in case
22762291 // they are used within inlined functions or instantiated generic functions. We do this *after*
@@ -2295,16 +2310,14 @@ fn linker_with_args(
22952310 . flatten ( )
22962311 . collect :: < Vec < _ > > ( ) ;
22972312 native_libraries_from_nonstatics. sort_unstable_by ( |a, b| a. name . as_str ( ) . cmp ( b. name . as_str ( ) ) ) ;
2298- for ( raw_dylib_name, raw_dylib_imports) in
2299- collate_raw_dylibs ( sess, native_libraries_from_nonstatics) ?
2300- {
2301- cmd. add_object ( & archive_builder_builder. create_dll_import_lib (
2302- sess,
2303- & raw_dylib_name,
2304- & raw_dylib_imports,
2305- tmpdir,
2306- false ,
2307- ) ) ;
2313+ for output_path in create_dll_import_libs (
2314+ sess,
2315+ archive_builder_builder,
2316+ native_libraries_from_nonstatics,
2317+ tmpdir,
2318+ false ,
2319+ ) ? {
2320+ cmd. add_object ( & output_path) ;
23082321 }
23092322
23102323 // Library linking above uses some global state for things like `-Bstatic`/`-Bdynamic` to make
0 commit comments