Move NativeLibKind from rustc_session to rustc_hir
This commit is contained in:
parent
3c91be712d
commit
aab5e0bf1f
10 changed files with 116 additions and 89 deletions
|
|
@ -3480,6 +3480,7 @@ dependencies = [
|
|||
"rustc_parse",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"thin-vec",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -17,5 +17,6 @@ rustc_macros = { path = "../rustc_macros" }
|
|||
rustc_parse = { path = "../rustc_parse" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
thin-vec.workspace = true
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@
|
|||
// tidy-alphabetical-start
|
||||
#![allow(internal_features)]
|
||||
#![doc(rust_logo)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![recursion_limit = "256"]
|
||||
// tidy-alphabetical-end
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN};
|
|||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_hashes::Hash128;
|
||||
use rustc_hir::attrs::NativeLibKind;
|
||||
use rustc_session::Session;
|
||||
use rustc_session::cstore::DllImport;
|
||||
use rustc_session::utils::NativeLibKind;
|
||||
use rustc_span::Symbol;
|
||||
|
||||
use crate::back::archive::ImportLibraryItem;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_hir::attrs::PeImportNameType;
|
||||
use rustc_middle::ty::layout::TyAndLayout;
|
||||
use rustc_middle::ty::{self, Instance, TyCtxt};
|
||||
use rustc_middle::{bug, mir, span_bug};
|
||||
use rustc_session::cstore::{DllCallingConvention, DllImport, PeImportNameType};
|
||||
use rustc_session::cstore::{DllCallingConvention, DllImport};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::spec::Target;
|
||||
|
||||
|
|
|
|||
|
|
@ -248,6 +248,109 @@ impl IntoDiagArg for MirPhase {
|
|||
}
|
||||
}
|
||||
|
||||
/// Different ways that the PE Format can decorate a symbol name.
|
||||
/// From <https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type>
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
Debug,
|
||||
Encodable,
|
||||
Decodable,
|
||||
HashStable_Generic,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PrintAttribute
|
||||
)]
|
||||
pub enum PeImportNameType {
|
||||
/// IMPORT_ORDINAL
|
||||
/// Uses the ordinal (i.e., a number) rather than the name.
|
||||
Ordinal(u16),
|
||||
/// Same as IMPORT_NAME
|
||||
/// Name is decorated with all prefixes and suffixes.
|
||||
Decorated,
|
||||
/// Same as IMPORT_NAME_NOPREFIX
|
||||
/// Prefix (e.g., the leading `_` or `@`) is skipped, but suffix is kept.
|
||||
NoPrefix,
|
||||
/// Same as IMPORT_NAME_UNDECORATE
|
||||
/// Prefix (e.g., the leading `_` or `@`) and suffix (the first `@` and all
|
||||
/// trailing characters) are skipped.
|
||||
Undecorated,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Hash,
|
||||
Encodable,
|
||||
Decodable,
|
||||
PrintAttribute
|
||||
)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum NativeLibKind {
|
||||
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
|
||||
Static {
|
||||
/// Whether to bundle objects from static library into produced rlib
|
||||
bundle: Option<bool>,
|
||||
/// Whether to link static library without throwing any object files away
|
||||
whole_archive: Option<bool>,
|
||||
},
|
||||
/// Dynamic library (e.g. `libfoo.so` on Linux)
|
||||
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
|
||||
Dylib {
|
||||
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
|
||||
as_needed: Option<bool>,
|
||||
},
|
||||
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
|
||||
/// On Linux, it refers to a generated shared library stub.
|
||||
RawDylib,
|
||||
/// A macOS-specific kind of dynamic libraries.
|
||||
Framework {
|
||||
/// Whether the framework will be linked only if it satisfies some undefined symbols
|
||||
as_needed: Option<bool>,
|
||||
},
|
||||
/// Argument which is passed to linker, relative order with libraries and other arguments
|
||||
/// is preserved
|
||||
LinkArg,
|
||||
|
||||
/// Module imported from WebAssembly
|
||||
WasmImportModule,
|
||||
|
||||
/// The library kind wasn't specified, `Dylib` is currently used as a default.
|
||||
Unspecified,
|
||||
}
|
||||
|
||||
impl NativeLibKind {
|
||||
pub fn has_modifiers(&self) -> bool {
|
||||
match self {
|
||||
NativeLibKind::Static { bundle, whole_archive } => {
|
||||
bundle.is_some() || whole_archive.is_some()
|
||||
}
|
||||
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
|
||||
as_needed.is_some()
|
||||
}
|
||||
NativeLibKind::RawDylib
|
||||
| NativeLibKind::Unspecified
|
||||
| NativeLibKind::LinkArg
|
||||
| NativeLibKind::WasmImportModule => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_statically_included(&self) -> bool {
|
||||
matches!(self, NativeLibKind::Static { .. })
|
||||
}
|
||||
|
||||
pub fn is_dllimport(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
|
||||
)
|
||||
}
|
||||
}
|
||||
/// Represents parsed *built-in* inert attributes.
|
||||
///
|
||||
/// ## Overview
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use rustc_abi::Align;
|
|||
use rustc_data_structures::profiling::TimePassesFormat;
|
||||
use rustc_errors::emitter::HumanReadableErrorType;
|
||||
use rustc_errors::{ColorConfig, registry};
|
||||
use rustc_hir::attrs::NativeLibKind;
|
||||
use rustc_session::config::{
|
||||
AutoDiff, BranchProtection, CFGuard, Cfg, CollapseMacroDebuginfo, CoverageLevel,
|
||||
CoverageOptions, DebugInfo, DumpMonoStatsFormat, ErrorOutputType, ExternEntry, ExternLocation,
|
||||
|
|
@ -20,7 +21,7 @@ use rustc_session::config::{
|
|||
};
|
||||
use rustc_session::lint::Level;
|
||||
use rustc_session::search_paths::SearchPath;
|
||||
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
|
||||
use rustc_session::utils::{CanonicalizedPath, NativeLib};
|
||||
use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, build_session, getopts};
|
||||
use rustc_span::edition::{DEFAULT_EDITION, Edition};
|
||||
use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
//! which have their own parser in `rustc_metadata`.)
|
||||
|
||||
use rustc_feature::UnstableFeatures;
|
||||
use rustc_hir::attrs::NativeLibKind;
|
||||
|
||||
use crate::EarlyDiagCtxt;
|
||||
use crate::config::UnstableOptions;
|
||||
use crate::utils::{NativeLib, NativeLibKind};
|
||||
use crate::utils::NativeLib;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ use std::any::Any;
|
|||
use std::path::PathBuf;
|
||||
|
||||
use rustc_abi::ExternAbi;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
|
||||
use rustc_hir::attrs::{CfgEntry, NativeLibKind, PeImportNameType};
|
||||
use rustc_hir::def_id::{
|
||||
CrateNum, DefId, LOCAL_CRATE, LocalDefId, StableCrateId, StableCrateIdMap,
|
||||
};
|
||||
|
|
@ -16,7 +16,6 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
|||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use crate::search_paths::PathKind;
|
||||
use crate::utils::NativeLibKind;
|
||||
|
||||
// lonely orphan structs and enums looking for a better home
|
||||
|
||||
|
|
@ -72,7 +71,7 @@ pub struct NativeLib {
|
|||
pub name: Symbol,
|
||||
/// If packed_bundled_libs enabled, actual filename of library is stored.
|
||||
pub filename: Option<Symbol>,
|
||||
pub cfg: Option<ast::MetaItemInner>,
|
||||
pub cfg: Option<CfgEntry>,
|
||||
pub foreign_module: Option<DefId>,
|
||||
pub verbatim: Option<bool>,
|
||||
pub dll_imports: Vec<DllImport>,
|
||||
|
|
@ -88,25 +87,6 @@ impl NativeLib {
|
|||
}
|
||||
}
|
||||
|
||||
/// Different ways that the PE Format can decorate a symbol name.
|
||||
/// From <https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type>
|
||||
#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic, PartialEq, Eq)]
|
||||
pub enum PeImportNameType {
|
||||
/// IMPORT_ORDINAL
|
||||
/// Uses the ordinal (i.e., a number) rather than the name.
|
||||
Ordinal(u16),
|
||||
/// Same as IMPORT_NAME
|
||||
/// Name is decorated with all prefixes and suffixes.
|
||||
Decorated,
|
||||
/// Same as IMPORT_NAME_NOPREFIX
|
||||
/// Prefix (e.g., the leading `_` or `@`) is skipped, but suffix is kept.
|
||||
NoPrefix,
|
||||
/// Same as IMPORT_NAME_UNDECORATE
|
||||
/// Prefix (e.g., the leading `_` or `@`) and suffix (the first `@` and all
|
||||
/// trailing characters) are skipped.
|
||||
Undecorated,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)]
|
||||
pub struct DllImport {
|
||||
pub name: Symbol,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::sync::OnceLock;
|
|||
|
||||
use rustc_data_structures::profiling::VerboseTimingGuard;
|
||||
use rustc_fs_util::try_canonicalize;
|
||||
use rustc_hir::attrs::NativeLibKind;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
|
||||
use crate::session::Session;
|
||||
|
|
@ -17,69 +18,6 @@ impl Session {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum NativeLibKind {
|
||||
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
|
||||
Static {
|
||||
/// Whether to bundle objects from static library into produced rlib
|
||||
bundle: Option<bool>,
|
||||
/// Whether to link static library without throwing any object files away
|
||||
whole_archive: Option<bool>,
|
||||
},
|
||||
/// Dynamic library (e.g. `libfoo.so` on Linux)
|
||||
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
|
||||
Dylib {
|
||||
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
|
||||
as_needed: Option<bool>,
|
||||
},
|
||||
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
|
||||
/// On Linux, it refers to a generated shared library stub.
|
||||
RawDylib,
|
||||
/// A macOS-specific kind of dynamic libraries.
|
||||
Framework {
|
||||
/// Whether the framework will be linked only if it satisfies some undefined symbols
|
||||
as_needed: Option<bool>,
|
||||
},
|
||||
/// Argument which is passed to linker, relative order with libraries and other arguments
|
||||
/// is preserved
|
||||
LinkArg,
|
||||
|
||||
/// Module imported from WebAssembly
|
||||
WasmImportModule,
|
||||
|
||||
/// The library kind wasn't specified, `Dylib` is currently used as a default.
|
||||
Unspecified,
|
||||
}
|
||||
|
||||
impl NativeLibKind {
|
||||
pub fn has_modifiers(&self) -> bool {
|
||||
match self {
|
||||
NativeLibKind::Static { bundle, whole_archive } => {
|
||||
bundle.is_some() || whole_archive.is_some()
|
||||
}
|
||||
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
|
||||
as_needed.is_some()
|
||||
}
|
||||
NativeLibKind::RawDylib
|
||||
| NativeLibKind::Unspecified
|
||||
| NativeLibKind::LinkArg
|
||||
| NativeLibKind::WasmImportModule => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_statically_included(&self) -> bool {
|
||||
matches!(self, NativeLibKind::Static { .. })
|
||||
}
|
||||
|
||||
pub fn is_dllimport(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub struct NativeLib {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue