@@ -31,7 +31,7 @@ fn collate_raw_dylibs_windows<'a>(
3131 let mut dylib_table = FxIndexMap :: < String , FxIndexMap < Symbol , & DllImport > > :: default ( ) ;
3232
3333 for lib in used_libraries {
34- if lib . kind == NativeLibKind :: RawDylib {
34+ if let NativeLibKind :: RawDylib { .. } = lib . kind {
3535 let ext = if lib. verbatim { "" } else { ".dll" } ;
3636 let name = format ! ( "{}{}" , lib. name, ext) ;
3737 let imports = dylib_table. entry ( name. clone ( ) ) . or_default ( ) ;
@@ -128,12 +128,12 @@ pub(super) fn create_raw_dylib_dll_import_libs<'a>(
128128fn collate_raw_dylibs_elf < ' a > (
129129 sess : & Session ,
130130 used_libraries : impl IntoIterator < Item = & ' a NativeLib > ,
131- ) -> Vec < ( String , Vec < DllImport > ) > {
131+ ) -> Vec < ( String , Vec < DllImport > , bool ) > {
132132 // Use index maps to preserve original order of imports and libraries.
133- let mut dylib_table = FxIndexMap :: < String , FxIndexMap < Symbol , & DllImport > > :: default ( ) ;
133+ let mut dylib_table = FxIndexMap :: < String , ( FxIndexMap < Symbol , & DllImport > , bool ) > :: default ( ) ;
134134
135135 for lib in used_libraries {
136- if lib . kind == NativeLibKind :: RawDylib {
136+ if let NativeLibKind :: RawDylib { as_needed } = lib . kind {
137137 let filename = if lib. verbatim {
138138 lib. name . as_str ( ) . to_owned ( )
139139 } else {
@@ -142,17 +142,19 @@ fn collate_raw_dylibs_elf<'a>(
142142 format ! ( "{prefix}{}{ext}" , lib. name)
143143 } ;
144144
145- let imports = dylib_table. entry ( filename. clone ( ) ) . or_default ( ) ;
145+ let ( stub_imports, stub_as_needed) =
146+ dylib_table. entry ( filename. clone ( ) ) . or_insert ( ( Default :: default ( ) , true ) ) ;
146147 for import in & lib. dll_imports {
147- imports . insert ( import. name , import) ;
148+ stub_imports . insert ( import. name , import) ;
148149 }
150+ * stub_as_needed = * stub_as_needed && as_needed. unwrap_or ( true ) ;
149151 }
150152 }
151153 sess. dcx ( ) . abort_if_errors ( ) ;
152154 dylib_table
153155 . into_iter ( )
154- . map ( |( name, imports) | {
155- ( name, imports. into_iter ( ) . map ( |( _, import) | import. clone ( ) ) . collect ( ) )
156+ . map ( |( name, ( imports, as_needed ) ) | {
157+ ( name, imports. into_iter ( ) . map ( |( _, import) | import. clone ( ) ) . collect ( ) , as_needed )
156158 } )
157159 . collect ( )
158160}
@@ -161,10 +163,10 @@ pub(super) fn create_raw_dylib_elf_stub_shared_objects<'a>(
161163 sess : & Session ,
162164 used_libraries : impl IntoIterator < Item = & ' a NativeLib > ,
163165 raw_dylib_so_dir : & Path ,
164- ) -> Vec < String > {
166+ ) -> Vec < ( String , bool ) > {
165167 collate_raw_dylibs_elf ( sess, used_libraries)
166168 . into_iter ( )
167- . map ( |( load_filename, raw_dylib_imports) | {
169+ . map ( |( load_filename, raw_dylib_imports, as_needed ) | {
168170 use std:: hash:: Hash ;
169171
170172 // `load_filename` is the *target/loader* filename that will end up in NEEDED.
@@ -205,7 +207,7 @@ pub(super) fn create_raw_dylib_elf_stub_shared_objects<'a>(
205207 } ) ;
206208 } ;
207209
208- temporary_lib_name
210+ ( temporary_lib_name, as_needed )
209211 } )
210212 . collect ( )
211213}
0 commit comments