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.)
This commit is contained in:
Jordan Justen 2021-02-26 10:24:25 -08:00 committed by Dylan Baker
parent e079553959
commit e127e47d7a
5 changed files with 53 additions and 0 deletions

View File

@ -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)

View File

@ -0,0 +1,2 @@
option('static', type : 'boolean')
option('method', type : 'string')

View File

@ -0,0 +1,5 @@
extern crate rs_math;
fn main() {
assert_eq!(rs_math::rs_log2(8.0), 3.0);
}

View File

@ -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) }
}

View File

@ -0,0 +1,10 @@
{
"matrix": {
"options": {
"static": [
{ "val": true },
{ "val": false }
]
}
}
}