Skip to content

Commit 00fe7d1

Browse files
Move NativeLibKind from rustc_session to rustc_hir
1 parent 93edf9f commit 00fe7d1

File tree

10 files changed

+116
-89
lines changed

10 files changed

+116
-89
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,7 @@ dependencies = [
34803480
"rustc_parse",
34813481
"rustc_session",
34823482
"rustc_span",
3483+
"rustc_target",
34833484
"thin-vec",
34843485
]
34853486

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_macros = { path = "../rustc_macros" }
1717
rustc_parse = { path = "../rustc_parse" }
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
@@ -7,9 +7,9 @@ use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN};
77
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
88
use rustc_data_structures::stable_hasher::StableHasher;
99
use rustc_hashes::Hash128;
10+
use rustc_hir::attrs::NativeLibKind;
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

33
use rustc_hir::LangItem;
4+
use rustc_hir::attrs::PeImportNameType;
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_hir/src/attrs/data_structures.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,109 @@ impl IntoDiagArg for MirPhase {
248248
}
249249
}
250250

251+
/// Different ways that the PE Format can decorate a symbol name.
252+
/// From <https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type>
253+
#[derive(
254+
Copy,
255+
Clone,
256+
Debug,
257+
Encodable,
258+
Decodable,
259+
HashStable_Generic,
260+
PartialEq,
261+
Eq,
262+
PrintAttribute
263+
)]
264+
pub enum PeImportNameType {
265+
/// IMPORT_ORDINAL
266+
/// Uses the ordinal (i.e., a number) rather than the name.
267+
Ordinal(u16),
268+
/// Same as IMPORT_NAME
269+
/// Name is decorated with all prefixes and suffixes.
270+
Decorated,
271+
/// Same as IMPORT_NAME_NOPREFIX
272+
/// Prefix (e.g., the leading `_` or `@`) is skipped, but suffix is kept.
273+
NoPrefix,
274+
/// Same as IMPORT_NAME_UNDECORATE
275+
/// Prefix (e.g., the leading `_` or `@`) and suffix (the first `@` and all
276+
/// trailing characters) are skipped.
277+
Undecorated,
278+
}
279+
280+
#[derive(
281+
Copy,
282+
Clone,
283+
Debug,
284+
PartialEq,
285+
Eq,
286+
PartialOrd,
287+
Ord,
288+
Hash,
289+
Encodable,
290+
Decodable,
291+
PrintAttribute
292+
)]
293+
#[derive(HashStable_Generic)]
294+
pub enum NativeLibKind {
295+
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
296+
Static {
297+
/// Whether to bundle objects from static library into produced rlib
298+
bundle: Option<bool>,
299+
/// Whether to link static library without throwing any object files away
300+
whole_archive: Option<bool>,
301+
},
302+
/// Dynamic library (e.g. `libfoo.so` on Linux)
303+
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
304+
Dylib {
305+
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
306+
as_needed: Option<bool>,
307+
},
308+
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
309+
/// On Linux, it refers to a generated shared library stub.
310+
RawDylib,
311+
/// A macOS-specific kind of dynamic libraries.
312+
Framework {
313+
/// Whether the framework will be linked only if it satisfies some undefined symbols
314+
as_needed: Option<bool>,
315+
},
316+
/// Argument which is passed to linker, relative order with libraries and other arguments
317+
/// is preserved
318+
LinkArg,
319+
320+
/// Module imported from WebAssembly
321+
WasmImportModule,
322+
323+
/// The library kind wasn't specified, `Dylib` is currently used as a default.
324+
Unspecified,
325+
}
326+
327+
impl NativeLibKind {
328+
pub fn has_modifiers(&self) -> bool {
329+
match self {
330+
NativeLibKind::Static { bundle, whole_archive } => {
331+
bundle.is_some() || whole_archive.is_some()
332+
}
333+
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
334+
as_needed.is_some()
335+
}
336+
NativeLibKind::RawDylib
337+
| NativeLibKind::Unspecified
338+
| NativeLibKind::LinkArg
339+
| NativeLibKind::WasmImportModule => false,
340+
}
341+
}
342+
343+
pub fn is_statically_included(&self) -> bool {
344+
matches!(self, NativeLibKind::Static { .. })
345+
}
346+
347+
pub fn is_dllimport(&self) -> bool {
348+
matches!(
349+
self,
350+
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
351+
)
352+
}
353+
}
251354
/// Represents parsed *built-in* inert attributes.
252355
///
253356
/// ## Overview

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_abi::Align;
88
use rustc_data_structures::profiling::TimePassesFormat;
99
use rustc_errors::emitter::HumanReadableErrorType;
1010
use rustc_errors::{ColorConfig, registry};
11+
use rustc_hir::attrs::NativeLibKind;
1112
use rustc_session::config::{
1213
AutoDiff, BranchProtection, CFGuard, Cfg, CollapseMacroDebuginfo, CoverageLevel,
1314
CoverageOptions, DebugInfo, DumpMonoStatsFormat, ErrorOutputType, ExternEntry, ExternLocation,
@@ -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/src/config/native_libs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
//! which have their own parser in `rustc_metadata`.)
66
77
use rustc_feature::UnstableFeatures;
8+
use rustc_hir::attrs::NativeLibKind;
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;

compiler/rustc_session/src/cstore.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::any::Any;
66
use std::path::PathBuf;
77

88
use rustc_abi::ExternAbi;
9-
use rustc_ast as ast;
109
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
10+
use rustc_hir::attrs::{CfgEntry, NativeLibKind, PeImportNameType};
1111
use rustc_hir::def_id::{
1212
CrateNum, DefId, LOCAL_CRATE, LocalDefId, StableCrateId, StableCrateIdMap,
1313
};
@@ -16,7 +16,6 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1616
use rustc_span::{Span, Symbol};
1717

1818
use crate::search_paths::PathKind;
19-
use crate::utils::NativeLibKind;
2019

2120
// lonely orphan structs and enums looking for a better home
2221

@@ -72,7 +71,7 @@ pub struct NativeLib {
7271
pub name: Symbol,
7372
/// If packed_bundled_libs enabled, actual filename of library is stored.
7473
pub filename: Option<Symbol>,
75-
pub cfg: Option<ast::MetaItemInner>,
74+
pub cfg: Option<CfgEntry>,
7675
pub foreign_module: Option<DefId>,
7776
pub verbatim: Option<bool>,
7877
pub dll_imports: Vec<DllImport>,
@@ -88,25 +87,6 @@ impl NativeLib {
8887
}
8988
}
9089

91-
/// Different ways that the PE Format can decorate a symbol name.
92-
/// From <https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type>
93-
#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic, PartialEq, Eq)]
94-
pub enum PeImportNameType {
95-
/// IMPORT_ORDINAL
96-
/// Uses the ordinal (i.e., a number) rather than the name.
97-
Ordinal(u16),
98-
/// Same as IMPORT_NAME
99-
/// Name is decorated with all prefixes and suffixes.
100-
Decorated,
101-
/// Same as IMPORT_NAME_NOPREFIX
102-
/// Prefix (e.g., the leading `_` or `@`) is skipped, but suffix is kept.
103-
NoPrefix,
104-
/// Same as IMPORT_NAME_UNDECORATE
105-
/// Prefix (e.g., the leading `_` or `@`) and suffix (the first `@` and all
106-
/// trailing characters) are skipped.
107-
Undecorated,
108-
}
109-
11090
#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)]
11191
pub struct DllImport {
11292
pub name: Symbol,

compiler/rustc_session/src/utils.rs

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::OnceLock;
33

44
use rustc_data_structures::profiling::VerboseTimingGuard;
55
use rustc_fs_util::try_canonicalize;
6+
use rustc_hir::attrs::NativeLibKind;
67
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
78

89
use crate::session::Session;
@@ -17,69 +18,6 @@ impl Session {
1718
}
1819
}
1920

20-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
21-
#[derive(HashStable_Generic)]
22-
pub enum NativeLibKind {
23-
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
24-
Static {
25-
/// Whether to bundle objects from static library into produced rlib
26-
bundle: Option<bool>,
27-
/// Whether to link static library without throwing any object files away
28-
whole_archive: Option<bool>,
29-
},
30-
/// Dynamic library (e.g. `libfoo.so` on Linux)
31-
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
32-
Dylib {
33-
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
34-
as_needed: Option<bool>,
35-
},
36-
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
37-
/// On Linux, it refers to a generated shared library stub.
38-
RawDylib,
39-
/// A macOS-specific kind of dynamic libraries.
40-
Framework {
41-
/// Whether the framework will be linked only if it satisfies some undefined symbols
42-
as_needed: Option<bool>,
43-
},
44-
/// Argument which is passed to linker, relative order with libraries and other arguments
45-
/// is preserved
46-
LinkArg,
47-
48-
/// Module imported from WebAssembly
49-
WasmImportModule,
50-
51-
/// The library kind wasn't specified, `Dylib` is currently used as a default.
52-
Unspecified,
53-
}
54-
55-
impl NativeLibKind {
56-
pub fn has_modifiers(&self) -> bool {
57-
match self {
58-
NativeLibKind::Static { bundle, whole_archive } => {
59-
bundle.is_some() || whole_archive.is_some()
60-
}
61-
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
62-
as_needed.is_some()
63-
}
64-
NativeLibKind::RawDylib
65-
| NativeLibKind::Unspecified
66-
| NativeLibKind::LinkArg
67-
| NativeLibKind::WasmImportModule => false,
68-
}
69-
}
70-
71-
pub fn is_statically_included(&self) -> bool {
72-
matches!(self, NativeLibKind::Static { .. })
73-
}
74-
75-
pub fn is_dllimport(&self) -> bool {
76-
matches!(
77-
self,
78-
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
79-
)
80-
}
81-
}
82-
8321
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
8422
#[derive(HashStable_Generic)]
8523
pub struct NativeLib {

0 commit comments

Comments
 (0)