Skip to content

Commit 8d970ff

Browse files
mejrsJonathanBrouwer
authored andcommitted
Move NativeLibKind
1 parent 38af4a2 commit 8d970ff

15 files changed

Lines changed: 90 additions & 82 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,6 +3875,7 @@ dependencies = [
38753875
"rustc_macros",
38763876
"rustc_serialize",
38773877
"rustc_span",
3878+
"rustc_structures",
38783879
]
38793880

38803881
[[package]]

‎compiler/rustc_attr_ir/src/data_structures.rs‎

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash};
1616
use rustc_span::def_id::DefId;
1717
use rustc_span::hygiene::Transparency;
1818
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
19-
use rustc_structures::{CrateType, Limit, SanitizerSet};
19+
use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet};
2020
use thin_vec::ThinVec;
2121

2222
pub use crate::canonical_symbols::{CanonicalSymbol, CanonicalSymbols};
@@ -371,76 +371,6 @@ pub enum PeImportNameType {
371371
Undecorated,
372372
}
373373

374-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
375-
#[derive(Encodable, Decodable, PrintAttribute)]
376-
#[derive(StableHash)]
377-
pub enum NativeLibKind {
378-
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
379-
Static {
380-
/// Whether to bundle objects from static library into produced rlib
381-
bundle: Option<bool>,
382-
/// Whether to link static library without throwing any object files away
383-
whole_archive: Option<bool>,
384-
/// Whether to export c static library symbols
385-
export_symbols: Option<bool>,
386-
},
387-
/// Dynamic library (e.g. `libfoo.so` on Linux)
388-
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
389-
Dylib {
390-
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
391-
as_needed: Option<bool>,
392-
},
393-
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
394-
/// On Linux, it refers to a generated shared library stub.
395-
RawDylib {
396-
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
397-
as_needed: Option<bool>,
398-
},
399-
/// A macOS-specific kind of dynamic libraries.
400-
Framework {
401-
/// Whether the framework will be linked only if it satisfies some undefined symbols
402-
as_needed: Option<bool>,
403-
},
404-
/// Argument which is passed to linker, relative order with libraries and other arguments
405-
/// is preserved
406-
LinkArg,
407-
408-
/// Module imported from WebAssembly
409-
WasmImportModule,
410-
411-
/// The library kind wasn't specified, `Dylib` is currently used as a default.
412-
Unspecified,
413-
}
414-
415-
impl NativeLibKind {
416-
pub fn has_modifiers(&self) -> bool {
417-
match self {
418-
NativeLibKind::Static { bundle, whole_archive, export_symbols } => {
419-
bundle.is_some() || whole_archive.is_some() || export_symbols.is_some()
420-
}
421-
NativeLibKind::Dylib { as_needed }
422-
| NativeLibKind::Framework { as_needed }
423-
| NativeLibKind::RawDylib { as_needed } => as_needed.is_some(),
424-
NativeLibKind::Unspecified
425-
| NativeLibKind::LinkArg
426-
| NativeLibKind::WasmImportModule => false,
427-
}
428-
}
429-
430-
pub fn is_statically_included(&self) -> bool {
431-
matches!(self, NativeLibKind::Static { .. })
432-
}
433-
434-
pub fn is_dllimport(&self) -> bool {
435-
matches!(
436-
self,
437-
NativeLibKind::Dylib { .. }
438-
| NativeLibKind::RawDylib { .. }
439-
| NativeLibKind::Unspecified
440-
)
441-
}
442-
}
443-
444374
#[derive(Debug, Encodable, Decodable, Clone, StableHash, PrintAttribute)]
445375
pub struct LinkEntry {
446376
pub span: Span,

‎compiler/rustc_attr_ir/src/pretty_printing.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxIndexMap;
1414
use rustc_span::def_id::DefId;
1515
use rustc_span::hygiene::Transparency;
1616
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
17-
use rustc_structures::{CrateType, Limit, SanitizerSet};
17+
use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet};
1818
use thin_vec::ThinVec;
1919

2020
/// This trait is used to print attributes in `rustc_hir_pretty`.
@@ -208,4 +208,5 @@ print_debug!(
208208
DiffActivity,
209209
DiffMode,
210210
CrateType,
211+
NativeLibKind,
211212
);

‎compiler/rustc_attr_parsing/src/attributes/link_attrs.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_session::Session;
77
use rustc_session::diagnostics::feature_err;
88
use rustc_span::edition::Edition::Edition2024;
99
use rustc_span::kw;
10+
use rustc_structures::NativeLibKind;
1011
use rustc_target::spec::{Arch, BinaryFormat};
1112

1213
use super::prelude::*;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_data_structures::memmap::Mmap;
2121
use rustc_data_structures::temp_dir::MaybeTempDir;
2222
use rustc_errors::DiagCtxtHandle;
2323
use rustc_fs_util::{TempDirBuilder, fix_windows_verbatim_for_gcc, try_canonicalize};
24-
use rustc_hir::attrs::NativeLibKind;
2524
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2625
use rustc_lint_defs::builtin::{LINKER_INFO, LINKER_MESSAGES};
2726
use rustc_macros::Diagnostic;
@@ -43,7 +42,7 @@ use rustc_session::search_paths::PathKind;
4342
/// need out of the shared crate context before we get rid of it.
4443
use rustc_session::{Session, filesearch};
4544
use rustc_span::Symbol;
46-
use rustc_structures::CrateType;
45+
use rustc_structures::{CrateType, NativeLibKind};
4746
use rustc_target::spec::crt_objects::CrtObjects;
4847
use rustc_target::spec::{
4948
Arch, BinaryFormat, Cc, CfgAbi, Env, LinkOutputKind, LinkSelfContainedComponents,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN};
88
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
99
use rustc_data_structures::stable_hash::StableHasher;
1010
use rustc_hashes::Hash128;
11-
use rustc_hir::attrs::NativeLibKind;
1211
use rustc_session::Session;
1312
use rustc_span::Symbol;
13+
use rustc_structures::NativeLibKind;
1414
use rustc_target::spec::Arch;
1515

1616
use crate::back::archive::ImportLibraryItem;

‎compiler/rustc_codegen_ssa/src/back/rmeta_link.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use std::path::{Path, PathBuf};
88
use object::read::archive::ArchiveFile;
99
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_data_structures::memmap::Mmap;
11-
use rustc_hir::attrs::NativeLibKind;
1211
use rustc_serialize::opaque::mem_encoder::MemEncoder;
1312
use rustc_serialize::opaque::{MAGIC_END_BYTES, MemDecoder};
1413
use rustc_serialize::{Decodable, Encodable};
1514
use rustc_span::Symbol;
15+
use rustc_structures::NativeLibKind;
1616
use rustc_target::spec::Target;
1717
use tracing::debug;
1818

‎compiler/rustc_codegen_ssa/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_crate_store::{self as cstore, CrateSource};
2222
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2323
use rustc_data_structures::unord::{UnordMap, UnordSet};
2424
use rustc_hir::CRATE_HIR_ID;
25-
use rustc_hir::attrs::{CfgEntry, NativeLibKind, WindowsSubsystemKind};
25+
use rustc_hir::attrs::{CfgEntry, WindowsSubsystemKind};
2626
use rustc_hir::def_id::CrateNum;
2727
use rustc_lint_defs::builtin::{LINKER_INFO, LINKER_MESSAGES};
2828
use rustc_macros::{Decodable, Encodable};
@@ -39,7 +39,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3939
use rustc_session::Session;
4040
use rustc_session::config::{OutputFilenames, OutputType};
4141
use rustc_span::{Span, Symbol};
42-
use rustc_structures::CrateType;
42+
use rustc_structures::{CrateType, NativeLibKind};
4343

4444
pub mod assert_module_sources;
4545
pub mod back;

‎compiler/rustc_crate_store/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ rustc_hir_id = { path = "../rustc_hir_id" }
1212
rustc_macros = { path = "../rustc_macros" }
1313
rustc_serialize = { path = "../rustc_serialize" }
1414
rustc_span = { path = "../rustc_span" }
15+
rustc_structures = { path = "../rustc_structures" }
1516
# tidy-alphabetical-end

‎compiler/rustc_crate_store/src/cstore.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use std::any::Any;
66
use std::path::PathBuf;
77

88
use rustc_abi::ExternAbi;
9-
use rustc_attr_ir::{CfgEntry, NativeLibKind, PeImportNameType};
9+
use rustc_attr_ir::{CfgEntry, PeImportNameType};
1010
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
1111
use rustc_hir_id::definitions::{DefKey, DefPath, Definitions};
1212
use rustc_macros::{BlobDecodable, Decodable, Encodable, StableHash};
1313
use rustc_span::def_id::{
1414
CrateNum, DefId, DefPathHash, LOCAL_CRATE, LocalDefId, StableCrateId, StableCrateIdMap,
1515
};
1616
use rustc_span::{Span, Symbol};
17+
use rustc_structures::NativeLibKind;
1718

1819
/// Where a crate came from on the local filesystem. One of these three options
1920
/// must be non-None.

0 commit comments

Comments
 (0)