Skip to content

Commit ae32b6e

Browse files
committed
Better handling of lib defaults
1 parent fc6f092 commit ae32b6e

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

src/librustc/session/config.rs

+30-29
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ top_level_options!(
288288
// much sense: The search path can stay the same while the
289289
// things discovered there might have changed on disk.
290290
search_paths: SearchPaths [TRACKED],
291-
libs: Vec<(String, Option<String>, cstore::NativeLibraryKind)> [TRACKED],
291+
libs: Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> [TRACKED],
292292
maybe_sysroot: Option<PathBuf> [TRACKED],
293293

294294
target_triple: String [TRACKED],
@@ -1495,18 +1495,18 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
14951495
let mut parts = s.splitn(2, '=');
14961496
let kind = parts.next().unwrap();
14971497
let (name, kind) = match (parts.next(), kind) {
1498-
(None, name) |
1499-
(Some(name), "dylib") => (name, cstore::NativeUnknown),
1500-
(Some(name), "framework") => (name, cstore::NativeFramework),
1501-
(Some(name), "static") => (name, cstore::NativeStatic),
1502-
(Some(name), "static-nobundle") => (name, cstore::NativeStaticNobundle),
1498+
(None, name) => (name, None),
1499+
(Some(name), "dylib") => (name, Some(cstore::NativeUnknown)),
1500+
(Some(name), "framework") => (name, Some(cstore::NativeFramework)),
1501+
(Some(name), "static") => (name, Some(cstore::NativeStatic)),
1502+
(Some(name), "static-nobundle") => (name, Some(cstore::NativeStaticNobundle)),
15031503
(_, s) => {
15041504
early_error(error_format, &format!("unknown library kind `{}`, expected \
15051505
one of dylib, framework, or static",
15061506
s));
15071507
}
15081508
};
1509-
if kind == cstore::NativeStaticNobundle && !nightly_options::is_nightly_build() {
1509+
if kind == Some(cstore::NativeStaticNobundle) && !nightly_options::is_nightly_build() {
15101510
early_error(error_format, &format!("the library kind 'static-nobundle' is only \
15111511
accepted on the nightly compiler"));
15121512
}
@@ -1772,6 +1772,7 @@ mod dep_tracking {
17721772
impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>);
17731773
impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
17741774
impl_dep_tracking_hash_via_hash!(Option<PathBuf>);
1775+
impl_dep_tracking_hash_via_hash!(Option<cstore::NativeLibraryKind>);
17751776
impl_dep_tracking_hash_via_hash!(CrateType);
17761777
impl_dep_tracking_hash_via_hash!(PanicStrategy);
17771778
impl_dep_tracking_hash_via_hash!(Passes);
@@ -1786,7 +1787,7 @@ mod dep_tracking {
17861787
impl_dep_tracking_hash_for_sortable_vec_of!(CrateType);
17871788
impl_dep_tracking_hash_for_sortable_vec_of!((String, lint::Level));
17881789
impl_dep_tracking_hash_for_sortable_vec_of!((String, Option<String>,
1789-
cstore::NativeLibraryKind));
1790+
Option<cstore::NativeLibraryKind>));
17901791
impl DepTrackingHash for SearchPaths {
17911792
fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) {
17921793
let mut elems: Vec<_> = self
@@ -2230,24 +2231,24 @@ mod tests {
22302231
let mut v4 = super::basic_options();
22312232

22322233
// Reference
2233-
v1.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2234-
(String::from("b"), None, cstore::NativeFramework),
2235-
(String::from("c"), None, cstore::NativeUnknown)];
2234+
v1.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2235+
(String::from("b"), None, Some(cstore::NativeFramework)),
2236+
(String::from("c"), None, Some(cstore::NativeUnknown))];
22362237

22372238
// Change label
2238-
v2.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2239-
(String::from("X"), None, cstore::NativeFramework),
2240-
(String::from("c"), None, cstore::NativeUnknown)];
2239+
v2.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2240+
(String::from("X"), None, Some(cstore::NativeFramework)),
2241+
(String::from("c"), None, Some(cstore::NativeUnknown))];
22412242

22422243
// Change kind
2243-
v3.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2244-
(String::from("b"), None, cstore::NativeStatic),
2245-
(String::from("c"), None, cstore::NativeUnknown)];
2244+
v3.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2245+
(String::from("b"), None, Some(cstore::NativeStatic)),
2246+
(String::from("c"), None, Some(cstore::NativeUnknown))];
22462247

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

22522253
assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
22532254
assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
@@ -2267,17 +2268,17 @@ mod tests {
22672268
let mut v3 = super::basic_options();
22682269

22692270
// Reference
2270-
v1.libs = vec![(String::from("a"), None, cstore::NativeStatic),
2271-
(String::from("b"), None, cstore::NativeFramework),
2272-
(String::from("c"), None, cstore::NativeUnknown)];
2271+
v1.libs = vec![(String::from("a"), None, Some(cstore::NativeStatic)),
2272+
(String::from("b"), None, Some(cstore::NativeFramework)),
2273+
(String::from("c"), None, Some(cstore::NativeUnknown))];
22732274

2274-
v2.libs = vec![(String::from("b"), None, cstore::NativeFramework),
2275-
(String::from("a"), None, cstore::NativeStatic),
2276-
(String::from("c"), None, cstore::NativeUnknown)];
2275+
v2.libs = vec![(String::from("b"), None, Some(cstore::NativeFramework)),
2276+
(String::from("a"), None, Some(cstore::NativeStatic)),
2277+
(String::from("c"), None, Some(cstore::NativeUnknown))];
22772278

2278-
v3.libs = vec![(String::from("c"), None, cstore::NativeUnknown),
2279-
(String::from("a"), None, cstore::NativeStatic),
2280-
(String::from("b"), None, cstore::NativeFramework)];
2279+
v3.libs = vec![(String::from("c"), None, Some(cstore::NativeUnknown)),
2280+
(String::from("a"), None, Some(cstore::NativeStatic)),
2281+
(String::from("b"), None, Some(cstore::NativeFramework))];
22812282

22822283
assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
22832284
assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());

src/librustc_metadata/creader.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,20 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
10771077
let mut found = false;
10781078
for lib in self.cstore.get_used_libraries().borrow_mut().iter_mut() {
10791079
if lib.name == name as &str {
1080-
lib.kind = kind;
1080+
let mut changed = false;
1081+
if let Some(k) = kind {
1082+
lib.kind = k;
1083+
changed = true;
1084+
}
10811085
if let &Some(ref new_name) = new_name {
10821086
lib.name = Symbol::intern(new_name);
1087+
changed = true;
1088+
}
1089+
if !changed {
1090+
self.sess.warn(&format!("redundant linker flag specified for library `{}`",
1091+
name));
10831092
}
1093+
10841094
found = true;
10851095
}
10861096
}
@@ -1089,7 +1099,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
10891099
let new_name = new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
10901100
let lib = NativeLibrary {
10911101
name: Symbol::intern(new_name.unwrap_or(name)),
1092-
kind: kind,
1102+
kind: if let Some(k) = kind { k } else { cstore::NativeUnknown },
10931103
cfg: None,
10941104
foreign_items: Vec::new(),
10951105
};

0 commit comments

Comments
 (0)