rust: update build system for Meson 1.8.0
Subsystems (2)
cover rust: update build system for Meson 1.8.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
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(-)
Signature · 1 line
2.49.0
PATCH 1/3 rust: use "objects" for Rust executables as well
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.
--- docs/devel/rust.rst | 2 -- rust/qemu-api/meson.build | 26 +++++--------------------- 2 files changed, 5 insertions(+), 23 deletions(-)
docs/devel/rust.rst +0 -2
@@ -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 '''''''''''''''
rust/qemu-api/meson.build +5 -21
@@ -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',
Signature · 1 line
2.49.0
PATCH 2/3 rust: add qemu-api doctests to "meson test"
In reply to Paolo BonziniDoctest 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.
--- .gitlab-ci.d/buildtest.yml | 5 ----- rust/qemu-api/meson.build | 11 +++++++++++ 1 file changed, 12 insertions(+), 6 deletions(-)
.gitlab-ci.d/buildtest.yml +1 -6
@@ -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
rust/qemu-api/meson.build +11 -0
@@ -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',
Signature · 1 line
2.49.0
PATCH 3/3 rust: cell: remove support for running doctests with "cargo test --doc"
In reply to Paolo BonziniThis is not needed anymore now that tests link with libqemuutil.
--- rust/qemu-api/src/cell.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
rust/qemu-api/src/cell.rs +9 -13
@@ -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); } }
Signature · 1 line
2.49.0
[PATCH 4/3] rust: use native Meson support for clippy and rustdoc
In reply to Paolo BonziniMeson 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.
--- 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%)
meson.build +1 -1
@@ -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')
clippy.toml renamed from rust/clippy.toml +0 -0
rust/Cargo.toml +0 -1
@@ -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"
rust/meson.build +0 -12
@@ -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
scripts/rust/rustc_args.py +1 -4
@@ -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:
Signature · 1 line
2.49.0
Quoted 8 lines · Paolo Bonzini
Date: Sat, 5 Apr 2025 12:06:00 +0200
From: Paolo Bonzini <[email protected]>
Subject: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
X-Mailer: git-send-email 2.49.0Meson 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
Quoted 6 lines · Zhao Liu
Quoted 5 lines · Paolo Bonzini
Date: Sat, 5 Apr 2025 12:06:00 +0200
From: Paolo Bonzini <[email protected]>
Subject: [PATCH preview 0/3] rust: update build system for Meson 1.8.0
X-Mailer: git-send-email 2.49.0
Quoted 6 lines
Quoted 3 lines
Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
* support for "objects" in Rust executables
* support for doctest targetsIs 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
Am 5. April 2025 10:06:00 UTC schrieb Paolo Bonzini <[email protected]>:
Quoted 3 lines
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
Quoted 21 lines
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(-)
Il mar 8 apr 2025, 22:34 Bernhard Beschow <[email protected]> ha scritto:
Quoted 12 lines
Am 5. April 2025 10:06:00 UTC schrieb Paolo Bonzini <[email protected]>:
Quoted 3 lines
Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
* support for "objects" in Rust executables
* support for doctest targetsUsing 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
Quoted 26 lines
Best regards,
BernhardQuoted 21 lines
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(-)