@@ -5,7 +5,6 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic, PrintAttribute};
55use rustc_span:: hygiene:: Transparency ;
66use rustc_span:: { Span , Symbol } ;
77use thin_vec:: ThinVec ;
8-
98use crate :: { DefaultBodyStability , PartialConstStability , PrintAttribute , RustcVersion , Stability } ;
109
1110#[ derive( Copy , Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic , PrintAttribute ) ]
@@ -142,6 +141,98 @@ pub enum UsedBy {
142141 Linker ,
143142}
144143
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+
145236/// Represents parsed *built-in* inert attributes.
146237///
147238/// ## Overview
@@ -256,6 +347,9 @@ pub enum AttributeKind {
256347 /// Represents `#[link_name]`.
257348 LinkName { name : Symbol , span : Span } ,
258349
350+ /// Represents `#[link]`.
351+ Link ( ThinVec < LinkEntry > ) ,
352+
259353 /// Represents `#[loop_match]`.
260354 LoopMatch ( Span ) ,
261355
0 commit comments