diff options
author | Jordan Justen <jljusten@gmail.com> | 2021-02-26 10:24:25 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-02-26 11:58:47 -0800 |
commit | e127e47d7a5aadc18240c920c8b24f32acff67a2 (patch) | |
tree | 188c1e4e4d8cb0d9b1ca34012ffa39696f3a590c /test cases/rust | |
parent | e0795539598c8dd21756158d0687b461712f0a21 (diff) | |
download | meson-e127e47d7a5aadc18240c920c8b24f32acff67a2.zip meson-e127e47d7a5aadc18240c920c8b24f32acff67a2.tar.gz meson-e127e47d7a5aadc18240c920c8b24f32acff67a2.tar.bz2 |
tests/rust: Add rust case linking to libm in rust static library
When building on Linux, I see:
rustc -C linker=cc --color=always --crate-type rlib --crate-name rs_math -g --emit dep-info=rs_math.d --emit link -L /usr/lib/x86_64-linux-gnu -o librs_math.rlib -l static=m ../rs_math.rs
error: failed to add native library /usr/lib/x86_64-linux-gnu/libm.a: file too small to be an archive
I think the "file too small to be an archive" message is coming from
libLLVM, and is a case of LLVM not handling this type of "script
archive". So, possibly this is just LLVM not handling a linking case.
The rust_args usage in meson.build is invalid, but required to
reproduce the issue in the test case. Perhaps meson should
automatically add the library include path via the dep_m meson object,
or maybe the meson.build can add the link path in a better way.
Changing '-l static=m' to '-l dylib=m' appears to fix this case. (See
comments in meson.build.)
Diffstat (limited to 'test cases/rust')
-rw-r--r-- | test cases/rust/14 external libm/meson.build | 24 | ||||
-rw-r--r-- | test cases/rust/14 external libm/meson_options.txt | 2 | ||||
-rw-r--r-- | test cases/rust/14 external libm/prog.rs | 5 | ||||
-rw-r--r-- | test cases/rust/14 external libm/rs_math.rs | 12 | ||||
-rw-r--r-- | test cases/rust/14 external libm/test.json | 10 |
5 files changed, 53 insertions, 0 deletions
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 } + ] + } + } +} |