Merge pull request #8429 from dcbaker/submit/rust-fix-linking-with-find-library

rust: correctly handle -l link args
This commit is contained in:
Dylan Baker 2021-02-26 16:50:53 -08:00 committed by GitHub
commit 6a9a1557e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 2 deletions

View File

@ -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 = '.'

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 }
]
}
}
}