Skip to content

Commit 17bcc1b

Browse files
committed
auto merge of #16505 : dotdash/rust/extern_realpath, r=alexcrichton
Crates that are resolved normally have their path canonicalized and all symlinks resolved. This does currently not happen for paths specified using the --extern option to rustc, which can lead to rustc thinking that it encountered two different versions of a crate, when it's actually the same version found through different paths. Fixes #16496
2 parents 22b7e4d + a5590b3 commit 17bcc1b

File tree

6 files changed

+67
-3
lines changed

6 files changed

+67
-3
lines changed

src/librustc/metadata/creader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use syntax::diagnostic::SpanHandler;
3333
use syntax::parse::token::InternedString;
3434
use syntax::parse::token;
3535
use syntax::visit;
36+
use util::fs;
3637

3738
struct Env<'a> {
3839
sess: &'a Session,
@@ -301,7 +302,7 @@ fn existing_match(e: &Env, name: &str,
301302
match e.sess.opts.externs.find_equiv(&name) {
302303
Some(locs) => {
303304
let found = locs.iter().any(|l| {
304-
let l = Some(Path::new(l.as_slice()));
305+
let l = fs::realpath(&Path::new(l.as_slice())).ok();
305306
l == source.dylib || l == source.rlib
306307
});
307308
if found {

src/librustc/metadata/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ impl<'a> Context<'a> {
666666
let mut dylibs = HashSet::new();
667667
for loc in locs {
668668
if loc.filename_str().unwrap().ends_with(".rlib") {
669-
rlibs.insert(loc.clone());
669+
rlibs.insert(fs::realpath(&loc).unwrap());
670670
} else {
671-
dylibs.insert(loc.clone());
671+
dylibs.insert(fs::realpath(&loc).unwrap());
672672
}
673673
}
674674

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-include ../tools.mk
2+
3+
# ignore windows: `ln` is actually `cp` on msys.
4+
ifndef IS_WINDOWS
5+
6+
all:
7+
$(RUSTC) foo.rs
8+
mkdir -p $(TMPDIR)/other
9+
ln -nsf $(TMPDIR)/libfoo.rlib $(TMPDIR)/other
10+
$(RUSTC) bar.rs -L $(TMPDIR)
11+
$(RUSTC) baz.rs --extern foo=$(TMPDIR)/other/libfoo.rlib -L $(TMPDIR)
12+
13+
else
14+
all:
15+
16+
endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2012-2014 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+
#![crate_type = "rlib"]
12+
13+
extern crate foo;
14+
15+
pub fn bar(_s: foo::S) {
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2012-2014 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+
extern crate bar;
12+
extern crate foo;
13+
14+
fn main() {
15+
bar::bar(foo::foo());
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2012-2014 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+
#![crate_type = "rlib"]
12+
13+
pub struct S;
14+
15+
pub fn foo() -> S { S }

0 commit comments

Comments
 (0)