rust: update build system for Meson 1.8.1
Subsystems (2)
cover rust: update build system for Meson 1.8.1
Meson 1.7.0 and 1.8.0 include improved support for Rust, namely:
* support for "objects" in Rust executables
* support for doctest targets
* invoking clippy and rustdoc
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).
Note that this does *not* yet require 1.8.1 for all of QEMU; the requirement is only there if Rust is enabled.
Paolo
Supersedes: <[email protected]>
Paolo Bonzini (6):
meson: update to version 1.8.1
rust: use "objects" for Rust executables as well build, dockerfiles: add support for detecting rustdoc
rust: add qemu-api doctests to "meson test"
rust: cell: remove support for running doctests with "cargo test
--doc"
rust: use native Meson support for clippy and rustdoc
docs/devel/rust.rst | 12 ++++--- configure | 16 +++++++++ meson.build | 4 ++- .gitlab-ci.d/buildtest-template.yml | 3 +- .gitlab-ci.d/buildtest.yml | 11 ++----- rust/clippy.toml => clippy.toml | 0 python/scripts/vendor.py | 4 +-- python/wheels/meson-1.5.0-py3-none-any.whl | Bin 959846 -> 0 bytes python/wheels/meson-1.8.1-py3-none-any.whl | Bin 0 -> 1013001 bytes pythondeps.toml | 2 +- rust/Cargo.toml | 1 - rust/meson.build | 14 ++------ rust/qemu-api/meson.build | 31 +++++++----------- rust/qemu-api/src/cell.rs | 22 +++++-------- scripts/rust/rustc_args.py | 5 +-- .../dockerfiles/fedora-rust-nightly.docker | 2 ++ tests/docker/dockerfiles/ubuntu2204.docker | 1 + tests/lcitool/mappings.yml | 6 +++- tests/lcitool/refresh | 3 ++ 19 files changed, 69 insertions(+), 68 deletions(-) rename rust/clippy.toml => clippy.toml (100%) delete mode 100644 python/wheels/meson-1.5.0-py3-none-any.whl create mode 100644 python/wheels/meson-1.8.1-py3-none-any.whl
Signature · 1 line
2.49.0
PATCH 1/6 meson: update to version 1.8.1
This adds several improvements to Rust support, including native clippy and rustdoc targets, the "objects" keyword, and running doctests.
Require it only when Rust support is requested, to avoid putting a strict requirement on all build platforms for the sake of an experimental feature.
--- configure | 8 ++++++++ python/scripts/vendor.py | 4 ++-- python/wheels/meson-1.5.0-py3-none-any.whl | Bin 959846 -> 0 bytes python/wheels/meson-1.8.1-py3-none-any.whl | Bin 0 -> 1013001 bytes pythondeps.toml | 2 +- tests/lcitool/mappings.yml | 6 +++++- 6 files changed, 16 insertions(+), 4 deletions(-) delete mode 100644 python/wheels/meson-1.5.0-py3-none-any.whl create mode 100644 python/wheels/meson-1.8.1-py3-none-any.whl
configure +8 -0
@@ -1178,6 +1178,14 @@ fi ########################################## # detect rust triple +meson_version=$($meson --version) +if test "$rust" != disabled && ! version_ge "$meson_version" 1.8.1; then + if test "$rust" = enabled; then + error_exit "Rust support needs Meson 1.8.1 or newer" + fi + echo "Rust needs Meson 1.8.1, disabling" 2>&1 + rust=disabled +fi if test "$rust" != disabled && has "$rustc" && $rustc -vV > "${TMPDIR1}/${TMPB}.out"; then rust_host_triple=$(sed -n 's/^host: //p' "${TMPDIR1}/${TMPB}.out") else
python/scripts/vendor.py +2 -2
@@ -41,8 +41,8 @@ def main() -> int: parser.parse_args() packages = { - "meson==1.5.0": - "52b34f4903b882df52ad0d533146d4b992c018ea77399f825579737672ae7b20", + "meson==1.8.1": + "374bbf71247e629475fc10b0bd2ef66fc418c2d8f4890572f74de0f97d0d42da", } vendor_dir = Path(__file__, "..", "..", "wheels").resolve()
pythondeps.toml +1 -1
@@ -19,7 +19,7 @@ [meson] # The install key should match the version in python/wheels/ -meson = { accepted = ">=1.5.0", installed = "1.5.0", canary = "meson" } +meson = { accepted = ">=1.5.0", installed = "1.8.1", canary = "meson" } pycotap = { accepted = ">=1.1.0", installed = "1.3.1" } [docs]
tests/lcitool/mappings.yml +5 -1
@@ -8,6 +8,10 @@ mappings: meson: OpenSUSELeap15: + # Use Meson from PyPI wherever Rust is enabled + Debian: + Fedora: + Ubuntu: python3: OpenSUSELeap15: python311-base
@@ -72,7 +76,7 @@ mappings: pypi_mappings: # Request more recent version meson: - default: meson==1.5.0 + default: meson==1.8.1 # Drop packages that need devel headers python3-numpy:
Signature · 1 line
2.49.0
PATCH 2/6 rust: use "objects" for Rust executables as well
In reply to Paolo Bonzinilibqemuutil 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/meson.build | 2 ++ rust/qemu-api/meson.build | 24 +++--------------------- 3 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/meson.build +2 -0
@@ -14,6 +14,8 @@ quote_rs_native = dependency('quote-1-rs', native: true) syn_rs_native = dependency('syn-2-rs', native: true) proc_macro2_rs_native = dependency('proc-macro2-1-rs', native: true) +qemuutil_rs = qemuutil.partial_dependency(link_args: true, links: true) + subdir('qemu-api-macros') subdir('qemu-api')
rust/qemu-api/meson.build +3 -21
@@ -41,26 +41,8 @@ _qemu_api_rs = static_library( 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(
@@ -69,7 +51,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 3/6 build, dockerfiles: add support for detecting rustdoc
In reply to Paolo Bonzinirustdoc is effectively a custom version of rustc, and it is necessary to specify it in order to run doctests from Meson. Add the relevant configure option and environment variables.
--- configure | 8 ++++++++ meson.build | 2 ++ tests/docker/dockerfiles/fedora-rust-nightly.docker | 2 ++ tests/docker/dockerfiles/ubuntu2204.docker | 1 + tests/lcitool/refresh | 3 +++ 5 files changed, 16 insertions(+)
configure +8 -0
@@ -209,6 +209,8 @@ for opt do ;; --rustc=*) RUSTC="$optarg" ;; + --rustdoc=*) RUSTDOC="$optarg" + ;; --cpu=*) cpu="$optarg" ;; --extra-cflags=*)
@@ -323,6 +325,7 @@ pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}" sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}" rustc="${RUSTC-rustc}" +rustdoc="${RUSTDOC-rustdoc}" check_define() { cat > $TMPC <<EOF
@@ -660,6 +663,8 @@ for opt do ;; --rustc=*) ;; + --rustdoc=*) + ;; --make=*) ;; --install=*)
@@ -890,6 +895,7 @@ Advanced options (experts only): --cxx=CXX use C++ compiler CXX [$cxx] --objcc=OBJCC use Objective-C compiler OBJCC [$objcc] --rustc=RUSTC use Rust compiler RUSTC [$rustc] + --rustdoc=RUSTDOC use rustdoc binary RUSTDOC [$rustdoc] --extra-cflags=CFLAGS append extra C compiler flags CFLAGS --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
@@ -1901,8 +1907,10 @@ if test "$skip_meson" = no; then if test "$rust" != disabled; then if test "$rust_host_triple" != "$rust_target_triple"; then echo "rust = [$(meson_quote $rustc --target "$rust_target_triple")]" >> $cross + echo "rustdoc = [$(meson_quote $rustdoc --target "$rust_target_triple")]" >> $cross else echo "rust = [$(meson_quote $rustc)]" >> $cross + echo "rustdoc = [$(meson_quote $rustdoc)]" >> $cross fi fi echo "ar = [$(meson_quote $ar)]" >> $cross
meson.build +2 -0
@@ -106,6 +106,7 @@ if have_rust endif if have_rust + rustdoc = find_program('rustdoc', required: get_option('rust')) bindgen = find_program('bindgen', required: get_option('rust')) if not bindgen.found() or bindgen.version().version_compare('<0.60.0') if get_option('rust').enabled()
@@ -4729,6 +4730,7 @@ if have_rust summary_info += {'Rust target': config_host['RUST_TARGET_TRIPLE']} summary_info += {'rustc': ' '.join(rustc.cmd_array())} summary_info += {'rustc version': rustc.version()} + summary_info += {'rustdoc': rustdoc} summary_info += {'bindgen': bindgen.full_path()} summary_info += {'bindgen version': bindgen.version()} endif
tests/docker/dockerfiles/fedora-rust-nightly.docker +2 -0
@@ -156,6 +156,7 @@ ENV PYTHON "/usr/bin/python3" RUN dnf install -y wget ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo ENV RUSTC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc +ENV RUSTDOC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustdoc ENV CARGO=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo RUN set -eux && \ rustArch='x86_64-unknown-linux-gnu' && \
@@ -170,6 +171,7 @@ RUN set -eux && \ /usr/local/cargo/bin/rustup run nightly cargo --version && \ /usr/local/cargo/bin/rustup run nightly rustc --version && \ test "$CARGO" = "$(/usr/local/cargo/bin/rustup +nightly which cargo)" && \ + test "$RUSTDOC" = "$(/usr/local/cargo/bin/rustup +nightly which rustdoc)" && \ test "$RUSTC" = "$(/usr/local/cargo/bin/rustup +nightly which rustc)" ENV PATH=$CARGO_HOME/bin:$PATH RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli
tests/docker/dockerfiles/ubuntu2204.docker +1 -0
@@ -151,6 +151,7 @@ ENV MAKE "/usr/bin/make" ENV NINJA "/usr/bin/ninja" ENV PYTHON "/usr/bin/python3" ENV RUSTC=/usr/bin/rustc-1.77 +ENV RUSTDOC=/usr/bin/rustdoc-1.77 ENV CARGO_HOME=/usr/local/cargo ENV PATH=$CARGO_HOME/bin:$PATH RUN DEBIAN_FRONTEND=noninteractive eatmydata \
tests/lcitool/refresh +3 -0
@@ -121,6 +121,7 @@ fedora_rustup_nightly_extras = [ "RUN dnf install -y wget\n", "ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo\n", "ENV RUSTC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc\n", + "ENV RUSTDOC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustdoc\n", "ENV CARGO=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo\n", "RUN set -eux && \\\n", " rustArch='x86_64-unknown-linux-gnu' && \\\n",
@@ -135,6 +136,7 @@ fedora_rustup_nightly_extras = [ " /usr/local/cargo/bin/rustup run nightly cargo --version && \\\n", " /usr/local/cargo/bin/rustup run nightly rustc --version && \\\n", ' test "$CARGO" = "$(/usr/local/cargo/bin/rustup +nightly which cargo)" && \\\n', + ' test "$RUSTDOC" = "$(/usr/local/cargo/bin/rustup +nightly which rustdoc)" && \\\n', ' test "$RUSTC" = "$(/usr/local/cargo/bin/rustup +nightly which rustc)"\n', 'ENV PATH=$CARGO_HOME/bin:$PATH\n', 'RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli\n',
@@ -143,6 +145,7 @@ fedora_rustup_nightly_extras = [ ubuntu2204_rust_extras = [ "ENV RUSTC=/usr/bin/rustc-1.77\n", + "ENV RUSTDOC=/usr/bin/rustdoc-1.77\n", "ENV CARGO_HOME=/usr/local/cargo\n", 'ENV PATH=$CARGO_HOME/bin:$PATH\n', "RUN DEBIAN_FRONTEND=noninteractive eatmydata \\\n",
Signature · 1 line
2.49.0
PATCH 4/6 rust: add qemu-api doctests to "meson test"
In reply to Paolo BonziniDoctests 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.
Because they run the linker and need all the .o files, run them in the build jobs rather than the test jobs.
--- docs/devel/rust.rst | 2 ++ .gitlab-ci.d/buildtest-template.yml | 3 ++- .gitlab-ci.d/buildtest.yml | 11 +++-------- rust/qemu-api/meson.build | 9 +++++++++ 4 files changed, 16 insertions(+), 9 deletions(-)
docs/devel/rust.rst +2 -0
@@ -66,6 +66,8 @@ be run via ``meson test`` or ``make``:: make check-rust +Note that doctests require all ``.o`` files from the build to be available. + Supported tools '''''''''''''''
.gitlab-ci.d/buildtest-template.yml +2 -1
@@ -76,7 +76,8 @@ fi - section_end buildenv - section_start test "Running tests" - - $MAKE NINJA=":" $MAKE_CHECK_ARGS + # doctests need all the compilation artifacts + - $MAKE NINJA=":" MTESTARGS="--no-suite doc" $MAKE_CHECK_ARGS - section_end test .native_test_job_template:
.gitlab-ci.d/buildtest.yml +3 -8
@@ -41,7 +41,7 @@ build-system-ubuntu: IMAGE: ubuntu2204 CONFIGURE_ARGS: --enable-docs --enable-rust TARGETS: alpha-softmmu microblazeel-softmmu mips64el-softmmu - MAKE_CHECK_ARGS: check-build + MAKE_CHECK_ARGS: check-build check-doc check-system-ubuntu: extends: .native_test_job_template
@@ -115,7 +115,7 @@ build-system-fedora: CONFIGURE_ARGS: --disable-gcrypt --enable-nettle --enable-docs --enable-crypto-afalg --enable-rust TARGETS: microblaze-softmmu mips-softmmu xtensa-softmmu m68k-softmmu riscv32-softmmu ppc-softmmu sparc64-softmmu - MAKE_CHECK_ARGS: check-build + MAKE_CHECK_ARGS: check-build check-doc build-system-fedora-rust-nightly: extends:
@@ -127,12 +127,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 +9 -0
@@ -44,6 +44,15 @@ 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 dependencies. +# Note that running them requires the object files for C code, so place them +# in a separate suite that is run by the "build" CI jobs rather than "check". +rust.doctest('rust-qemu-api-doctests', + _qemu_api_rs, + protocol: 'rust', + dependencies: qemu_api, + suite: ['doc', 'rust']) + test('rust-qemu-api-integration', executable( 'rust-qemu-api-integration',
Signature · 1 line
2.49.0
PATCH 5/6 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 6/6 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; this requires disabling the multiple_crate_versions lint (the only one that was enabled from the "cargo" group)---which was not particularly useful anyway because all dependencies are converted by hand into Meson subprojects.
rustfmt is still not supported.
--- docs/devel/rust.rst | 10 +++++++--- meson.build | 2 +- rust/clippy.toml => clippy.toml | 0 rust/Cargo.toml | 1 - rust/meson.build | 12 ------------ scripts/rust/rustc_args.py | 5 +---- 6 files changed, 9 insertions(+), 21 deletions(-) rename rust/clippy.toml => clippy.toml (100%)
docs/devel/rust.rst +7 -3
@@ -37,12 +37,16 @@ output directory (typically ``rust/target/``). A vanilla invocation of Cargo will complain that it cannot find the generated sources, which can be fixed in different ways: -* by using special shorthand targets in the QEMU build directory:: +* by using Makefile targets, provided by Meson, that run ``clippy`` or + ``rustdoc``: make clippy - make rustfmt make rustdoc +A target for ``rustfmt`` is also declared in ``rust/meson.build``: + + make rustfmt + * by invoking ``cargo`` through the Meson `development environment`__ feature::
@@ -50,7 +54,7 @@ which can be fixed in different ways: pyvenv/bin/meson devenv -w ../rust cargo fmt If you are going to use ``cargo`` repeatedly, ``pyvenv/bin/meson devenv`` - will enter a shell where commands like ``cargo clippy`` just work. + will enter a shell where commands like ``cargo fmt`` just work. __ https://mesonbuild.com/Commands.html#devenv
meson.build +1 -1
@@ -4376,7 +4376,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
@@ -63,7 +63,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
@@ -24,21 +24,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