Re: [PATCH 04/11] rust: Do not link qemuutil into Rust rlibs

Zhao Liu <[email protected]>
Newsgroups org.nongnu.qemu-rust,org.nongnu.qemu-devel
Message-ID <[email protected]>
On Mon, Dec 15, 2025 at 08:49:53AM +0100, Paolo Bonzini wrote:
> Date: Mon, 15 Dec 2025 08:49:53 +0100
> From: Paolo Bonzini <[email protected]>
> Subject: [PATCH 04/11] rust: Do not link qemuutil into Rust rlibs
> X-Mailer: git-send-email 2.52.0
> 
> From: Martin Kletzander <[email protected]>
> 
> 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 <[email protected]>
> Signed-off-by: Paolo Bonzini <[email protected]>
> ---
>  rust/chardev/meson.build | 2 +-
>  rust/qom/meson.build     | 2 +-
>  rust/util/meson.build    | 4 ++--
>  3 files changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Zhao Liu <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.