Skip to content

Commit ee7a35a

Browse files
committed
Rename some types describing native libraries
NativeLibrary(Kind) -> NativeLib(Kind) NativeStatic -> StaticBundle NativeStaticNobundle -> StaticNoBundle NativeFramework -> Framework NativeRawDylib -> RawDylib NativeUnknown -> Unspecified
1 parent f182c4a commit ee7a35a

File tree

16 files changed

+117
-122
lines changed

16 files changed

+117
-122
lines changed

src/librustc_codegen_llvm/attributes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ pub fn provide(providers: &mut Providers<'_>) {
361361

362362
pub fn provide_extern(providers: &mut Providers<'_>) {
363363
providers.wasm_import_module_map = |tcx, cnum| {
364-
// Build up a map from DefId to a `NativeLibrary` structure, where
365-
// `NativeLibrary` internally contains information about
364+
// Build up a map from DefId to a `NativeLib` structure, where
365+
// `NativeLib` internally contains information about
366366
// `#[link(wasm_import_module = "...")]` for example.
367367
let native_libs = tcx.native_libraries(cnum);
368368

src/librustc_codegen_ssa/back/link.rs

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use rustc_data_structures::fx::FxHashSet;
22
use rustc_fs_util::fix_windows_verbatim_for_gcc;
33
use rustc_hir::def_id::CrateNum;
4-
use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLibrary, NativeLibraryKind};
4+
use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLib};
55
use rustc_middle::middle::dependency_format::Linkage;
66
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo};
77
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, Sanitizer};
88
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
99
use rustc_session::search_paths::PathKind;
10+
use rustc_session::utils::NativeLibKind;
1011
/// For all the linkers we support, and information they might
1112
/// need out of the shared crate context before we get rid of it.
1213
use rustc_session::{filesearch, Session};
@@ -327,11 +328,11 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
327328
// metadata of the rlib we're generating somehow.
328329
for lib in codegen_results.crate_info.used_libraries.iter() {
329330
match lib.kind {
330-
NativeLibraryKind::NativeStatic => {}
331-
NativeLibraryKind::NativeStaticNobundle
332-
| NativeLibraryKind::NativeFramework
333-
| NativeLibraryKind::NativeRawDylib
334-
| NativeLibraryKind::NativeUnknown => continue,
331+
NativeLibKind::StaticBundle => {}
332+
NativeLibKind::StaticNoBundle
333+
| NativeLibKind::Framework
334+
| NativeLibKind::RawDylib
335+
| NativeLibKind::Unspecified => continue,
335336
}
336337
if let Some(name) = lib.name {
337338
ab.add_native_library(name);
@@ -430,7 +431,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
430431
// object files come from where and selectively skip them.
431432
let skip_object_files = native_libs
432433
.iter()
433-
.any(|lib| lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib));
434+
.any(|lib| lib.kind == NativeLibKind::StaticBundle && !relevant_lib(sess, lib));
434435
ab.add_rlib(
435436
path,
436437
&name.as_str(),
@@ -858,26 +859,26 @@ enum RlibFlavor {
858859
StaticlibBase,
859860
}
860861

861-
fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary]) {
862+
fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
862863
let lib_args: Vec<_> = all_native_libs
863864
.iter()
864865
.filter(|l| relevant_lib(sess, l))
865866
.filter_map(|lib| {
866867
let name = lib.name?;
867868
match lib.kind {
868-
NativeLibraryKind::NativeStaticNobundle | NativeLibraryKind::NativeUnknown => {
869+
NativeLibKind::StaticNoBundle | NativeLibKind::Unspecified => {
869870
if sess.target.target.options.is_like_msvc {
870871
Some(format!("{}.lib", name))
871872
} else {
872873
Some(format!("-l{}", name))
873874
}
874875
}
875-
NativeLibraryKind::NativeFramework => {
876+
NativeLibKind::Framework => {
876877
// ld-only syntax, since there are no frameworks in MSVC
877878
Some(format!("-framework {}", name))
878879
}
879880
// These are included, no need to print them
880-
NativeLibraryKind::NativeStatic | NativeLibraryKind::NativeRawDylib => None,
881+
NativeLibKind::StaticBundle | NativeLibKind::RawDylib => None,
881882
}
882883
})
883884
.collect();
@@ -1647,11 +1648,11 @@ fn add_local_native_libraries(
16471648
None => continue,
16481649
};
16491650
match lib.kind {
1650-
NativeLibraryKind::NativeUnknown => cmd.link_dylib(name),
1651-
NativeLibraryKind::NativeFramework => cmd.link_framework(name),
1652-
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(name),
1653-
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path),
1654-
NativeLibraryKind::NativeRawDylib => {
1651+
NativeLibKind::Unspecified => cmd.link_dylib(name),
1652+
NativeLibKind::Framework => cmd.link_framework(name),
1653+
NativeLibKind::StaticNoBundle => cmd.link_staticlib(name),
1654+
NativeLibKind::StaticBundle => cmd.link_whole_staticlib(name, &search_path),
1655+
NativeLibKind::RawDylib => {
16551656
// FIXME(#58713): Proper handling for raw dylibs.
16561657
bug!("raw_dylib feature not yet implemented");
16571658
}
@@ -1841,7 +1842,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
18411842
let native_libs = &codegen_results.crate_info.native_libraries[&cnum];
18421843
let skip_native = native_libs
18431844
.iter()
1844-
.any(|lib| lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib));
1845+
.any(|lib| lib.kind == NativeLibKind::StaticBundle && !relevant_lib(sess, lib));
18451846

18461847
if (!are_upstream_rust_objects_already_included(sess)
18471848
|| ignored_for_lto(sess, &codegen_results.crate_info, cnum))
@@ -1983,9 +1984,9 @@ fn add_upstream_native_libraries(
19831984
continue;
19841985
}
19851986
match lib.kind {
1986-
NativeLibraryKind::NativeUnknown => cmd.link_dylib(name),
1987-
NativeLibraryKind::NativeFramework => cmd.link_framework(name),
1988-
NativeLibraryKind::NativeStaticNobundle => {
1987+
NativeLibKind::Unspecified => cmd.link_dylib(name),
1988+
NativeLibKind::Framework => cmd.link_framework(name),
1989+
NativeLibKind::StaticNoBundle => {
19891990
// Link "static-nobundle" native libs only if the crate they originate from
19901991
// is being linked statically to the current crate. If it's linked dynamically
19911992
// or is an rlib already included via some other dylib crate, the symbols from
@@ -1997,8 +1998,8 @@ fn add_upstream_native_libraries(
19971998
// ignore statically included native libraries here as we've
19981999
// already included them when we included the rust library
19992000
// previously
2000-
NativeLibraryKind::NativeStatic => {}
2001-
NativeLibraryKind::NativeRawDylib => {
2001+
NativeLibKind::StaticBundle => {}
2002+
NativeLibKind::RawDylib => {
20022003
// FIXME(#58713): Proper handling for raw dylibs.
20032004
bug!("raw_dylib feature not yet implemented");
20042005
}
@@ -2007,7 +2008,7 @@ fn add_upstream_native_libraries(
20072008
}
20082009
}
20092010

2010-
fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool {
2011+
fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
20112012
match lib.cfg {
20122013
Some(ref cfg) => rustc_attr::cfg_matches(cfg, &sess.parse_sess, None),
20132014
None => true,

src/librustc_codegen_ssa/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use rustc_middle::ty::query::Providers;
4444
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
4545
use rustc_session::cgu_reuse_tracker::CguReuse;
4646
use rustc_session::config::{self, EntryFnType};
47+
use rustc_session::utils::NativeLibKind;
4748
use rustc_session::Session;
4849
use rustc_span::Span;
4950
use rustc_symbol_mangling::test as symbol_names_test;
@@ -895,7 +896,7 @@ pub fn provide_both(providers: &mut Providers<'_>) {
895896
.native_libraries(krate)
896897
.iter()
897898
.filter(|lib| {
898-
if lib.kind != cstore::NativeLibraryKind::NativeUnknown {
899+
if lib.kind != NativeLibKind::Unspecified {
899900
return false;
900901
}
901902
let cfg = match lib.cfg {

src/librustc_codegen_ssa/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_data_structures::sync::Lrc;
2424
use rustc_hir::def_id::CrateNum;
2525
use rustc_hir::LangItem;
2626
use rustc_middle::dep_graph::WorkProduct;
27-
use rustc_middle::middle::cstore::{CrateSource, LibSource, NativeLibrary};
27+
use rustc_middle::middle::cstore::{CrateSource, LibSource, NativeLib};
2828
use rustc_middle::middle::dependency_format::Dependencies;
2929
use rustc_middle::ty::query::Providers;
3030
use rustc_session::config::{OutputFilenames, OutputType, RUST_CGU_EXT};
@@ -112,9 +112,9 @@ pub struct CrateInfo {
112112
pub compiler_builtins: Option<CrateNum>,
113113
pub profiler_runtime: Option<CrateNum>,
114114
pub is_no_builtins: FxHashSet<CrateNum>,
115-
pub native_libraries: FxHashMap<CrateNum, Lrc<Vec<NativeLibrary>>>,
115+
pub native_libraries: FxHashMap<CrateNum, Lrc<Vec<NativeLib>>>,
116116
pub crate_name: FxHashMap<CrateNum, String>,
117-
pub used_libraries: Lrc<Vec<NativeLibrary>>,
117+
pub used_libraries: Lrc<Vec<NativeLib>>,
118118
pub link_args: Lrc<Vec<String>>,
119119
pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
120120
pub used_crates_static: Vec<(CrateNum, LibSource)>,

src/librustc_interface/tests.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::interface::parse_cfgspecs;
22

33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
5-
use rustc_middle::middle::cstore;
65
use rustc_session::config::Strip;
76
use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
87
use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes};
@@ -11,6 +10,7 @@ use rustc_session::config::{Externs, OutputType, OutputTypes, Sanitizer, SymbolM
1110
use rustc_session::getopts;
1211
use rustc_session::lint::Level;
1312
use rustc_session::search_paths::SearchPath;
13+
use rustc_session::utils::NativeLibKind;
1414
use rustc_session::{build_session, Session};
1515
use rustc_span::edition::{Edition, DEFAULT_EDITION};
1616
use rustc_span::symbol::sym;
@@ -300,30 +300,30 @@ fn test_native_libs_tracking_hash_different_values() {
300300

301301
// Reference
302302
v1.libs = vec![
303-
(String::from("a"), None, Some(cstore::NativeStatic)),
304-
(String::from("b"), None, Some(cstore::NativeFramework)),
305-
(String::from("c"), None, Some(cstore::NativeUnknown)),
303+
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
304+
(String::from("b"), None, Some(NativeLibKind::Framework)),
305+
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
306306
];
307307

308308
// Change label
309309
v2.libs = vec![
310-
(String::from("a"), None, Some(cstore::NativeStatic)),
311-
(String::from("X"), None, Some(cstore::NativeFramework)),
312-
(String::from("c"), None, Some(cstore::NativeUnknown)),
310+
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
311+
(String::from("X"), None, Some(NativeLibKind::Framework)),
312+
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
313313
];
314314

315315
// Change kind
316316
v3.libs = vec![
317-
(String::from("a"), None, Some(cstore::NativeStatic)),
318-
(String::from("b"), None, Some(cstore::NativeStatic)),
319-
(String::from("c"), None, Some(cstore::NativeUnknown)),
317+
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
318+
(String::from("b"), None, Some(NativeLibKind::StaticBundle)),
319+
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
320320
];
321321

322322
// Change new-name
323323
v4.libs = vec![
324-
(String::from("a"), None, Some(cstore::NativeStatic)),
325-
(String::from("b"), Some(String::from("X")), Some(cstore::NativeFramework)),
326-
(String::from("c"), None, Some(cstore::NativeUnknown)),
324+
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
325+
(String::from("b"), Some(String::from("X")), Some(NativeLibKind::Framework)),
326+
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
327327
];
328328

329329
assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
@@ -345,21 +345,21 @@ fn test_native_libs_tracking_hash_different_order() {
345345

346346
// Reference
347347
v1.libs = vec![
348-
(String::from("a"), None, Some(cstore::NativeStatic)),
349-
(String::from("b"), None, Some(cstore::NativeFramework)),
350-
(String::from("c"), None, Some(cstore::NativeUnknown)),
348+
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
349+
(String::from("b"), None, Some(NativeLibKind::Framework)),
350+
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
351351
];
352352

353353
v2.libs = vec![
354-
(String::from("b"), None, Some(cstore::NativeFramework)),
355-
(String::from("a"), None, Some(cstore::NativeStatic)),
356-
(String::from("c"), None, Some(cstore::NativeUnknown)),
354+
(String::from("b"), None, Some(NativeLibKind::Framework)),
355+
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
356+
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
357357
];
358358

359359
v3.libs = vec![
360-
(String::from("c"), None, Some(cstore::NativeUnknown)),
361-
(String::from("a"), None, Some(cstore::NativeStatic)),
362-
(String::from("b"), None, Some(cstore::NativeFramework)),
360+
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
361+
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
362+
(String::from("b"), None, Some(NativeLibKind::Framework)),
363363
];
364364

365365
assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());

src/librustc_metadata/native_libs.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ use rustc_data_structures::fx::FxHashSet;
33
use rustc_errors::struct_span_err;
44
use rustc_hir as hir;
55
use rustc_hir::itemlikevisit::ItemLikeVisitor;
6-
use rustc_middle::middle::cstore::{self, NativeLibrary};
6+
use rustc_middle::middle::cstore::NativeLib;
77
use rustc_middle::ty::TyCtxt;
88
use rustc_session::parse::feature_err;
9+
use rustc_session::utils::NativeLibKind;
910
use rustc_session::Session;
1011
use rustc_span::source_map::Span;
1112
use rustc_span::symbol::{kw, sym, Symbol};
1213
use rustc_target::spec::abi::Abi;
1314

14-
crate fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLibrary> {
15+
crate fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
1516
let mut collector = Collector { tcx, libs: Vec::new() };
1617
tcx.hir().krate().visit_all_item_likes(&mut collector);
1718
collector.process_command_line();
1819
collector.libs
1920
}
2021

21-
crate fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool {
22+
crate fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
2223
match lib.cfg {
2324
Some(ref cfg) => attr::cfg_matches(cfg, &sess.parse_sess, None),
2425
None => true,
@@ -27,7 +28,7 @@ crate fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool {
2728

2829
struct Collector<'tcx> {
2930
tcx: TyCtxt<'tcx>,
30-
libs: Vec<NativeLibrary>,
31+
libs: Vec<NativeLib>,
3132
}
3233

3334
impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
@@ -47,9 +48,9 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
4748
Some(item) => item,
4849
None => continue,
4950
};
50-
let mut lib = NativeLibrary {
51+
let mut lib = NativeLib {
5152
name: None,
52-
kind: cstore::NativeUnknown,
53+
kind: NativeLibKind::Unspecified,
5354
cfg: None,
5455
foreign_module: Some(self.tcx.hir().local_def_id(it.hir_id).to_def_id()),
5556
wasm_import_module: None,
@@ -64,11 +65,11 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
6465
None => continue, // skip like historical compilers
6566
};
6667
lib.kind = match &*kind.as_str() {
67-
"static" => cstore::NativeStatic,
68-
"static-nobundle" => cstore::NativeStaticNobundle,
69-
"dylib" => cstore::NativeUnknown,
70-
"framework" => cstore::NativeFramework,
71-
"raw-dylib" => cstore::NativeRawDylib,
68+
"static" => NativeLibKind::StaticBundle,
69+
"static-nobundle" => NativeLibKind::StaticNoBundle,
70+
"dylib" => NativeLibKind::Unspecified,
71+
"framework" => NativeLibKind::Framework,
72+
"raw-dylib" => NativeLibKind::RawDylib,
7273
k => {
7374
struct_span_err!(
7475
self.tcx.sess,
@@ -80,7 +81,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
8081
.span_label(item.span(), "unknown kind")
8182
.span_label(m.span, "")
8283
.emit();
83-
cstore::NativeUnknown
84+
NativeLibKind::Unspecified
8485
}
8586
};
8687
} else if item.check_name(sym::name) {
@@ -134,7 +135,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
134135
}
135136

136137
impl Collector<'tcx> {
137-
fn register_native_lib(&mut self, span: Option<Span>, lib: NativeLibrary) {
138+
fn register_native_lib(&mut self, span: Option<Span>, lib: NativeLib) {
138139
if lib.name.as_ref().map(|&s| s == kw::Invalid).unwrap_or(false) {
139140
match span {
140141
Some(span) => {
@@ -154,7 +155,7 @@ impl Collector<'tcx> {
154155
return;
155156
}
156157
let is_osx = self.tcx.sess.target.target.options.is_like_osx;
157-
if lib.kind == cstore::NativeFramework && !is_osx {
158+
if lib.kind == NativeLibKind::Framework && !is_osx {
158159
let msg = "native frameworks are only available on macOS targets";
159160
match span {
160161
Some(span) => struct_span_err!(self.tcx.sess, span, E0455, "{}", msg).emit(),
@@ -170,7 +171,7 @@ impl Collector<'tcx> {
170171
)
171172
.emit();
172173
}
173-
if lib.kind == cstore::NativeStaticNobundle && !self.tcx.features().static_nobundle {
174+
if lib.kind == NativeLibKind::StaticNoBundle && !self.tcx.features().static_nobundle {
174175
feature_err(
175176
&self.tcx.sess.parse_sess,
176177
sym::static_nobundle,
@@ -179,7 +180,7 @@ impl Collector<'tcx> {
179180
)
180181
.emit();
181182
}
182-
if lib.kind == cstore::NativeRawDylib && !self.tcx.features().raw_dylib {
183+
if lib.kind == NativeLibKind::RawDylib && !self.tcx.features().raw_dylib {
183184
feature_err(
184185
&self.tcx.sess.parse_sess,
185186
sym::raw_dylib,
@@ -255,9 +256,9 @@ impl Collector<'tcx> {
255256
if existing.is_empty() {
256257
// Add if not found
257258
let new_name = new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
258-
let lib = NativeLibrary {
259+
let lib = NativeLib {
259260
name: Some(Symbol::intern(new_name.unwrap_or(name))),
260-
kind: if let Some(k) = kind { k } else { cstore::NativeUnknown },
261+
kind: if let Some(k) = kind { k } else { NativeLibKind::Unspecified },
261262
cfg: None,
262263
foreign_module: None,
263264
wasm_import_module: None,

0 commit comments

Comments
 (0)