From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org, Martin Kletzander <mkletzan@redhat.com>
Subject: [PATCH 8/9] rust: Do not link qemuutil into Rust rlibs
Date: Thu, 27 Nov 2025 14:20:35 +0100 [thread overview]
Message-ID: <20251127132036.84384-9-pbonzini@redhat.com> (raw)
In-Reply-To: <20251127132036.84384-1-pbonzini@redhat.com>
From: Martin Kletzander <mkletzan@redhat.com>
Commit de037ab8d83d removed qemuutil dependency from chardev and util
rust crates. However it stayed in the _util_rs static library. The
dependency is also defined as `link_with`, which is fine for C targets,
where the resulting archive gets linked as another parameter on the
command line when it is a static library.
However, when a C library is linked into a Rust rlib, rustc remembers
the dependency into the metadata and adds the library to the linker
command line.
Unfortunately, static libraries are sensitive to their
position on the command line and rustc does not always get it right.
Fortunately, simply removing it from dependencies of any rust libraries
and instead adding them into the dependencies of executables and
doctests fixes the behaviour.
Without this patch the error I get is:
FAILED: [code=1] rust/tests/rust-integration
...
= note: rust-lld: error: unable to find library -l:libqemuutil.a
rust-lld: error: unable to find library -l:libvhost-user-glib.a
rust-lld: error: unable to find library -l:libvhost-user.a
rust-lld: error: unable to find library -l:libqemuutil.a
rust-lld: error: unable to find library -l:libvhost-user-glib.a
rust-lld: error: unable to find library -l:libvhost-user.a
rust-lld: error: unable to find library -l:libqemuutil.a
rust-lld: error: unable to find library -l:libvhost-user-glib.a
rust-lld: error: unable to find library -l:libvhost-user.a
rust-lld: error: unable to find library -l:libqemuutil.a
rust-lld: error: unable to find library -l:libvhost-user-glib.a
rust-lld: error: unable to find library -l:libvhost-user.a
rust-lld: error: unable to find library -l:libqemuutil.a
rust-lld: error: unable to find library -l:libvhost-user-glib.a
rust-lld: error: unable to find library -l:libvhost-user.a
rust-lld: error: unable to find library -l:libqemuutil.a
rust-lld: error: unable to find library -l:libvhost-user-glib.a
rust-lld: error: unable to find library -l:libvhost-user.a
collect2: error: ld returned 1 exit status
Meson could work around it itself by never adding these static libraries
to the rlibs (after all, Meson tracks the transitive dependencies already
and knows how to add them to dependents of those rlibs); at least for now,
do it in QEMU: never link C libraries into Rust rlibs, and add them to the
final build products only.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/chardev/meson.build | 2 +-
rust/qom/meson.build | 2 +-
rust/util/meson.build | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/rust/chardev/meson.build b/rust/chardev/meson.build
index 6b681c609ad..204977ca47c 100644
--- a/rust/chardev/meson.build
+++ b/rust/chardev/meson.build
@@ -37,4 +37,4 @@ _chardev_rs = static_library(
dependencies: [glib_sys_rs, common_rs, qemu_macros],
)
-chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [chardev])
+chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [chardev, qemuutil])
diff --git a/rust/qom/meson.build b/rust/qom/meson.build
index 551c4f0bf5f..dda26c3f981 100644
--- a/rust/qom/meson.build
+++ b/rust/qom/meson.build
@@ -30,7 +30,7 @@ _qom_rs = static_library(
dependencies: [common_rs, glib_sys_rs, qemu_macros],
)
-qom_rs = declare_dependency(link_with: [_qom_rs], dependencies: [qemu_macros, qom])
+qom_rs = declare_dependency(link_with: [_qom_rs], dependencies: [qemu_macros, qom, qemuutil])
# Doctests are essentially integration tests, so they need the same dependencies.
# Note that running them requires the object files for C code, so place them
diff --git a/rust/util/meson.build b/rust/util/meson.build
index 18d67a4b374..95aa211ef0b 100644
--- a/rust/util/meson.build
+++ b/rust/util/meson.build
@@ -38,10 +38,10 @@ _util_rs = static_library(
],
{'.': _util_bindings_inc_rs}
),
- dependencies: [anyhow_rs, libc_rs, foreign_rs, glib_sys_rs, common_rs, qom, qemuutil],
+ dependencies: [anyhow_rs, libc_rs, foreign_rs, glib_sys_rs, common_rs],
)
-util_rs = declare_dependency(link_with: [_util_rs])
+util_rs = declare_dependency(link_with: [_util_rs], dependencies: [qemuutil, qom])
rust.test('rust-util-tests', _util_rs,
dependencies: [qemuutil, qom],
--
2.51.1
next prev parent reply other threads:[~2025-11-27 13:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 13:20 [PATCH 0/9] rust: build system and other cleanups Paolo Bonzini
2025-11-27 13:20 ` [PATCH 1/9] rust: remove leftover bindings/ Paolo Bonzini
2025-12-03 9:11 ` Zhao Liu
2025-11-27 13:20 ` [PATCH 2/9] rust: remove unused --cfg arguments Paolo Bonzini
2025-12-03 10:25 ` Zhao Liu
2025-11-27 13:20 ` [PATCH 3/9] rust: remove unnecessary repetitive options Paolo Bonzini
2025-12-03 10:37 ` Zhao Liu
2025-11-27 13:20 ` [PATCH 4/9] rust/bql: make bindings public Paolo Bonzini
2025-12-03 10:58 ` Zhao Liu
2025-11-27 13:20 ` [PATCH 5/9] rust: do not copy the SysBusDevice Paolo Bonzini
2025-12-03 10:59 ` Zhao Liu
2025-11-27 13:20 ` [PATCH 6/9] rust: fix reference to MemoryRegion Paolo Bonzini
2025-12-03 11:00 ` Zhao Liu
2025-11-27 13:20 ` [PATCH 7/9] rust: move strict lints handling to meson.build Paolo Bonzini
2025-12-03 15:29 ` Zhao Liu
2025-11-27 13:20 ` Paolo Bonzini [this message]
2025-11-27 13:20 ` [PATCH 9/9] rust: only link the Rust part of the code into devices Paolo Bonzini
2025-12-03 9:32 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251127132036.84384-9-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=mkletzan@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).