mbox series

[RFC,00/11] rust: improved integration with cargo

Message ID 20241108180139.117112-1-pbonzini@redhat.com (mailing list archive)
Headers show
Series rust: improved integration with cargo | expand

Message

Paolo Bonzini Nov. 8, 2024, 6:01 p.m. UTC
While we're not sure where we'll be going in the future, for now
using cargo remains an important part of developing QEMU Rust code.
This is because cargo is the easiest way to run clippy, rustfmt,
rustdoc.  Cargo also allows working with doc tests, though there are
pretty much none yet, and provides tools such as "cargo expand".

This series aims at improving the integration with cargo and
cargo-based tooling.

First, while it is currently possible to run cargo on the rust/ directory,
but it has the issue that the bindings.rs must be placed by hand in
the build directory.  Therefore, this series starts by allowing
cargo to "just work" when run in a "meson devenv" environment:

    meson devenv -w ../rust cargo clippy --tests
    meson devenv -w ../rust cargo fmt

If you are going to use cargo repeatedly, invoking just 'meson devenv'
will put you in a shell where commands like 'cargo clippy' just work.
For simplicity, I am also adding two targets 'make clippy' and 'make
rustfmt'.

Secondly, one problem with mixing Cargo and meson is having to redo the
configuration of "lints" in both sides.  This series standardizes
on using Cargo.toml to configure the build, and bringing the flags
over to build.ninja with extensions to the existing rustc_args.py script.
I admit that these additions to the script are pretty large and therefore
I'm open to scrapping the idea.  I tried to organize the changes so that
the changes are split over multiple patches.

Finally, this series adds a CI job that runs rustfmt, clippy, and
rustdoc, including running doctests.

Please send comments!

Paolo

Paolo Bonzini (11):
  rust: qemu_api: do not disable lints outside bindgen-generated code
  rust: build: move rustc_args.py invocation to individual crates
  rust: build: restrict --cfg generation to only required symbols
  rust: build: generate warning flags from Cargo.toml
  rust: cargo: store desired warning levels in workspace Cargo.toml
  rust: build: move strict lints handling to rustc_args.py
  rust: fix a couple style issues from clippy
  rust: build: establish a baseline of lints across all crates
  rust: build: add "make clippy", "make rustfmt"
  rust: fix doc test syntax
  rust: ci: add job that runs Rust tools

 meson.build                                   |  56 +++---
 .gitlab-ci.d/buildtest-template.yml           |  14 ++
 .gitlab-ci.d/buildtest.yml                    |  14 ++
 rust/Cargo.toml                               |  80 ++++++++
 rust/hw/char/pl011/Cargo.toml                 |   3 +
 rust/hw/char/pl011/src/device.rs              |   6 +-
 rust/hw/char/pl011/src/lib.rs                 |  18 +-
 rust/hw/char/pl011/src/memory_ops.rs          |   4 +-
 rust/meson.build                              |  14 ++
 rust/qemu-api-macros/Cargo.toml               |   3 +
 rust/qemu-api/.gitignore                      |   2 +-
 rust/qemu-api/Cargo.toml                      |   5 +-
 rust/qemu-api/build.rs                        |  24 ++-
 rust/qemu-api/meson.build                     |   5 +
 rust/qemu-api/src/bindings.rs                 |  29 +++
 rust/qemu-api/src/lib.rs                      |  22 ---
 rust/qemu-api/src/zeroable.rs                 |   6 +-
 rust/qemu-api/tests/tests.rs                  |   2 +-
 scripts/rust/rustc_args.py                    | 178 ++++++++++++++++--
 .../dockerfiles/fedora-rust-nightly.docker    |   4 +
 tests/lcitool/refresh                         |   4 +
 21 files changed, 391 insertions(+), 102 deletions(-)
 create mode 100644 rust/qemu-api/src/bindings.rs