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

rust: correctly handle -l link args
pull/8432/head
Dylan Baker 4 years ago committed by GitHub
commit 6a9a1557e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      mesonbuild/backend/ninjabackend.py
  2. 24
      test cases/rust/14 external libm/meson.build
  3. 2
      test cases/rust/14 external libm/meson_options.txt
  4. 5
      test cases/rust/14 external libm/prog.rs
  5. 12
      test cases/rust/14 external libm/rs_math.rs
  6. 10
      test cases/rust/14 external libm/test.json

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

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

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

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

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

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