aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-02-26 16:50:53 -0800
committerGitHub <noreply@github.com>2021-02-26 16:50:53 -0800
commit6a9a1557e4895525c7a39bfd41b32b51505a56d0 (patch)
treecb90b98720dc7ffc0f036c741317c3efc4d318ad
parent219535aad426e9678fcab4887c1fdce321d2ba05 (diff)
parentd7d80945ea00f3536fd529a8f61ca3351fef4a2d (diff)
downloadmeson-6a9a1557e4895525c7a39bfd41b32b51505a56d0.zip
meson-6a9a1557e4895525c7a39bfd41b32b51505a56d0.tar.gz
meson-6a9a1557e4895525c7a39bfd41b32b51505a56d0.tar.bz2
Merge pull request #8429 from dcbaker/submit/rust-fix-linking-with-find-library
rust: correctly handle -l link args
-rw-r--r--mesonbuild/backend/ninjabackend.py4
-rw-r--r--test cases/rust/14 external libm/meson.build24
-rw-r--r--test cases/rust/14 external libm/meson_options.txt2
-rw-r--r--test cases/rust/14 external libm/prog.rs5
-rw-r--r--test cases/rust/14 external libm/rs_math.rs12
-rw-r--r--test cases/rust/14 external libm/test.json10
6 files changed, 55 insertions, 2 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index b7723ef..240cc0a 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1624,8 +1624,8 @@ int dummy;
elif a.startswith('-L'):
args.append(a)
elif a.startswith('-l'):
- # This should always be a static lib, I think
- args.extend(['-l', f'static={a[2:]}'])
+ _type = 'static' if e.static else 'dylib'
+ args.extend(['-l', f'{_type}={a[2:]}'])
for d in linkdirs:
if d == '':
d = '.'
diff --git a/test cases/rust/14 external libm/meson.build b/test cases/rust/14 external libm/meson.build
new file mode 100644
index 0000000..20af83c
--- /dev/null
+++ b/test cases/rust/14 external libm/meson.build
@@ -0,0 +1,24 @@
+project('rust linking to libm', 'c', 'rust')
+
+if host_machine.system() == 'darwin'
+ error('MESON_SKIP_TEST: doesnt work right on macos, please fix!')
+endif
+
+cc = meson.get_compiler('c')
+dep_m = cc.find_library('m', required : false, static : get_option('static'))
+if not dep_m.found()
+ error('MESON_SKIP_TEST: Could not find a @0@ libm'.format(get_option('static') ? 'static' : 'shared'))
+endif
+
+librs_math = static_library(
+ 'rs_math',
+ 'rs_math.rs',
+ dependencies : [dep_m],
+)
+
+e = executable(
+ 'prog', 'prog.rs',
+ link_with : [librs_math],
+)
+
+test('cdepstest', e)
diff --git a/test cases/rust/14 external libm/meson_options.txt b/test cases/rust/14 external libm/meson_options.txt
new file mode 100644
index 0000000..f501348
--- /dev/null
+++ b/test cases/rust/14 external libm/meson_options.txt
@@ -0,0 +1,2 @@
+option('static', type : 'boolean')
+option('method', type : 'string')
diff --git a/test cases/rust/14 external libm/prog.rs b/test cases/rust/14 external libm/prog.rs
new file mode 100644
index 0000000..6745977
--- /dev/null
+++ b/test cases/rust/14 external libm/prog.rs
@@ -0,0 +1,5 @@
+extern crate rs_math;
+
+fn main() {
+ assert_eq!(rs_math::rs_log2(8.0), 3.0);
+}
diff --git a/test cases/rust/14 external libm/rs_math.rs b/test cases/rust/14 external libm/rs_math.rs
new file mode 100644
index 0000000..ef53a5c
--- /dev/null
+++ b/test cases/rust/14 external libm/rs_math.rs
@@ -0,0 +1,12 @@
+#![crate_name = "rs_math"]
+
+use std::os::raw::c_double;
+
+extern "C" {
+ fn log2(n: c_double) -> c_double;
+}
+
+#[no_mangle]
+pub extern fn rs_log2(n: c_double) -> c_double {
+ unsafe { log2(n) }
+}
diff --git a/test cases/rust/14 external libm/test.json b/test cases/rust/14 external libm/test.json
new file mode 100644
index 0000000..42d8fe9
--- /dev/null
+++ b/test cases/rust/14 external libm/test.json
@@ -0,0 +1,10 @@
+{
+ "matrix": {
+ "options": {
+ "static": [
+ { "val": true },
+ { "val": false }
+ ]
+ }
+ }
+}