RustInQemu: Difference between revisions

From QEMU
No edit summary
Line 5: Line 5:
* [[ChangeLog/10.0#Rust|Current state]]
* [[ChangeLog/10.0#Rust|Current state]]
* [https://www.qemu.org/docs/master/devel/rust.html Documentation]
* [https://www.qemu.org/docs/master/devel/rust.html Documentation]
* Roadmap: [https://lore.kernel.org/all/cc40943e-dec1-4890-a1d9-579350ce296f@pbonzini.local/ November 2024] | [https://lore.kernel.org/qemu-devel/17ad81c3-98fc-44c2-8f65-f5e2cc07030b@gnu.org/ January 2025]
* Roadmap: [https://lore.kernel.org/qemu-devel/d3d1944e-2482-4aa7-b621-596246a08107@gnu.org/ April 2025] | [https://lore.kernel.org/qemu-devel/17ad81c3-98fc-44c2-8f65-f5e2cc07030b@gnu.org/ January 2025] |  [https://lore.kernel.org/all/cc40943e-dec1-4890-a1d9-579350ce296f@pbonzini.local/ November 2024]


<!--
* <code>Subject: [RFC 0/6] scripts: Rewrite simpletrace printer in Rust</code><br /><code>Date: Mon, 27 May 2024 16:14:15 +0800</code><br />[https://lore.kernel.org/qemu-devel/20240527081421.2258624-1-zhao1.liu@intel.com/ RFC v1]
-->


== Past efforts ==
== Past efforts ==


* <code>[RFC v3 00/32] Rust binding for QAPI and qemu-ga QMP handler examples</code><br />[https://patchew.org/QEMU/20210907121943.3498701-1-marcandre.lureau@redhat.com/ on patchew] [https://lore.kernel.org/qemu-devel/20210907121943.3498701-1-marcandre.lureau@redhat.com/ on lore]
* <code>[RFC v3 00/32] Rust binding for QAPI and qemu-ga QMP handler examples</code><br />[https://patchew.org/QEMU/20210907121943.3498701-1-marcandre.lureau@redhat.com/ on patchew] [https://lore.kernel.org/qemu-devel/20210907121943.3498701-1-marcandre.lureau@redhat.com/ on lore]
* <code>Subject: [RFC 0/6] scripts: Rewrite simpletrace printer in Rust</code><br /><code>Date: Mon, 27 May 2024 16:14:15 +0800</code><br />[https://lore.kernel.org/qemu-devel/20240527081421.2258624-1-zhao1.liu@intel.com/ RFC v1]


== Work in progress ==
== Work in progress ==
=== Paolo ===
=== Paolo ===
* Posted: Opaque<> (to split crates and also first step for annotated pinning)
* Waiting for Meson 1.8.1: "objects:", rustdoc,
* Planned: chardev
* Later: pinned_init... maybe use MaybeUninit as a first step?
* Later: pinned_init... maybe use MaybeUninit as a first step?
* Upstream Meson: "objects:", rustdoc, <tt>-C prefer-dynamic</tt>


=== Manos ===
=== Manos ===
* Documentation
=== Zhao ===
=== Zhao ===
* HPET live migration.


=== Kevin ===
=== Kevin ===
Line 33: Line 25:
** https://lore.kernel.org/qemu-devel/20250211214328.640374-1-kwolf@redhat.com/
** https://lore.kernel.org/qemu-devel/20250211214328.640374-1-kwolf@redhat.com/


== TODO ==
== Bugs ==
=== Bugs ===
* Integration tests are linked with libqemuutil as link_whole, which does not work when modules are enabled
** [https://github.com/mesonbuild/meson/pull/14031 meson seems to be buggy and does not allow using link_with instead?]
** probably best to require meson 1.8.0 anyway as it has nicer integration with clippy, and possibly rustdoc
* Add BQL abstraction for tests - avoid running them with "--test-threads 1"
* Add BQL abstraction for tests - avoid running them with "--test-threads 1"
* [https://github.com/mesonbuild/meson/issues/8828 Distros would prefer to link libstd dynamically]; Rust-enabled QEMU binaries are huge
* [https://github.com/mesonbuild/meson/issues/8828 Distros would prefer to link libstd dynamically]; Rust-enabled QEMU binaries are huge
== Possible project targets ==


=== Nice things to have ===
=== Nice things to have ===
* [https://github.com/mesonbuild/meson/pull/13933 run doctests with meson test]
* Remove need for manual "meson subprojects update --reset" when updating packagefiles/
* Remove need for manual "meson subprojects update --reset" when updating packagefiles/
* Improve tool integration
* Improve tool integration
** Run code checks a la "meson test --suite codecheck"? (clippy and rustfmt)
** Run code checks a la "meson test --suite codecheck"? (clippy and rustfmt)
* rustfmt currently requires nightly, decide what to do about it
* Place rustdoc output for master somewhere?
* Place rustdoc output for master somewhere?
* split qemu_api into multiple crates
* split qemu_api into multiple crates
* more QOM procedural macros
** generate qdev properties
** generate parts of TypeInfo?
** monomorphization of <tt>T: IsA&lt;Class&gt;</tt> to <tt>&T</tt> (like the momo crate)
* distros need dynamically linked libstd
* distros need dynamically linked libstd
** rewrite all main()s in Rust and use [https://github.com/mesonbuild/meson/issues/14224 -C prefer-dynamic]?
** rewrite all main()s in Rust and use [https://github.com/mesonbuild/meson/issues/14224 -C prefer-dynamic]?
Line 58: Line 42:


=== New code to write===
=== New code to write===
* more QOM procedural macros
** generate qdev properties
** generate parts of TypeInfo?
** monomorphization of <tt>T: IsA&lt;Class&gt;</tt> to <tt>&T</tt> (like the momo crate)
* feature parity for pl011
* feature parity for pl011
* safe object creation with [https://docs.rs/pinned-init/ pinned_init, originating from Linux])
* safe object creation with [https://docs.rs/pinned-init/ pinned_init, originating from Linux])
* complete vmstate bindings
* Generic Rust<->C interop, Error (https://github.com/bonzini/rust-qemu)
* Generic Rust<->C interop, Error (https://github.com/bonzini/rust-qemu)
* DMA (investigate vm-memory?)
* DMA (investigate vm-memory?)
* Trace/log
* Trace/log (Summer of Code)


== Ideas for lints without breaking CI ==
== Ideas for improved clippy coverage in CI? ==
See https://github.com/bonzini/rust-qemu/commit/95b25f7c5f4e2694a85a5503050cc98da7562c7c
* run clippy as part of "make check"
* run clippy as part of "make check", possibly only if Rust is newer than some version (1.74.0 so that clippy can be configured in Cargo.toml?)
* deny many individual lints, do not deny groups (complexity, perf, style, suspicious) on regular builds. allow unknown_lints.
* add to CI a fallible job that runs on nightly clippy with <tt>-Dclippy::complexity -Dclippy::perf -Dclippy::suspicious -Dclippy::style -Dunknown_lints</tt>. the job should generally pass, and if a new lint triggers it probably should be added to Cargo.toml as either "allow" (rare) or "deny" (possibly after adding #[allow()] to the source).
* add to CI a fallible job that runs on nightly clippy with <tt>-Dclippy::complexity -Dclippy::perf -Dclippy::suspicious -Dclippy::style -Dunknown_lints</tt>. the job should generally pass, and if a new lint triggers it probably should be added to Cargo.toml as either "allow" (rare) or "deny" (possibly after adding #[allow()] to the source).
== Possible project targets ==


=== Miscellanea  ===
=== Miscellanea  ===
Line 80: Line 63:


* visitors/QOM properties, could be interesting for <code>hw/sensor/tmp105.c</code>...
* visitors/QOM properties, could be interesting for <code>hw/sensor/tmp105.c</code>...
* complete vmstate bindings (needs const_refs_static in Rust 1.83.0, Zhao+Paolo have a prototype)
=== Devices  ===
=== Devices  ===



Revision as of 12:48, 2 May 2025

For the old RustInQemu page, see RustInQemu/2022

Active effort


Past efforts

  • [RFC v3 00/32] Rust binding for QAPI and qemu-ga QMP handler examples
    on patchew on lore
  • Subject: [RFC 0/6] scripts: Rewrite simpletrace printer in Rust
    Date: Mon, 27 May 2024 16:14:15 +0800
    RFC v1

Work in progress

Paolo

  • Waiting for Meson 1.8.1: "objects:", rustdoc,
  • Later: pinned_init... maybe use MaybeUninit as a first step?

Manos

Zhao

Kevin

Bugs

Possible project targets

Nice things to have

  • Remove need for manual "meson subprojects update --reset" when updating packagefiles/
  • Improve tool integration
    • Run code checks a la "meson test --suite codecheck"? (clippy and rustfmt)
  • Place rustdoc output for master somewhere?
  • split qemu_api into multiple crates
  • distros need dynamically linked libstd
    • rewrite all main()s in Rust and use -C prefer-dynamic?
    • or should Meson be able to link C programs with rlibs?

New code to write

  • more QOM procedural macros
    • generate qdev properties
    • generate parts of TypeInfo?
    • monomorphization of T: IsA<Class> to &T (like the momo crate)
  • feature parity for pl011
  • safe object creation with pinned_init, originating from Linux)
  • Generic Rust<->C interop, Error (https://github.com/bonzini/rust-qemu)
  • DMA (investigate vm-memory?)
  • Trace/log (Summer of Code)

Ideas for improved clippy coverage in CI?

  • run clippy as part of "make check"
  • add to CI a fallible job that runs on nightly clippy with -Dclippy::complexity -Dclippy::perf -Dclippy::suspicious -Dclippy::style -Dunknown_lints. the job should generally pass, and if a new lint triggers it probably should be added to Cargo.toml as either "allow" (rare) or "deny" (possibly after adding #[allow()] to the source).

Miscellanea

  • qemu-bridge-helper.c Re-write SUID C executable with useful features.

Bindings

  • visitors/QOM properties, could be interesting for hw/sensor/tmp105.c...
  • complete vmstate bindings (needs const_refs_static in Rust 1.83.0, Zhao+Paolo have a prototype)

Devices

  • hw/block/pflash_cfi01.c, hw/block/pflash_cfi02.c (claimed, WIP)
    • needs block bindings
  • hw/timer/i8254.c (claimed, WIP)
  • hw/mem/nvdimm.c (suggested by Manos)