Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RFC 1717 #37973

Merged
merged 9 commits into from
Dec 6, 2016
11 changes: 6 additions & 5 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
@@ -131,6 +131,7 @@ pub struct NativeLibrary {
pub kind: NativeLibraryKind,
pub name: Symbol,
pub cfg: Option<ast::MetaItem>,
pub foreign_items: Vec<DefIndex>,
}

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

// crate metadata
fn dylib_dependency_formats(&self, cnum: CrateNum)
@@ -462,7 +464,8 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }

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

// utility functions
72 changes: 50 additions & 22 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
@@ -262,7 +262,7 @@ top_level_options!(
// much sense: The search path can stay the same while the
// things discovered there might have changed on disk.
search_paths: SearchPaths [TRACKED],
libs: Vec<(String, cstore::NativeLibraryKind)> [TRACKED],
libs: Vec<(String, Option<String>, cstore::NativeLibraryKind)> [TRACKED],
maybe_sysroot: Option<PathBuf> [TRACKED],

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

let libs = matches.opt_strs("l").into_iter().map(|s| {
// Parse string of the form "[KIND=]lib[:new_name]",
// where KIND is one of "dylib", "framework", "static".
let mut parts = s.splitn(2, '=');
let kind = parts.next().unwrap();
let (name, kind) = match (parts.next(), kind) {
@@ -1452,7 +1454,10 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
s));
}
};
(name.to_string(), kind)
let mut name_parts = name.splitn(2, ':');
let name = name_parts.next().unwrap();
let new_name = name_parts.next();
(name.to_string(), new_name.map(|n| n.to_string()), kind)
}).collect();

let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
@@ -1716,8 +1721,8 @@ mod dep_tracking {
impl_dep_tracking_hash_for_sortable_vec_of!(String);
impl_dep_tracking_hash_for_sortable_vec_of!(CrateType);
impl_dep_tracking_hash_for_sortable_vec_of!((String, lint::Level));
impl_dep_tracking_hash_for_sortable_vec_of!((String, cstore::NativeLibraryKind));

impl_dep_tracking_hash_for_sortable_vec_of!((String, Option<String>,
cstore::NativeLibraryKind));
impl DepTrackingHash for SearchPaths {
fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) {
let mut elems: Vec<_> = self
@@ -1740,6 +1745,21 @@ mod dep_tracking {
}
}

impl<T1, T2, T3> DepTrackingHash for (T1, T2, T3)
where T1: DepTrackingHash,
T2: DepTrackingHash,
T3: DepTrackingHash
{
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
Hash::hash(&0, hasher);
DepTrackingHash::hash(&self.0, hasher, error_format);
Hash::hash(&1, hasher);
DepTrackingHash::hash(&self.1, hasher, error_format);
Hash::hash(&2, hasher);
DepTrackingHash::hash(&self.2, hasher, error_format);
}
}

// This is a stable hash because BTreeMap is a sorted container
pub fn stable_hash(sub_hashes: BTreeMap<&'static str, &DepTrackingHash>,
hasher: &mut DefaultHasher,
@@ -2143,29 +2163,37 @@ mod tests {
let mut v1 = super::basic_options();
let mut v2 = super::basic_options();
let mut v3 = super::basic_options();
let mut v4 = super::basic_options();

// Reference
v1.libs = vec![(String::from("a"), cstore::NativeStatic),
(String::from("b"), cstore::NativeFramework),
(String::from("c"), cstore::NativeUnknown)];
v1.libs = vec![(String::from("a"), None, cstore::NativeStatic),
(String::from("b"), None, cstore::NativeFramework),
(String::from("c"), None, cstore::NativeUnknown)];

// Change label
v2.libs = vec![(String::from("a"), cstore::NativeStatic),
(String::from("X"), cstore::NativeFramework),
(String::from("c"), cstore::NativeUnknown)];
v2.libs = vec![(String::from("a"), None, cstore::NativeStatic),
(String::from("X"), None, cstore::NativeFramework),
(String::from("c"), None, cstore::NativeUnknown)];

// Change kind
v3.libs = vec![(String::from("a"), cstore::NativeStatic),
(String::from("b"), cstore::NativeStatic),
(String::from("c"), cstore::NativeUnknown)];
v3.libs = vec![(String::from("a"), None, cstore::NativeStatic),
(String::from("b"), None, cstore::NativeStatic),
(String::from("c"), None, cstore::NativeUnknown)];

// Change new-name
v4.libs = vec![(String::from("a"), None, cstore::NativeStatic),
(String::from("b"), Some(String::from("X")), cstore::NativeFramework),
(String::from("c"), None, cstore::NativeUnknown)];

assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
assert!(v1.dep_tracking_hash() != v4.dep_tracking_hash());

// Check clone
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
}

#[test]
@@ -2175,17 +2203,17 @@ mod tests {
let mut v3 = super::basic_options();

// Reference
v1.libs = vec![(String::from("a"), cstore::NativeStatic),
(String::from("b"), cstore::NativeFramework),
(String::from("c"), cstore::NativeUnknown)];
v1.libs = vec![(String::from("a"), None, cstore::NativeStatic),
(String::from("b"), None, cstore::NativeFramework),
(String::from("c"), None, cstore::NativeUnknown)];

v2.libs = vec![(String::from("b"), cstore::NativeFramework),
(String::from("a"), cstore::NativeStatic),
(String::from("c"), cstore::NativeUnknown)];
v2.libs = vec![(String::from("b"), None, cstore::NativeFramework),
(String::from("a"), None, cstore::NativeStatic),
(String::from("c"), None, cstore::NativeUnknown)];

v3.libs = vec![(String::from("c"), cstore::NativeUnknown),
(String::from("a"), cstore::NativeStatic),
(String::from("b"), cstore::NativeFramework)];
v3.libs = vec![(String::from("c"), None, cstore::NativeUnknown),
(String::from("a"), None, cstore::NativeStatic),
(String::from("b"), None, cstore::NativeFramework)];

assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
8 changes: 3 additions & 5 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
@@ -465,11 +465,9 @@ pub mod debuginfo {
// generates an llvmdeps.rs file next to this one which will be
// automatically updated whenever LLVM is updated to include an up-to-date
// set of the libraries we need to link to LLVM for.
#[link(name = "rustllvm", kind = "static")]
#[cfg(not(cargobuild))]
extern "C" {}

#[linked_from = "rustllvm"] // not quite true but good enough
#[cfg_attr(not(all(stage0,cargobuild)),
link(name = "rustllvm", kind = "static"))] // not quite true but good enough
#[cfg_attr(stage0, linked_from = "rustllvm")]
extern "C" {
// Create and destroy contexts.
pub fn LLVMContextCreate() -> ContextRef;
2 changes: 1 addition & 1 deletion src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
#![feature(concat_idents)]
#![feature(libc)]
#![feature(link_args)]
#![feature(linked_from)]
#![cfg_attr(stage0, feature(linked_from))]
#![feature(staged_api)]

extern crate libc;
Loading