Skip to content

Commit 1692c0b

Browse files
committed
Auto merge of #37973 - vadimcn:dllimport, r=alexcrichton
Implement RFC 1717 Implement the first two points from #37403. r? @alexcrichton
2 parents ff261d3 + 7d05d1e commit 1692c0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+437
-155
lines changed

src/librustc/middle/cstore.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pub struct NativeLibrary {
131131
pub kind: NativeLibraryKind,
132132
pub name: Symbol,
133133
pub cfg: Option<ast::MetaItem>,
134+
pub foreign_items: Vec<DefIndex>,
134135
}
135136

136137
/// The data we save and restore about an inlined item or method. This is not
@@ -305,7 +306,8 @@ pub trait CrateStore<'tcx> {
305306
fn is_defaulted_trait(&self, did: DefId) -> bool;
306307
fn is_default_impl(&self, impl_did: DefId) -> bool;
307308
fn is_foreign_item(&self, did: DefId) -> bool;
308-
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
309+
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
310+
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
309311

310312
// crate metadata
311313
fn dylib_dependency_formats(&self, cnum: CrateNum)
@@ -463,7 +465,8 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
463465
fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
464466
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
465467
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
466-
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
468+
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
469+
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
467470

468471
// crate metadata
469472
fn dylib_dependency_formats(&self, cnum: CrateNum)
@@ -529,9 +532,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
529532
// This is basically a 1-based range of ints, which is a little
530533
// silly - I may fix that.
531534
fn crates(&self) -> Vec<CrateNum> { vec![] }
532-
fn used_libraries(&self) -> Vec<NativeLibrary> {
533-
vec![]
534-
}
535+
fn used_libraries(&self) -> Vec<NativeLibrary> { vec![] }
535536
fn used_link_args(&self) -> Vec<String> { vec![] }
536537

537538
// utility functions

src/librustc/session/config.rs

+50-22
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ top_level_options!(
262262
// much sense: The search path can stay the same while the
263263
// things discovered there might have changed on disk.
264264
search_paths: SearchPaths [TRACKED],
265-
libs: Vec<(String, cstore::NativeLibraryKind)> [TRACKED],
265+
libs: Vec<(String, Option<String>, cstore::NativeLibraryKind)> [TRACKED],
266266
maybe_sysroot: Option<PathBuf> [TRACKED],
267267

268268
target_triple: String [TRACKED],
@@ -1449,6 +1449,8 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
14491449
}
14501450

14511451
let libs = matches.opt_strs("l").into_iter().map(|s| {
1452+
// Parse string of the form "[KIND=]lib[:new_name]",
1453+
// where KIND is one of "dylib", "framework", "static".
14521454
let mut parts = s.splitn(2, '=');
14531455
let kind = parts.next().unwrap();
14541456
let (name, kind) = match (parts.next(), kind) {
@@ -1462,7 +1464,10 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
14621464
s));
14631465
}
14641466
};
1465-
(name.to_string(), kind)
1467+
let mut name_parts = name.splitn(2, ':');
1468+
let name = name_parts.next().unwrap();
1469+
let new_name = name_parts.next();
1470+
(name.to_string(), new_name.map(|n| n.to_string()), kind)
14661471
}).collect();
14671472

14681473
let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
@@ -1728,8 +1733,8 @@ mod dep_tracking {
17281733
impl_dep_tracking_hash_for_sortable_vec_of!(String);
17291734
impl_dep_tracking_hash_for_sortable_vec_of!(CrateType);
17301735
impl_dep_tracking_hash_for_sortable_vec_of!((String, lint::Level));
1731-
impl_dep_tracking_hash_for_sortable_vec_of!((String, cstore::NativeLibraryKind));
1732-
1736+
impl_dep_tracking_hash_for_sortable_vec_of!((String, Option<String>,
1737+
cstore::NativeLibraryKind));
17331738
impl DepTrackingHash for SearchPaths {
17341739
fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) {
17351740
let mut elems: Vec<_> = self
@@ -1752,6 +1757,21 @@ mod dep_tracking {
17521757
}
17531758
}
17541759

1760+
impl<T1, T2, T3> DepTrackingHash for (T1, T2, T3)
1761+
where T1: DepTrackingHash,
1762+
T2: DepTrackingHash,
1763+
T3: DepTrackingHash
1764+
{
1765+
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
1766+
Hash::hash(&0, hasher);
1767+
DepTrackingHash::hash(&self.0, hasher, error_format);
1768+
Hash::hash(&1, hasher);
1769+
DepTrackingHash::hash(&self.1, hasher, error_format);
1770+
Hash::hash(&2, hasher);
1771+
DepTrackingHash::hash(&self.2, hasher, error_format);
1772+
}
1773+
}
1774+
17551775
// This is a stable hash because BTreeMap is a sorted container
17561776
pub fn stable_hash(sub_hashes: BTreeMap<&'static str, &DepTrackingHash>,
17571777
hasher: &mut DefaultHasher,
@@ -2155,29 +2175,37 @@ mod tests {
21552175
let mut v1 = super::basic_options();
21562176
let mut v2 = super::basic_options();
21572177
let mut v3 = super::basic_options();
2178+
let mut v4 = super::basic_options();
21582179

21592180
// Reference
2160-
v1.libs = vec![(String::from("a"), cstore::NativeStatic),
2161-
(String::from("b"), cstore::NativeFramework),
2162-
(String::from("c"), cstore::NativeUnknown)];
2181+
v1.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2182+
(String::from("b"), None, cstore::NativeFramework),
2183+
(String::from("c"), None, cstore::NativeUnknown)];
21632184

21642185
// Change label
2165-
v2.libs = vec![(String::from("a"), cstore::NativeStatic),
2166-
(String::from("X"), cstore::NativeFramework),
2167-
(String::from("c"), cstore::NativeUnknown)];
2186+
v2.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2187+
(String::from("X"), None, cstore::NativeFramework),
2188+
(String::from("c"), None, cstore::NativeUnknown)];
21682189

21692190
// Change kind
2170-
v3.libs = vec![(String::from("a"), cstore::NativeStatic),
2171-
(String::from("b"), cstore::NativeStatic),
2172-
(String::from("c"), cstore::NativeUnknown)];
2191+
v3.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2192+
(String::from("b"), None, cstore::NativeStatic),
2193+
(String::from("c"), None, cstore::NativeUnknown)];
2194+
2195+
// Change new-name
2196+
v4.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2197+
(String::from("b"), Some(String::from("X")), cstore::NativeFramework),
2198+
(String::from("c"), None, cstore::NativeUnknown)];
21732199

21742200
assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
21752201
assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
2202+
assert!(v1.dep_tracking_hash() != v4.dep_tracking_hash());
21762203

21772204
// Check clone
21782205
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
21792206
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
21802207
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
2208+
assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
21812209
}
21822210

21832211
#[test]
@@ -2187,17 +2215,17 @@ mod tests {
21872215
let mut v3 = super::basic_options();
21882216

21892217
// Reference
2190-
v1.libs = vec![(String::from("a"), cstore::NativeStatic),
2191-
(String::from("b"), cstore::NativeFramework),
2192-
(String::from("c"), cstore::NativeUnknown)];
2218+
v1.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2219+
(String::from("b"), None, cstore::NativeFramework),
2220+
(String::from("c"), None, cstore::NativeUnknown)];
21932221

2194-
v2.libs = vec![(String::from("b"), cstore::NativeFramework),
2195-
(String::from("a"), cstore::NativeStatic),
2196-
(String::from("c"), cstore::NativeUnknown)];
2222+
v2.libs = vec![(String::from("b"), None, cstore::NativeFramework),
2223+
(String::from("a"), None, cstore::NativeStatic),
2224+
(String::from("c"), None, cstore::NativeUnknown)];
21972225

2198-
v3.libs = vec![(String::from("c"), cstore::NativeUnknown),
2199-
(String::from("a"), cstore::NativeStatic),
2200-
(String::from("b"), cstore::NativeFramework)];
2226+
v3.libs = vec![(String::from("c"), None, cstore::NativeUnknown),
2227+
(String::from("a"), None, cstore::NativeStatic),
2228+
(String::from("b"), None, cstore::NativeFramework)];
22012229

22022230
assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
22032231
assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());

src/librustc_llvm/ffi.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,9 @@ pub mod debuginfo {
471471
// generates an llvmdeps.rs file next to this one which will be
472472
// automatically updated whenever LLVM is updated to include an up-to-date
473473
// set of the libraries we need to link to LLVM for.
474-
#[link(name = "rustllvm", kind = "static")]
475-
#[cfg(not(cargobuild))]
476-
extern "C" {}
477-
478-
#[linked_from = "rustllvm"] // not quite true but good enough
474+
#[cfg_attr(not(all(stage0,cargobuild)),
475+
link(name = "rustllvm", kind = "static"))] // not quite true but good enough
476+
#[cfg_attr(stage0, linked_from = "rustllvm")]
479477
extern "C" {
480478
// Create and destroy contexts.
481479
pub fn LLVMContextCreate() -> ContextRef;

src/librustc_llvm/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#![feature(concat_idents)]
2828
#![feature(libc)]
2929
#![feature(link_args)]
30-
#![feature(linked_from)]
30+
#![cfg_attr(stage0, feature(linked_from))]
3131
#![feature(staged_api)]
3232
#![cfg_attr(not(stage0), feature(rustc_private))]
3333

0 commit comments

Comments
 (0)