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