From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org, manos.pitsidianakis@linaro.org
Subject: [PATCH 2/2] meson: let Meson handle mixed-language linking of Rust and C objects
Date: Mon, 11 Aug 2025 18:17:37 +0200 [thread overview]
Message-ID: <20250811161737.220835-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20250811161737.220835-1-pbonzini@redhat.com>
Meson 1.9.0 can pass C objects into rustc so that the final link pass can
add the Rust libstd. Use that to eliminate the staticlib and allow
dynamic linking with libstd (also introduced by Meson 1.9.0, but not
for staticlib crates due to lack of support in rustc).
The main() function is still provided by C, which is possible by
declaring the main source file of the Rust executable (which is
created by scripts/rust/rust_root_crate.sh) as #![no_main].
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
meson.build | 19 ++++++++-----------
scripts/rust/rust_root_crate.sh | 1 +
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/meson.build b/meson.build
index e53cd5b4138..0a921272f57 100644
--- a/meson.build
+++ b/meson.build
@@ -4377,25 +4377,22 @@ foreach target : target_dirs
arch_srcs += target_specific.sources()
arch_deps += target_specific.dependencies()
+ main_rs = []
+ crates = []
if have_rust and target_type == 'system'
target_rust = rust_devices_ss.apply(config_target, strict: false)
- crates = []
+ arch_deps += target_rust.dependencies()
foreach dep : target_rust.dependencies()
crates += dep.get_variable('crate')
endforeach
if crates.length() > 0
- rlib_rs = custom_target('rust_' + target.underscorify() + '.rs',
+ main_rs = custom_target('rust_' + target.underscorify() + '.rs',
output: 'rust_' + target.underscorify() + '.rs',
command: [rust_root_crate, crates],
capture: true,
build_by_default: true,
build_always_stale: true)
- rlib = static_library('rust_' + target.underscorify(),
- structured_sources([], {'.': rlib_rs}),
- dependencies: target_rust.dependencies(),
- override_options: ['rust_std=2021', 'build.rust_std=2021'],
- rust_abi: 'c')
- arch_deps += declare_dependency(link_whole: [rlib])
+ main_rs = structured_sources(main_rs)
endif
endif
@@ -4419,14 +4416,14 @@ foreach target : target_dirs
execs = [{
'name': 'qemu-system-' + target_name,
'win_subsystem': 'console',
- 'sources': files('system/main.c'),
+ 'sources': [main_rs, files('system/main.c')],
'dependencies': [sdl]
}]
if host_os == 'windows' and (sdl.found() or gtk.found())
execs += [{
'name': 'qemu-system-' + target_name + 'w',
'win_subsystem': 'windows',
- 'sources': files('system/main.c'),
+ 'sources': [main_rs, files('system/main.c')],
'dependencies': [sdl]
}]
endif
@@ -4435,7 +4432,7 @@ foreach target : target_dirs
execs += [{
'name': 'qemu-fuzz-' + target_name,
'win_subsystem': 'console',
- 'sources': specific_fuzz.sources(),
+ 'sources': [main_rs, specific_fuzz.sources()],
'dependencies': specific_fuzz.dependencies(),
}]
endif
diff --git a/scripts/rust/rust_root_crate.sh b/scripts/rust/rust_root_crate.sh
index 975bddf7f1a..1ee88114ad9 100755
--- a/scripts/rust/rust_root_crate.sh
+++ b/scripts/rust/rust_root_crate.sh
@@ -6,6 +6,7 @@ cat <<EOF
// @generated
// This file is autogenerated by scripts/rust_root_crate.sh
+#![no_main]
EOF
for crate in $*; do
--
2.50.1
prev parent reply other threads:[~2025-08-11 16:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 16:17 [PATCH for-10.2 0/2] meson: let Meson handle mixed-language linking of Rust and C objects Paolo Bonzini
2025-08-11 16:17 ` [PATCH 1/2] rust: do not link C libraries into Rust rlibs Paolo Bonzini
2025-08-11 16:17 ` Paolo Bonzini [this message]
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=20250811161737.220835-3-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--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).