Skip to content

Commit 4f68d13

Browse files
committed
auto merge of #10368 : tautologico/rust/default_pkgid, r=catamorphism
This Fixes #10265 and paves the way for fixing #9543. It works by adding a 'package_id' attribute by default for library crates that don't specify it. This is necessary to use the 'extern mod foo = "bar"' form instead of 'extern mod foo(name="bar") (as per #9543), because the former adds a required package_id when trying to link with the bar crate. I added a simple test to ensure that the default package_id value is being generated, and also added an explicit package_id in the link attribute in all rust libs to avoid getting warnings about default package_id values when building rust.
2 parents 162ba89 + ca22e94 commit 4f68d13

File tree

11 files changed

+73
-6
lines changed

11 files changed

+73
-6
lines changed

src/libextra/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Rust extras are part of the standard Rust distribution.
2121
*/
2222

2323
#[link(name = "extra",
24+
package_id = "extra",
2425
vers = "0.9-pre",
2526
uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297",
2627
url = "https://github.com/mozilla/rust/tree/master/src/libextra")];

src/librustc/back/link.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,18 @@ pub fn build_link_meta(sess: Session,
634634
}
635635
}
636636

637+
fn crate_meta_pkgid(sess: Session, name: @str, opt_pkg_id: Option<@str>)
638+
-> @str {
639+
match opt_pkg_id {
640+
Some(v) if !v.is_empty() => v,
641+
_ => {
642+
let pkg_id = name.clone();
643+
warn_missing(sess, "package_id", pkg_id);
644+
pkg_id
645+
}
646+
}
647+
}
648+
637649
let ProvidedMetas {
638650
name: opt_name,
639651
vers: opt_vers,
@@ -642,15 +654,16 @@ pub fn build_link_meta(sess: Session,
642654
} = provided_link_metas(sess, c);
643655
let name = crate_meta_name(sess, output, opt_name);
644656
let vers = crate_meta_vers(sess, opt_vers);
657+
let pkg_id = crate_meta_pkgid(sess, name, opt_pkg_id);
645658
let dep_hashes = cstore::get_dep_hashes(sess.cstore);
646659
let extras_hash =
647660
crate_meta_extras_hash(symbol_hasher, cmh_items,
648-
dep_hashes, opt_pkg_id);
661+
dep_hashes, Some(pkg_id));
649662

650663
LinkMeta {
651664
name: name,
652665
vers: vers,
653-
package_id: opt_pkg_id,
666+
package_id: Some(pkg_id),
654667
extras_hash: extras_hash
655668
}
656669
}

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#[link(name = "rustc",
12+
package_id = "rustc",
1213
vers = "0.9-pre",
1314
uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf",
1415
url = "https://github.com/mozilla/rust/tree/master/src/rustc")];

src/librustc/metadata/encoder.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,8 @@ fn encode_attributes(ebml_w: &mut writer::Encoder, attrs: &[Attribute]) {
14871487

14881488
// So there's a special crate attribute called 'link' which defines the
14891489
// metadata that Rust cares about for linking crates. This attribute requires
1490-
// 'name' and 'vers' items, so if the user didn't provide them we will throw
1491-
// them in anyway with default values.
1490+
// 'name', 'vers' and 'package_id' items, so if the user didn't provide them we
1491+
// will throw them in anyway with default values.
14921492
fn synthesize_crate_attrs(ecx: &EncodeContext,
14931493
crate: &Crate) -> ~[Attribute] {
14941494

@@ -1505,9 +1505,20 @@ fn synthesize_crate_attrs(ecx: &EncodeContext,
15051505
attr::mk_name_value_item_str(@"vers",
15061506
ecx.link_meta.vers);
15071507

1508-
let mut meta_items = ~[name_item, vers_item];
1508+
let pkgid_item = match ecx.link_meta.package_id {
1509+
Some(pkg_id) => attr::mk_name_value_item_str(@"package_id",
1510+
pkg_id),
1511+
// uses package_id equal to name;
1512+
// this should never happen here but package_id is an Option
1513+
// FIXME (#10370): change package_id in LinkMeta to @str instead of Option<@str>
1514+
_ => attr::mk_name_value_item_str(@"package_id",
1515+
ecx.link_meta.name)
1516+
};
1517+
1518+
let mut meta_items = ~[name_item, vers_item, pkgid_item];
15091519

1510-
for &mi in items.iter().filter(|mi| "name" != mi.name() && "vers" != mi.name()) {
1520+
for &mi in items.iter().filter(|mi| "name" != mi.name() && "vers" != mi.name() &&
1521+
"package_id" != mi.name()) {
15111522
meta_items.push(mi);
15121523
}
15131524
let link_item = attr::mk_list_item(@"link", meta_items);

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#[link(name = "rustdoc",
12+
package_id = "rustdoc",
1213
vers = "0.9-pre",
1314
uuid = "8c6e4598-1596-4aa5-a24c-b811914bbbc6",
1415
url = "https://github.com/mozilla/rust/tree/master/src/librustdoc")];

src/librustpkg/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// rustpkg - a package manager and build system for Rust
1212

1313
#[link(name = "rustpkg",
14+
package_id = "rustpkg",
1415
vers = "0.9-pre",
1516
uuid = "25de5e6e-279e-4a20-845c-4cabae92daaf",
1617
url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")];

src/librustuv/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ via `close` and `delete` methods.
3535
*/
3636

3737
#[link(name = "rustuv",
38+
package_id = "rustuv",
3839
vers = "0.9-pre",
3940
uuid = "f3719011-0459-9b86-b11c-29265c0d0864",
4041
url = "https://github.com/mozilla/rust/tree/master/src/librustuv")];

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
//! use std::prelude::*;
4545
4646
#[link(name = "std",
47+
package_id = "std",
4748
vers = "0.9-pre",
4849
uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8",
4950
url = "https://github.com/mozilla/rust/tree/master/src/libstd")];

src/libsyntax/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#[link(name = "syntax",
17+
package_id = "syntax",
1718
vers = "0.9-pre",
1819
uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")];
1920

src/test/auxiliary/crateresolve8-1.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// default link meta for 'package_id' will be equal to filestem
12+
#[link(name = "crateresolve8",
13+
vers = "0.1")];
14+
15+
#[crate_type = "lib"];
16+
17+
pub fn f() -> int { 20 }

src/test/run-pass/crateresolve8.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast
12+
// aux-build:crateresolve8-1.rs
13+
14+
extern mod crateresolve8(vers = "0.1", package_id="crateresolve8");
15+
//extern mod crateresolve8(vers = "0.1");
16+
17+
pub fn main() {
18+
assert_eq!(crateresolve8::f(), 20);
19+
}

0 commit comments

Comments
 (0)