Fix Rust compiler-private library ambiguity

When building a Rust target with Rust library dependencies, an
`--extern` argument is now specified to avoid ambiguity between the
dependency library, and any crates of the same name in `rustc`'s
private sysroot.

Includes an illustrative test case.
pull/3136/head
Adam C. Foltzer 7 years ago committed by Jussi Pakkanen
parent 2f21e1ffc0
commit 3332f33649
  1. 6
      docs/markdown/snippets/rust-private-disambiguation.md
  2. 4
      mesonbuild/backend/ninjabackend.py
  3. 2
      test cases/rust/7 private crate collision/installed_files.txt
  4. 5
      test cases/rust/7 private crate collision/meson.build
  5. 3
      test cases/rust/7 private crate collision/prog.rs
  6. 4
      test cases/rust/7 private crate collision/rand.rs

@ -0,0 +1,6 @@
## Rust compiler-private library disambiguation
When building a Rust target with Rust library dependencies, an
`--extern` argument is now specified to avoid ambiguity between the
dependency library, and any crates of the same name in `rustc`'s
private sysroot.

@ -1276,6 +1276,10 @@ int dummy;
linkdirs = OrderedDict()
for d in target.link_targets:
linkdirs[d.subdir] = True
# specify `extern CRATE_NAME=OUTPUT_FILE` for each Rust
# dependency, so that collisions with libraries in rustc's
# sysroot don't cause ambiguity
args += ['--extern', '{}={}'.format(d.name, os.path.join(d.subdir, d.filename))]
for d in linkdirs.keys():
if d == '':
d = '.'

@ -0,0 +1,2 @@
usr/bin/prog?exe
usr/lib/librand.rlib

@ -0,0 +1,5 @@
project('rust private crate collision', 'rust')
l = static_library('rand', 'rand.rs', install : true)
e = executable('prog', 'prog.rs', link_with : l, install : true)
test('linktest', e)

@ -0,0 +1,3 @@
extern crate rand;
fn main() { println!("printing: {}", rand::explore()); }

@ -0,0 +1,4 @@
// use a name that collides with one of the rustc_private libraries
#![crate_name = "rand"]
pub fn explore() -> &'static str { "librarystring" }
Loading…
Cancel
Save