@@ -142,6 +142,120 @@ pub enum UsedBy {
142
142
Linker ,
143
143
}
144
144
145
+ /// Different ways that the PE Format can decorate a symbol name.
146
+ /// From <https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type>
147
+ #[ derive(
148
+ Copy ,
149
+ Clone ,
150
+ Debug ,
151
+ Encodable ,
152
+ Decodable ,
153
+ HashStable_Generic ,
154
+ PartialEq ,
155
+ Eq ,
156
+ PrintAttribute
157
+ ) ]
158
+ pub enum PeImportNameType {
159
+ /// IMPORT_ORDINAL
160
+ /// Uses the ordinal (i.e., a number) rather than the name.
161
+ Ordinal ( u16 ) ,
162
+ /// Same as IMPORT_NAME
163
+ /// Name is decorated with all prefixes and suffixes.
164
+ Decorated ,
165
+ /// Same as IMPORT_NAME_NOPREFIX
166
+ /// Prefix (e.g., the leading `_` or `@`) is skipped, but suffix is kept.
167
+ NoPrefix ,
168
+ /// Same as IMPORT_NAME_UNDECORATE
169
+ /// Prefix (e.g., the leading `_` or `@`) and suffix (the first `@` and all
170
+ /// trailing characters) are skipped.
171
+ Undecorated ,
172
+ }
173
+
174
+ #[ derive(
175
+ Copy ,
176
+ Clone ,
177
+ Debug ,
178
+ PartialEq ,
179
+ Eq ,
180
+ PartialOrd ,
181
+ Ord ,
182
+ Hash ,
183
+ Encodable ,
184
+ Decodable ,
185
+ PrintAttribute
186
+ ) ]
187
+ #[ derive( HashStable_Generic ) ]
188
+ pub enum NativeLibKind {
189
+ /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
190
+ Static {
191
+ /// Whether to bundle objects from static library into produced rlib
192
+ bundle : Option < bool > ,
193
+ /// Whether to link static library without throwing any object files away
194
+ whole_archive : Option < bool > ,
195
+ } ,
196
+ /// Dynamic library (e.g. `libfoo.so` on Linux)
197
+ /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
198
+ Dylib {
199
+ /// Whether the dynamic library will be linked only if it satisfies some undefined symbols
200
+ as_needed : Option < bool > ,
201
+ } ,
202
+ /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
203
+ /// On Linux, it refers to a generated shared library stub.
204
+ RawDylib ,
205
+ /// A macOS-specific kind of dynamic libraries.
206
+ Framework {
207
+ /// Whether the framework will be linked only if it satisfies some undefined symbols
208
+ as_needed : Option < bool > ,
209
+ } ,
210
+ /// Argument which is passed to linker, relative order with libraries and other arguments
211
+ /// is preserved
212
+ LinkArg ,
213
+
214
+ /// Module imported from WebAssembly
215
+ WasmImportModule ,
216
+
217
+ /// The library kind wasn't specified, `Dylib` is currently used as a default.
218
+ Unspecified ,
219
+ }
220
+
221
+ impl NativeLibKind {
222
+ pub fn has_modifiers ( & self ) -> bool {
223
+ match self {
224
+ NativeLibKind :: Static { bundle, whole_archive } => {
225
+ bundle. is_some ( ) || whole_archive. is_some ( )
226
+ }
227
+ NativeLibKind :: Dylib { as_needed } | NativeLibKind :: Framework { as_needed } => {
228
+ as_needed. is_some ( )
229
+ }
230
+ NativeLibKind :: RawDylib
231
+ | NativeLibKind :: Unspecified
232
+ | NativeLibKind :: LinkArg
233
+ | NativeLibKind :: WasmImportModule => false ,
234
+ }
235
+ }
236
+
237
+ pub fn is_statically_included ( & self ) -> bool {
238
+ matches ! ( self , NativeLibKind :: Static { .. } )
239
+ }
240
+
241
+ pub fn is_dllimport ( & self ) -> bool {
242
+ matches ! (
243
+ self ,
244
+ NativeLibKind :: Dylib { .. } | NativeLibKind :: RawDylib | NativeLibKind :: Unspecified
245
+ )
246
+ }
247
+ }
248
+
249
+ #[ derive( Copy , Debug , Encodable , Decodable , Clone , HashStable_Generic , PrintAttribute ) ]
250
+ pub struct LinkEntry {
251
+ pub span : Span ,
252
+ pub kind : NativeLibKind ,
253
+ pub name : Symbol ,
254
+ pub cfg : Option < ( ) > , //TODO
255
+ pub verbatim : Option < bool > ,
256
+ pub import_name_type : Option < ( PeImportNameType , Span ) > ,
257
+ }
258
+
145
259
/// Represents parsed *built-in* inert attributes.
146
260
///
147
261
/// ## Overview
@@ -256,6 +370,9 @@ pub enum AttributeKind {
256
370
/// Represents `#[link_name]`.
257
371
LinkName { name : Symbol , span : Span } ,
258
372
373
+ /// Represents `#[link]`.
374
+ Link ( ThinVec < LinkEntry > ) ,
375
+
259
376
/// Represents `#[loop_match]`.
260
377
LoopMatch ( Span ) ,
261
378
0 commit comments