aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam C. Foltzer <acfoltzer@galois.com>2018-02-21 10:22:18 -0800
committerJussi Pakkanen <jpakkane@gmail.com>2018-02-22 22:16:58 +0200
commit3332f3364901ac282c545e1a463618e86e70cdf9 (patch)
tree70401bf342f5e4e2055a9e1699960b549b24f040
parent2f21e1ffc06ca41dac132018e8bef5bd2fe95ab1 (diff)
downloadmeson-3332f3364901ac282c545e1a463618e86e70cdf9.zip
meson-3332f3364901ac282c545e1a463618e86e70cdf9.tar.gz
meson-3332f3364901ac282c545e1a463618e86e70cdf9.tar.bz2
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.
-rw-r--r--docs/markdown/snippets/rust-private-disambiguation.md6
-rw-r--r--mesonbuild/backend/ninjabackend.py4
-rw-r--r--test cases/rust/7 private crate collision/installed_files.txt2
-rw-r--r--test cases/rust/7 private crate collision/meson.build5
-rw-r--r--test cases/rust/7 private crate collision/prog.rs3
-rw-r--r--test cases/rust/7 private crate collision/rand.rs4
6 files changed, 24 insertions, 0 deletions
diff --git a/docs/markdown/snippets/rust-private-disambiguation.md b/docs/markdown/snippets/rust-private-disambiguation.md
new file mode 100644
index 0000000..6988a7a
--- /dev/null
+++ b/docs/markdown/snippets/rust-private-disambiguation.md
@@ -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.
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 59eaf6b..e8c8b39 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -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 = '.'
diff --git a/test cases/rust/7 private crate collision/installed_files.txt b/test cases/rust/7 private crate collision/installed_files.txt
new file mode 100644
index 0000000..06ebd77
--- /dev/null
+++ b/test cases/rust/7 private crate collision/installed_files.txt
@@ -0,0 +1,2 @@
+usr/bin/prog?exe
+usr/lib/librand.rlib
diff --git a/test cases/rust/7 private crate collision/meson.build b/test cases/rust/7 private crate collision/meson.build
new file mode 100644
index 0000000..81b6aab
--- /dev/null
+++ b/test cases/rust/7 private crate collision/meson.build
@@ -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)
diff --git a/test cases/rust/7 private crate collision/prog.rs b/test cases/rust/7 private crate collision/prog.rs
new file mode 100644
index 0000000..b9a30f1
--- /dev/null
+++ b/test cases/rust/7 private crate collision/prog.rs
@@ -0,0 +1,3 @@
+extern crate rand;
+
+fn main() { println!("printing: {}", rand::explore()); }
diff --git a/test cases/rust/7 private crate collision/rand.rs b/test cases/rust/7 private crate collision/rand.rs
new file mode 100644
index 0000000..8a3d427
--- /dev/null
+++ b/test cases/rust/7 private crate collision/rand.rs
@@ -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" }