Skip to content

Commit 3213d0e

Browse files
Move NativeLibKind from rustc_session t- rust_attr_data_structures
1 parent 3014e79 commit 3213d0e

File tree

12 files changed

+120
-89
lines changed

12 files changed

+120
-89
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,7 @@ dependencies = [
33233323
"rustc_macros",
33243324
"rustc_session",
33253325
"rustc_span",
3326+
"rustc_target",
33263327
"thin-vec",
33273328
]
33283329

@@ -3880,6 +3881,7 @@ dependencies = [
38803881
"rustc_ast_lowering",
38813882
"rustc_ast_passes",
38823883
"rustc_ast_pretty",
3884+
"rustc_attr_data_structures",
38833885
"rustc_attr_parsing",
38843886
"rustc_borrowck",
38853887
"rustc_builtin_macros",
@@ -4431,6 +4433,7 @@ dependencies = [
44314433
"rand 0.9.1",
44324434
"rustc_abi",
44334435
"rustc_ast",
4436+
"rustc_attr_data_structures",
44344437
"rustc_data_structures",
44354438
"rustc_errors",
44364439
"rustc_feature",

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,109 @@ pub enum CfgEntry {
165165
Version(Option<RustcVersion>, Span),
166166
}
167167

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

compiler/rustc_attr_parsing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ rustc_lexer = { path = "../rustc_lexer" }
1717
rustc_macros = { path = "../rustc_macros" }
1818
rustc_session = { path = "../rustc_session" }
1919
rustc_span = { path = "../rustc_span" }
20+
rustc_target = { path = "../rustc_target" }
2021
thin-vec = "0.2.12"
2122
# tidy-alphabetical-end

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
// tidy-alphabetical-start
8080
#![allow(internal_features)]
8181
#![doc(rust_logo)]
82+
#![feature(decl_macro)]
8283
#![feature(rustdoc_internals)]
8384
#![recursion_limit = "256"]
8485
// tidy-alphabetical-end

compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::io::{BufWriter, Write};
33
use std::path::{Path, PathBuf};
44

55
use rustc_abi::Endian;
6+
use rustc_attr_data_structures::NativeLibKind;
67
use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN};
78
use rustc_data_structures::fx::FxIndexMap;
89
use rustc_data_structures::stable_hasher::StableHasher;
910
use rustc_hashes::Hash128;
1011
use rustc_session::Session;
1112
use rustc_session::cstore::DllImport;
12-
use rustc_session::utils::NativeLibKind;
1313
use rustc_span::Symbol;
1414

1515
use crate::back::archive::ImportLibraryItem;

compiler/rustc_codegen_ssa/src/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#![allow(non_camel_case_types)]
22

3+
use rustc_attr_data_structures::PeImportNameType;
34
use rustc_hir::LangItem;
45
use rustc_middle::ty::layout::TyAndLayout;
56
use rustc_middle::ty::{self, Instance, TyCtxt};
67
use rustc_middle::{bug, mir, span_bug};
7-
use rustc_session::cstore::{DllCallingConvention, DllImport, PeImportNameType};
8+
use rustc_session::cstore::{DllCallingConvention, DllImport};
89
use rustc_span::Span;
910
use rustc_target::spec::Target;
1011

compiler/rustc_interface/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ tracing = "0.1"
5252
[dev-dependencies]
5353
# tidy-alphabetical-start
5454
rustc_abi = { path = "../rustc_abi" }
55+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures"}
5556
# tidy-alphabetical-end
5657

5758
[features]

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::PathBuf;
55
use std::sync::atomic::AtomicBool;
66

77
use rustc_abi::Align;
8+
use rustc_attr_data_structures::NativeLibKind;
89
use rustc_data_structures::profiling::TimePassesFormat;
910
use rustc_errors::emitter::HumanReadableErrorType;
1011
use rustc_errors::{ColorConfig, registry};
@@ -20,7 +21,7 @@ use rustc_session::config::{
2021
};
2122
use rustc_session::lint::Level;
2223
use rustc_session::search_paths::SearchPath;
23-
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
24+
use rustc_session::utils::{CanonicalizedPath, NativeLib};
2425
use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, build_session, getopts};
2526
use rustc_span::edition::{DEFAULT_EDITION, Edition};
2627
use rustc_span::source_map::{RealFileLoader, SourceMapInputs};

compiler/rustc_session/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ getopts = "0.2"
1010
rand = "0.9.0"
1111
rustc_abi = { path = "../rustc_abi" }
1212
rustc_ast = { path = "../rustc_ast" }
13+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
1314
rustc_data_structures = { path = "../rustc_data_structures" }
1415
rustc_errors = { path = "../rustc_errors" }
1516
rustc_feature = { path = "../rustc_feature" }

compiler/rustc_session/src/config/native_libs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
//! (There is also a similar but separate syntax for `#[link]` attributes,
55
//! which have their own parser in `rustc_metadata`.)
66
7+
use rustc_attr_data_structures::NativeLibKind;
78
use rustc_feature::UnstableFeatures;
89

910
use crate::EarlyDiagCtxt;
1011
use crate::config::UnstableOptions;
11-
use crate::utils::{NativeLib, NativeLibKind};
12+
use crate::utils::NativeLib;
1213

1314
#[cfg(test)]
1415
mod tests;

0 commit comments

Comments
 (0)