* [PATCH preview 0/3] rust: update build system for Meson 1.8.0
@ 2025-04-05 10:06 Paolo Bonzini
2025-04-05 10:06 ` [PATCH 1/3] rust: use "objects" for Rust executables as well Paolo Bonzini
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Paolo Bonzini @ 2025-04-05 10:06 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-rust
Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
* support for "objects" in Rust executables
* support for doctest targets
Use it to remove BQL-related hacks, fix --enable-modules --enable-rust
and also simplify the Meson logic for building the qemu-api crate
(which may help splitting the crate, too).
Meson also supports clippy and rustdoc but there are some bugs in the
prerelease. I'll try to get them fixed before 1.8.0.
Paolo
Paolo Bonzini (3):
rust: use "objects" for Rust executables as well
rust: add qemu-api doctests to "meson test"
rust: cell: remove support for running doctests with "cargo test --doc"
docs/devel/rust.rst | 2 --
.gitlab-ci.d/buildtest.yml | 5 -----
rust/qemu-api/meson.build | 35 +++++++++++++++--------------------
rust/qemu-api/src/cell.rs | 22 +++++++++-------------
4 files changed, 24 insertions(+), 40 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] rust: use "objects" for Rust executables as well
2025-04-05 10:06 [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Paolo Bonzini
@ 2025-04-05 10:06 ` Paolo Bonzini
2025-04-05 10:06 ` [PATCH 2/3] rust: add qemu-api doctests to "meson test" Paolo Bonzini
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2025-04-05 10:06 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-rust, Bernhard Beschow
libqemuutil is not meant be linked as a whole; if modules are enabled, doing
so results in undefined symbols (corresponding to QMP commands) in
rust/qemu-api/rust-qemu-api-integration.
Support for "objects" in Rust executables is available in Meson 1.8.0; use it
to switching to the same dependencies that C targets use: link_with for
libqemuutil, and objects for everything else.
Reported-by: Bernhard Beschow <shentey@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
docs/devel/rust.rst | 2 --
rust/qemu-api/meson.build | 26 +++++---------------------
2 files changed, 5 insertions(+), 23 deletions(-)
diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst
index 88bdec1eb28..8030aa42d0c 100644
--- a/docs/devel/rust.rst
+++ b/docs/devel/rust.rst
@@ -66,8 +66,6 @@ be run via ``meson test`` or ``make``::
make check-rust
-Building Rust code with ``--enable-modules`` is not supported yet.
-
Supported tools
'''''''''''''''
diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build
index 858685ddd4a..8fa41c0a95e 100644
--- a/rust/qemu-api/meson.build
+++ b/rust/qemu-api/meson.build
@@ -45,29 +45,13 @@ _qemu_api_rs = static_library(
dependencies: [libc_dep, qemu_api_macros],
)
+qemuutil_rs = qemuutil.partial_dependency(link_args: true, links: true)
+
rust.test('rust-qemu-api-tests', _qemu_api_rs,
suite: ['unit', 'rust'])
-qemu_api = declare_dependency(link_with: _qemu_api_rs)
-
-# Rust executables do not support objects, so add an intermediate step.
-rust_qemu_api_objs = static_library(
- 'rust_qemu_api_objs',
- objects: [libqom.extract_all_objects(recursive: false),
- libhwcore.extract_all_objects(recursive: false),
- libchardev.extract_all_objects(recursive: false),
- libcrypto.extract_all_objects(recursive: false),
- libauthz.extract_all_objects(recursive: false),
- libio.extract_all_objects(recursive: false),
- libmigration.extract_all_objects(recursive: false)])
-rust_qemu_api_deps = declare_dependency(
- dependencies: [
- qom_ss.dependencies(),
- chardev_ss.dependencies(),
- crypto_ss.dependencies(),
- authz_ss.dependencies(),
- io_ss.dependencies()],
- link_whole: [rust_qemu_api_objs, libqemuutil])
+qemu_api = declare_dependency(link_with: [_qemu_api_rs],
+ dependencies: [qemuutil_rs, qemu_api_macros, qom, hwcore, chardev, migration])
test('rust-qemu-api-integration',
executable(
@@ -76,7 +60,7 @@ test('rust-qemu-api-integration',
override_options: ['rust_std=2021', 'build.rust_std=2021'],
rust_args: ['--test'],
install: false,
- dependencies: [qemu_api, qemu_api_macros, rust_qemu_api_deps]),
+ dependencies: qemu_api),
args: [
'--test', '--test-threads', '1',
'--format', 'pretty',
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] rust: add qemu-api doctests to "meson test"
2025-04-05 10:06 [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Paolo Bonzini
2025-04-05 10:06 ` [PATCH 1/3] rust: use "objects" for Rust executables as well Paolo Bonzini
@ 2025-04-05 10:06 ` Paolo Bonzini
2025-04-05 10:06 ` [PATCH 3/3] rust: cell: remove support for running doctests with "cargo test --doc" Paolo Bonzini
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2025-04-05 10:06 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-rust
Doctest are weird. They are essentially integration tests, but they're
"ran" by executing rustdoc --test, which takes a compiler-ish
command line. This is supported by Meson 1.8.0.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
.gitlab-ci.d/buildtest.yml | 5 -----
rust/qemu-api/meson.build | 11 +++++++++++
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml
index 00f4bfcd9f3..088d5683c88 100644
--- a/.gitlab-ci.d/buildtest.yml
+++ b/.gitlab-ci.d/buildtest.yml
@@ -131,12 +131,7 @@ build-system-fedora-rust-nightly:
IMAGE: fedora-rust-nightly
CONFIGURE_ARGS: --disable-docs --enable-rust --enable-strict-rust-lints
TARGETS: aarch64-softmmu
- MAKE_CHECK_ARGS: check-build
- after_script:
- - source scripts/ci/gitlab-ci-section
- - section_start test "Running Rust doctests"
- - cd build
- - pyvenv/bin/meson devenv -w ../rust ${CARGO-cargo} test --doc -p qemu_api
+ MAKE_CHECK_ARGS: check-build check-doc
allow_failure: true
diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build
index 8fa41c0a95e..ede6e14e5e0 100644
--- a/rust/qemu-api/meson.build
+++ b/rust/qemu-api/meson.build
@@ -53,6 +53,17 @@ rust.test('rust-qemu-api-tests', _qemu_api_rs,
qemu_api = declare_dependency(link_with: [_qemu_api_rs],
dependencies: [qemuutil_rs, qemu_api_macros, qom, hwcore, chardev, migration])
+# Doctests are essentially integration tests, so they need the same "depends" as
+# below and cannot be run with "cargo test --doc". Developer tools are only
+# supported for versions 1.74.0 or newer of Rust.
+if rustc.version().version_compare('>=1.74.0')
+ rust.doctest('rust-qemu-api-doctests',
+ _qemu_api_rs,
+ protocol: 'rust',
+ dependencies: qemu_api,
+ suite: ['doc', 'rust'])
+endif
+
test('rust-qemu-api-integration',
executable(
'rust-qemu-api-integration',
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] rust: cell: remove support for running doctests with "cargo test --doc"
2025-04-05 10:06 [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Paolo Bonzini
2025-04-05 10:06 ` [PATCH 1/3] rust: use "objects" for Rust executables as well Paolo Bonzini
2025-04-05 10:06 ` [PATCH 2/3] rust: add qemu-api doctests to "meson test" Paolo Bonzini
@ 2025-04-05 10:06 ` Paolo Bonzini
2025-04-05 12:23 ` [PATCH 4/3] rust: use native Meson support for clippy and rustdoc Paolo Bonzini
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2025-04-05 10:06 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-rust
This is not needed anymore now that tests link with libqemuutil.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api/src/cell.rs | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs
index ab0785a2692..b3d68bf4a0d 100644
--- a/rust/qemu-api/src/cell.rs
+++ b/rust/qemu-api/src/cell.rs
@@ -225,27 +225,23 @@
/// An internal function that is used by doctests.
pub fn bql_start_test() {
- if cfg!(MESON) {
- // SAFETY: integration tests are run with --test-threads=1, while
- // unit tests and doctests are not multithreaded and do not have
- // any BQL-protected data. Just set bql_locked to true.
- unsafe {
- bindings::rust_bql_mock_lock();
- }
+ // SAFETY: integration tests are run with --test-threads=1, while
+ // unit tests and doctests are not multithreaded and do not have
+ // any BQL-protected data. Just set bql_locked to true.
+ unsafe {
+ bindings::rust_bql_mock_lock();
}
}
pub fn bql_locked() -> bool {
// SAFETY: the function does nothing but return a thread-local bool
- !cfg!(MESON) || unsafe { bindings::bql_locked() }
+ unsafe { bindings::bql_locked() }
}
fn bql_block_unlock(increase: bool) {
- if cfg!(MESON) {
- // SAFETY: this only adjusts a counter
- unsafe {
- bindings::bql_block_unlock(increase);
- }
+ // SAFETY: this only adjusts a counter
+ unsafe {
+ bindings::bql_block_unlock(increase);
}
}
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/3] rust: use native Meson support for clippy and rustdoc
2025-04-05 10:06 [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Paolo Bonzini
` (2 preceding siblings ...)
2025-04-05 10:06 ` [PATCH 3/3] rust: cell: remove support for running doctests with "cargo test --doc" Paolo Bonzini
@ 2025-04-05 12:23 ` Paolo Bonzini
2025-04-07 7:37 ` [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Zhao Liu
2025-04-08 20:34 ` Bernhard Beschow
5 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2025-04-05 12:23 UTC (permalink / raw)
To: qemu-devel
Meson has support for invoking clippy and rustdoc on all crates
(1.7.0 for clippy, 1.8.0 for rustdoc). Use it instead of the
homegrown version.
rustfmt is still not supported.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
meson.build | 2 +-
rust/clippy.toml => clippy.toml | 0
rust/Cargo.toml | 1 -
rust/meson.build | 12 ------------
scripts/rust/rustc_args.py | 5 +----
5 files changed, 2 insertions(+), 18 deletions(-)
rename rust/clippy.toml => clippy.toml (100%)
diff --git a/meson.build b/meson.build
index ce4c947e956..d4a868c5188 100644
--- a/meson.build
+++ b/meson.build
@@ -4241,7 +4241,7 @@ foreach target : target_dirs
build_by_default: true,
build_always_stale: true)
rlib = static_library('rust_' + target.underscorify(),
- rlib_rs,
+ structured_sources([], {'.': rlib_rs}),
dependencies: target_rust.dependencies(),
override_options: ['rust_std=2021', 'build.rust_std=2021'],
rust_abi: 'c')
diff --git a/rust/clippy.toml b/clippy.toml
similarity index 100%
rename from rust/clippy.toml
rename to clippy.toml
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index ab1185a8143..38870f06c11 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -56,7 +56,6 @@ ignored_unit_patterns = "deny"
implicit_clone = "deny"
macro_use_imports = "deny"
missing_safety_doc = "deny"
-multiple_crate_versions = "deny"
mut_mut = "deny"
needless_bitwise_bool = "deny"
needless_pass_by_ref_mut = "deny"
diff --git a/rust/meson.build b/rust/meson.build
index 91e52b8fb8e..9736ad300bb 100644
--- a/rust/meson.build
+++ b/rust/meson.build
@@ -6,21 +6,9 @@ subdir('hw')
cargo = find_program('cargo', required: false)
if cargo.found()
- run_target('clippy',
- command: [config_host['MESON'], 'devenv',
- '--workdir', '@CURRENT_SOURCE_DIR@',
- cargo, 'clippy', '--tests'],
- depends: bindings_rs)
-
run_target('rustfmt',
command: [config_host['MESON'], 'devenv',
'--workdir', '@CURRENT_SOURCE_DIR@',
cargo, 'fmt'],
depends: bindings_rs)
-
- run_target('rustdoc',
- command: [config_host['MESON'], 'devenv',
- '--workdir', '@CURRENT_SOURCE_DIR@',
- cargo, 'doc', '--no-deps', '--document-private-items'],
- depends: bindings_rs)
endif
diff --git a/scripts/rust/rustc_args.py b/scripts/rust/rustc_args.py
index 2633157df2a..63b0748e0d3 100644
--- a/scripts/rust/rustc_args.py
+++ b/scripts/rust/rustc_args.py
@@ -104,10 +104,7 @@ def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iterable[s
else:
raise Exception(f"invalid level {level} for {prefix}{lint}")
- # This may change if QEMU ever invokes clippy-driver or rustdoc by
- # hand. For now, check the syntax but do not add non-rustc lints to
- # the command line.
- if k == "rust" and not (strict_lints and lint in STRICT_LINTS):
+ if not (strict_lints and lint in STRICT_LINTS):
lint_list.append(LintFlag(flags=[flag, prefix + lint], priority=priority))
if strict_lints:
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
2025-04-05 10:06 [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Paolo Bonzini
` (3 preceding siblings ...)
2025-04-05 12:23 ` [PATCH 4/3] rust: use native Meson support for clippy and rustdoc Paolo Bonzini
@ 2025-04-07 7:37 ` Zhao Liu
2025-04-07 7:51 ` Paolo Bonzini
2025-04-08 20:34 ` Bernhard Beschow
5 siblings, 1 reply; 9+ messages in thread
From: Zhao Liu @ 2025-04-07 7:37 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, qemu-rust
On Sat, Apr 05, 2025 at 12:06:00PM +0200, Paolo Bonzini wrote:
> Date: Sat, 5 Apr 2025 12:06:00 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
> X-Mailer: git-send-email 2.49.0
>
> Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
> * support for "objects" in Rust executables
> * support for doctest targets
Is there a patch missing to actually bump the required meson version up
to v1.8.0?
Regards,
Zhao
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
2025-04-07 7:37 ` [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Zhao Liu
@ 2025-04-07 7:51 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2025-04-07 7:51 UTC (permalink / raw)
To: Zhao Liu; +Cc: qemu-devel, qemu-rust
On Mon, Apr 7, 2025 at 9:17 AM Zhao Liu <zhao1.liu@intel.com> wrote:
> On Sat, Apr 05, 2025 at 12:06:00PM +0200, Paolo Bonzini wrote:
> > Date: Sat, 5 Apr 2025 12:06:00 +0200
> > From: Paolo Bonzini <pbonzini@redhat.com>
> > Subject: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
> > X-Mailer: git-send-email 2.49.0
> >
> > Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
> > * support for "objects" in Rust executables
> > * support for doctest targets
>
> Is there a patch missing to actually bump the required meson version up
> to v1.8.0?
Yes, because there has not been a 1.8.0 release yet (or even an -rc).
Paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
2025-04-05 10:06 [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Paolo Bonzini
` (4 preceding siblings ...)
2025-04-07 7:37 ` [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Zhao Liu
@ 2025-04-08 20:34 ` Bernhard Beschow
2025-04-08 21:08 ` Paolo Bonzini
5 siblings, 1 reply; 9+ messages in thread
From: Bernhard Beschow @ 2025-04-08 20:34 UTC (permalink / raw)
To: qemu-devel, Paolo Bonzini; +Cc: qemu-rust
Am 5. April 2025 10:06:00 UTC schrieb Paolo Bonzini <pbonzini@redhat.com>:
>Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
>* support for "objects" in Rust executables
>* support for doctest targets
Using Meson 1.7.2 (shipped with my distro) I didn't succeed with either of these. If just applying the first patch with --enable-modules I get linker errors again. With all patches applied, "doctest" isn't recognized. Is this perhaps 1.8-only material?
Best regards,
Bernhard
>
>Use it to remove BQL-related hacks, fix --enable-modules --enable-rust
>and also simplify the Meson logic for building the qemu-api crate
>(which may help splitting the crate, too).
>
>Meson also supports clippy and rustdoc but there are some bugs in the
>prerelease. I'll try to get them fixed before 1.8.0.
>
>Paolo
>
>Paolo Bonzini (3):
> rust: use "objects" for Rust executables as well
> rust: add qemu-api doctests to "meson test"
> rust: cell: remove support for running doctests with "cargo test --doc"
>
> docs/devel/rust.rst | 2 --
> .gitlab-ci.d/buildtest.yml | 5 -----
> rust/qemu-api/meson.build | 35 +++++++++++++++--------------------
> rust/qemu-api/src/cell.rs | 22 +++++++++-------------
> 4 files changed, 24 insertions(+), 40 deletions(-)
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
2025-04-08 20:34 ` Bernhard Beschow
@ 2025-04-08 21:08 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2025-04-08 21:08 UTC (permalink / raw)
To: Bernhard Beschow; +Cc: qemu-devel, qemu-rust
[-- Attachment #1: Type: text/plain, Size: 1754 bytes --]
Il mar 8 apr 2025, 22:34 Bernhard Beschow <shentey@gmail.com> ha scritto:
>
>
> Am 5. April 2025 10:06:00 UTC schrieb Paolo Bonzini <pbonzini@redhat.com>:
> >Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
> >* support for "objects" in Rust executables
> >* support for doctest targets
>
> Using Meson 1.7.2 (shipped with my distro) I didn't succeed with either of
> these. If just applying the first patch with --enable-modules I get linker
> errors again. With all patches applied, "doctest" isn't recognized. Is this
> perhaps 1.8-only material?
>
Yes, it's 1.8 only. Once it's released I will repost it with an update to
pythondeps.toml, for now you can uninstall the distro Meson and install
from their git repository using pip (I think "pip install ." should work).
I did test modules a few months ago when you reported it, but I will check
again before reposting.
Paolo
> Best regards,
> Bernhard
>
> >
> >Use it to remove BQL-related hacks, fix --enable-modules --enable-rust
> >and also simplify the Meson logic for building the qemu-api crate
> >(which may help splitting the crate, too).
> >
> >Meson also supports clippy and rustdoc but there are some bugs in the
> >prerelease. I'll try to get them fixed before 1.8.0.
> >
> >Paolo
> >
> >Paolo Bonzini (3):
> > rust: use "objects" for Rust executables as well
> > rust: add qemu-api doctests to "meson test"
> > rust: cell: remove support for running doctests with "cargo test --doc"
> >
> > docs/devel/rust.rst | 2 --
> > .gitlab-ci.d/buildtest.yml | 5 -----
> > rust/qemu-api/meson.build | 35 +++++++++++++++--------------------
> > rust/qemu-api/src/cell.rs | 22 +++++++++-------------
> > 4 files changed, 24 insertions(+), 40 deletions(-)
> >
>
>
[-- Attachment #2: Type: text/html, Size: 2861 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-04-08 21:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-05 10:06 [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Paolo Bonzini
2025-04-05 10:06 ` [PATCH 1/3] rust: use "objects" for Rust executables as well Paolo Bonzini
2025-04-05 10:06 ` [PATCH 2/3] rust: add qemu-api doctests to "meson test" Paolo Bonzini
2025-04-05 10:06 ` [PATCH 3/3] rust: cell: remove support for running doctests with "cargo test --doc" Paolo Bonzini
2025-04-05 12:23 ` [PATCH 4/3] rust: use native Meson support for clippy and rustdoc Paolo Bonzini
2025-04-07 7:37 ` [PATCH preview 0/3] rust: update build system for Meson 1.8.0 Zhao Liu
2025-04-07 7:51 ` Paolo Bonzini
2025-04-08 20:34 ` Bernhard Beschow
2025-04-08 21:08 ` Paolo Bonzini
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).