mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Move NativeLibKind
This commit is contained in:
@@ -3875,6 +3875,7 @@ dependencies = [
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
"rustc_span",
|
||||
"rustc_structures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -16,7 +16,7 @@ use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::hygiene::Transparency;
|
||||
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
|
||||
use rustc_structures::{CrateType, Limit, SanitizerSet};
|
||||
use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
pub use crate::canonical_symbols::{CanonicalSymbol, CanonicalSymbols};
|
||||
@@ -371,76 +371,6 @@ pub enum PeImportNameType {
|
||||
Undecorated,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Encodable, Decodable, PrintAttribute)]
|
||||
#[derive(StableHash)]
|
||||
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>,
|
||||
/// Whether to export c static library symbols
|
||||
export_symbols: 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 {
|
||||
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
|
||||
as_needed: Option<bool>,
|
||||
},
|
||||
/// 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, export_symbols } => {
|
||||
bundle.is_some() || whole_archive.is_some() || export_symbols.is_some()
|
||||
}
|
||||
NativeLibKind::Dylib { as_needed }
|
||||
| NativeLibKind::Framework { as_needed }
|
||||
| NativeLibKind::RawDylib { as_needed } => as_needed.is_some(),
|
||||
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(Debug, Encodable, Decodable, Clone, StableHash, PrintAttribute)]
|
||||
pub struct LinkEntry {
|
||||
pub span: Span,
|
||||
|
||||
@@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::hygiene::Transparency;
|
||||
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
|
||||
use rustc_structures::{CrateType, Limit, SanitizerSet};
|
||||
use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
/// This trait is used to print attributes in `rustc_hir_pretty`.
|
||||
@@ -208,4 +208,5 @@ print_debug!(
|
||||
DiffActivity,
|
||||
DiffMode,
|
||||
CrateType,
|
||||
NativeLibKind,
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ use rustc_session::Session;
|
||||
use rustc_session::diagnostics::feature_err;
|
||||
use rustc_span::edition::Edition::Edition2024;
|
||||
use rustc_span::kw;
|
||||
use rustc_structures::NativeLibKind;
|
||||
use rustc_target::spec::{Arch, BinaryFormat};
|
||||
|
||||
use super::prelude::*;
|
||||
|
||||
@@ -21,7 +21,6 @@ use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_data_structures::temp_dir::MaybeTempDir;
|
||||
use rustc_errors::DiagCtxtHandle;
|
||||
use rustc_fs_util::{TempDirBuilder, fix_windows_verbatim_for_gcc, try_canonicalize};
|
||||
use rustc_hir::attrs::NativeLibKind;
|
||||
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use rustc_lint_defs::builtin::{LINKER_INFO, LINKER_MESSAGES};
|
||||
use rustc_macros::Diagnostic;
|
||||
@@ -43,7 +42,7 @@ use rustc_session::search_paths::PathKind;
|
||||
/// need out of the shared crate context before we get rid of it.
|
||||
use rustc_session::{Session, filesearch};
|
||||
use rustc_span::Symbol;
|
||||
use rustc_structures::CrateType;
|
||||
use rustc_structures::{CrateType, NativeLibKind};
|
||||
use rustc_target::spec::crt_objects::CrtObjects;
|
||||
use rustc_target::spec::{
|
||||
Arch, BinaryFormat, Cc, CfgAbi, Env, LinkOutputKind, LinkSelfContainedComponents,
|
||||
|
||||
@@ -8,9 +8,9 @@ use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||
use rustc_data_structures::stable_hash::StableHasher;
|
||||
use rustc_hashes::Hash128;
|
||||
use rustc_hir::attrs::NativeLibKind;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_structures::NativeLibKind;
|
||||
use rustc_target::spec::Arch;
|
||||
|
||||
use crate::back::archive::ImportLibraryItem;
|
||||
|
||||
@@ -8,11 +8,11 @@ use std::path::{Path, PathBuf};
|
||||
use object::read::archive::ArchiveFile;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_hir::attrs::NativeLibKind;
|
||||
use rustc_serialize::opaque::mem_encoder::MemEncoder;
|
||||
use rustc_serialize::opaque::{MAGIC_END_BYTES, MemDecoder};
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_span::Symbol;
|
||||
use rustc_structures::NativeLibKind;
|
||||
use rustc_target::spec::Target;
|
||||
use tracing::debug;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ use rustc_crate_store::{self as cstore, CrateSource};
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||
use rustc_hir::CRATE_HIR_ID;
|
||||
use rustc_hir::attrs::{CfgEntry, NativeLibKind, WindowsSubsystemKind};
|
||||
use rustc_hir::attrs::{CfgEntry, WindowsSubsystemKind};
|
||||
use rustc_hir::def_id::CrateNum;
|
||||
use rustc_lint_defs::builtin::{LINKER_INFO, LINKER_MESSAGES};
|
||||
use rustc_macros::{Decodable, Encodable};
|
||||
@@ -39,7 +39,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||
use rustc_session::Session;
|
||||
use rustc_session::config::{OutputFilenames, OutputType};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_structures::CrateType;
|
||||
use rustc_structures::{CrateType, NativeLibKind};
|
||||
|
||||
pub mod assert_module_sources;
|
||||
pub mod back;
|
||||
|
||||
@@ -12,4 +12,5 @@ rustc_hir_id = { path = "../rustc_hir_id" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_serialize = { path = "../rustc_serialize" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_structures = { path = "../rustc_structures" }
|
||||
# tidy-alphabetical-end
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::any::Any;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rustc_abi::ExternAbi;
|
||||
use rustc_attr_ir::{CfgEntry, NativeLibKind, PeImportNameType};
|
||||
use rustc_attr_ir::{CfgEntry, PeImportNameType};
|
||||
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
|
||||
use rustc_hir_id::definitions::{DefKey, DefPath, Definitions};
|
||||
use rustc_macros::{BlobDecodable, Decodable, Encodable, StableHash};
|
||||
@@ -14,6 +14,7 @@ use rustc_span::def_id::{
|
||||
CrateNum, DefId, DefPathHash, LOCAL_CRATE, LocalDefId, StableCrateId, StableCrateIdMap,
|
||||
};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_structures::NativeLibKind;
|
||||
|
||||
/// Where a crate came from on the local filesystem. One of these three options
|
||||
/// must be non-None.
|
||||
|
||||
@@ -4,7 +4,7 @@ use rustc_crate_store::{
|
||||
DllCallingConvention, DllImport, DllImportSymbolType, ForeignModule, NativeLib,
|
||||
};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::attrs::{NativeLibKind, PeImportNameType};
|
||||
use rustc_hir::attrs::PeImportNameType;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::find_attr;
|
||||
use rustc_middle::bug;
|
||||
@@ -14,6 +14,7 @@ use rustc_middle::ty::{self, List, Ty, TyCtxt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_span::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_structures::NativeLibKind;
|
||||
use rustc_target::spec::{Arch, BinaryFormat, CfgAbi};
|
||||
|
||||
use crate::diagnostics;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
//! (There is also a similar but separate syntax for `#[link]` attributes,
|
||||
//! which have their own parser in `rustc_metadata`.)
|
||||
|
||||
use rustc_attr_ir::NativeLibKind;
|
||||
use rustc_feature::UnstableFeatures;
|
||||
use rustc_structures::NativeLibKind;
|
||||
|
||||
use crate::EarlyDiagCtxt;
|
||||
use crate::config::UnstableOptions;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use rustc_attr_ir::NativeLibKind;
|
||||
use rustc_data_structures::profiling::VerboseTimingGuard;
|
||||
use rustc_fs_util::try_canonicalize;
|
||||
use rustc_macros::{Decodable, Encodable, StableHash};
|
||||
use rustc_structures::NativeLibKind;
|
||||
|
||||
use crate::session::Session;
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
mod crate_type;
|
||||
mod limit;
|
||||
mod native_lib_kind;
|
||||
mod sanitizer_set;
|
||||
|
||||
pub use crate_type::CrateType;
|
||||
pub use limit::Limit;
|
||||
pub use native_lib_kind::NativeLibKind;
|
||||
pub use sanitizer_set::SanitizerSet;
|
||||
|
||||
71
compiler/rustc_structures/src/native_lib_kind.rs
Normal file
71
compiler/rustc_structures/src/native_lib_kind.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
#[cfg(feature = "nightly")]
|
||||
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "nightly", derive(StableHash, Encodable_NoContext, Decodable_NoContext))]
|
||||
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>,
|
||||
/// Whether to export c static library symbols
|
||||
export_symbols: 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 {
|
||||
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
|
||||
as_needed: Option<bool>,
|
||||
},
|
||||
/// 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, export_symbols } => {
|
||||
bundle.is_some() || whole_archive.is_some() || export_symbols.is_some()
|
||||
}
|
||||
NativeLibKind::Dylib { as_needed }
|
||||
| NativeLibKind::Framework { as_needed }
|
||||
| NativeLibKind::RawDylib { as_needed } => as_needed.is_some(),
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user