diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2024-03-04 16:01:04 -0500 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2024-03-05 09:18:32 -0500 |
commit | 5e0a3073dad6ec4c4bdbccb755338f01b805fe53 (patch) | |
tree | 0ca4024c3db769585dfb8fd0394b109f216910fe | |
parent | a9d42a7c1e567fb18f835c9f352c0b0efad8391b (diff) | |
download | meson-5e0a3073dad6ec4c4bdbccb755338f01b805fe53.zip meson-5e0a3073dad6ec4c4bdbccb755338f01b805fe53.tar.gz meson-5e0a3073dad6ec4c4bdbccb755338f01b805fe53.tar.bz2 |
rust: Link with rlib external dependencies
When linking with a Rust rlib, we should also link with its external
system dependencies. This was currently done only for C ABI crates, do
it for both rlib and staticlib now.
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 5 | ||||
-rw-r--r-- | test cases/rust/24 system deps/main.rs | 5 | ||||
-rw-r--r-- | test cases/rust/24 system deps/meson.build | 9 | ||||
-rw-r--r-- | test cases/rust/24 system deps/wrapper.rs | 9 |
4 files changed, 25 insertions, 3 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 74994d0..f665e61 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1979,6 +1979,8 @@ class NinjaBackend(backends.Backend): for d in target_deps: linkdirs.add(d.subdir) deps.append(self.get_dependency_filename(d)) + if isinstance(d, build.StaticLibrary): + external_deps.extend(d.external_deps) if d.uses_rust_abi(): if d not in itertools.chain(target.link_targets, target.link_whole_targets): # Indirect Rust ABI dependency, we only need its path in linkdirs. @@ -1993,9 +1995,6 @@ class NinjaBackend(backends.Backend): # Link a C ABI library - if isinstance(d, build.StaticLibrary): - external_deps.extend(d.external_deps) - # Pass native libraries directly to the linker with "-C link-arg" # because rustc's "-l:+verbatim=" is not portable and we cannot rely # on linker to find the right library without using verbatim filename. diff --git a/test cases/rust/24 system deps/main.rs b/test cases/rust/24 system deps/main.rs new file mode 100644 index 0000000..cfa599b --- /dev/null +++ b/test cases/rust/24 system deps/main.rs @@ -0,0 +1,5 @@ +extern crate wrapper; + +fn main() { + wrapper::func(); +} diff --git a/test cases/rust/24 system deps/meson.build b/test cases/rust/24 system deps/meson.build new file mode 100644 index 0000000..d9160f1 --- /dev/null +++ b/test cases/rust/24 system deps/meson.build @@ -0,0 +1,9 @@ +project('system deps', 'rust') + +glib = dependency('glib-2.0', required: false) +if not glib.found() + error('MESON_SKIP_TEST: Need glib system dependency') +endif + +rlib = static_library('wrapper', 'wrapper.rs', dependencies: glib) +exe = executable('main', 'main.rs', link_with: rlib) diff --git a/test cases/rust/24 system deps/wrapper.rs b/test cases/rust/24 system deps/wrapper.rs new file mode 100644 index 0000000..630cd77 --- /dev/null +++ b/test cases/rust/24 system deps/wrapper.rs @@ -0,0 +1,9 @@ +extern "C" { + fn g_hash_table_new() -> *mut std::ffi::c_void; +} + +pub fn func() { + unsafe { + g_hash_table_new(); + } +} |