@@ -31,7 +31,7 @@ fn collate_raw_dylibs_windows<'a>(
31
31
let mut dylib_table = FxIndexMap :: < String , FxIndexMap < Symbol , & DllImport > > :: default ( ) ;
32
32
33
33
for lib in used_libraries {
34
- if lib . kind == NativeLibKind :: RawDylib {
34
+ if let NativeLibKind :: RawDylib { .. } = lib . kind {
35
35
let ext = if lib. verbatim { "" } else { ".dll" } ;
36
36
let name = format ! ( "{}{}" , lib. name, ext) ;
37
37
let imports = dylib_table. entry ( name. clone ( ) ) . or_default ( ) ;
@@ -128,12 +128,12 @@ pub(super) fn create_raw_dylib_dll_import_libs<'a>(
128
128
fn collate_raw_dylibs_elf < ' a > (
129
129
sess : & Session ,
130
130
used_libraries : impl IntoIterator < Item = & ' a NativeLib > ,
131
- ) -> Vec < ( String , Vec < DllImport > ) > {
131
+ ) -> Vec < ( String , Vec < DllImport > , bool ) > {
132
132
// 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 ( ) ;
134
134
135
135
for lib in used_libraries {
136
- if lib . kind == NativeLibKind :: RawDylib {
136
+ if let NativeLibKind :: RawDylib { as_needed } = lib . kind {
137
137
let filename = if lib. verbatim {
138
138
lib. name . as_str ( ) . to_owned ( )
139
139
} else {
@@ -142,17 +142,19 @@ fn collate_raw_dylibs_elf<'a>(
142
142
format ! ( "{prefix}{}{ext}" , lib. name)
143
143
} ;
144
144
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 ) ) ;
146
147
for import in & lib. dll_imports {
147
- imports . insert ( import. name , import) ;
148
+ stub_imports . insert ( import. name , import) ;
148
149
}
150
+ * stub_as_needed = * stub_as_needed && as_needed. unwrap_or ( true ) ;
149
151
}
150
152
}
151
153
sess. dcx ( ) . abort_if_errors ( ) ;
152
154
dylib_table
153
155
. 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 )
156
158
} )
157
159
. collect ( )
158
160
}
@@ -161,10 +163,10 @@ pub(super) fn create_raw_dylib_elf_stub_shared_objects<'a>(
161
163
sess : & Session ,
162
164
used_libraries : impl IntoIterator < Item = & ' a NativeLib > ,
163
165
raw_dylib_so_dir : & Path ,
164
- ) -> Vec < String > {
166
+ ) -> Vec < ( String , bool ) > {
165
167
collate_raw_dylibs_elf ( sess, used_libraries)
166
168
. into_iter ( )
167
- . map ( |( load_filename, raw_dylib_imports) | {
169
+ . map ( |( load_filename, raw_dylib_imports, as_needed ) | {
168
170
use std:: hash:: Hash ;
169
171
170
172
// `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>(
205
207
} ) ;
206
208
} ;
207
209
208
- temporary_lib_name
210
+ ( temporary_lib_name, as_needed )
209
211
} )
210
212
. collect ( )
211
213
}
0 commit comments