[PATCH v2 00/14] rust: bindings for Error

Paolo Bonzini posted 14 patches 5 months, 2 weeks ago
Failed in applying to current master (apply log)
docs/devel/rust.rst                           |   2 +-
include/qapi/error-internal.h                 |  27 ++
rust/wrapper.h                                |   1 +
hw/timer/hpet.c                               |  21 +-
util/error.c                                  |  20 +-
rust/Cargo.lock                               |  17 +
rust/Cargo.toml                               |   1 +
rust/hw/char/pl011/src/device.rs              |   5 +-
rust/hw/timer/hpet/src/device.rs              |  62 ++-
rust/hw/timer/hpet/src/fw_cfg.rs              |   7 +-
rust/meson.build                              |   4 +
rust/qemu-api/Cargo.toml                      |   2 +
rust/qemu-api/meson.build                     |   3 +-
rust/qemu-api/src/error.rs                    | 403 ++++++++++++++++++
rust/qemu-api/src/lib.rs                      |   3 +
rust/qemu-api/src/qdev.rs                     |  10 +-
scripts/archive-source.sh                     |   5 +-
scripts/make-release                          |   5 +-
subprojects/.gitignore                        |   2 +
subprojects/anyhow-1-rs.wrap                  |   7 +
subprojects/foreign-0.3-rs.wrap               |   7 +
.../packagefiles/anyhow-1.0-rs/meson.build    |  33 ++
.../packagefiles/foreign-0.3-rs/meson.build   |  26 ++
23 files changed, 602 insertions(+), 71 deletions(-)
create mode 100644 include/qapi/error-internal.h
create mode 100644 rust/qemu-api/src/error.rs
create mode 100644 subprojects/anyhow-1-rs.wrap
create mode 100644 subprojects/foreign-0.3-rs.wrap
create mode 100644 subprojects/packagefiles/anyhow-1.0-rs/meson.build
create mode 100644 subprojects/packagefiles/foreign-0.3-rs/meson.build
[PATCH v2 00/14] rust: bindings for Error
Posted by Paolo Bonzini 5 months, 2 weeks ago
As explained for v1, the impetus for this series is to remove BqlCell<>
from HPETState::num_timers.  However, it's also an important step for QAPI:
error propagation is pretty central for example to QMP, and the series
is also a first example of two-way conversion between C and native-Rust
structs (i.e. not using bindgen-generated structs or their opaque wrappers).

As an aside, support for NUL-terminated file is now scheduled for
inclusion in Rust as "panic::Location::file_with_nul()", but it will be
quite a while before QEMU can use it.  For more information, see
https://github.com/rust-lang/rust/issues/141727.

Paolo

v1->v2:
- patch "rust: make declaration of dependent crates more consistent" merged
- change dependency name for anyhow to anyhow-1-rs
- update scripts/archive-source.sh and scripts/make-release [Zhao]
- update foreign to 0.3.1 instead of 0.2.0
- use %.*s to print non-NUL-terminated err->src [Markus]
- make err->src_len an int instead of a size_t [Markus]
- add doc comment for error module
- remove #[derive(Default)] for Error [Markus]
- rewrite ok_or_propagate in functional style [Markus]
- clarify "validity" of Error** [Markus]
- clarify that err_or_unit/err_or_else free the Error* [Markus]

new patches:
- hpet: adjust VMState for consistency with Rust version [Zhao]
- rust: qemu-api: add tests for Error bindings
- docs: update Rust module status


Paolo Bonzini (13):
  subprojects: add the anyhow crate
  subprojects: add the foreign crate
  util/error: expose Error definition to Rust code
  util/error: allow non-NUL-terminated err->src
  util/error: make func optional
  rust: qemu-api: add bindings to Error
  rust: qemu-api: add tests for Error bindings
  rust: qdev: support returning errors from realize
  rust/hpet: change type of num_timers to usize
  hpet: adjust VMState for consistency with Rust version
  hpet: return errors from realize if properties are incorrect
  rust/hpet: return errors from realize if properties are incorrect
  docs: update Rust module status

Zhao Liu (1):
  rust/hpet: Drop BqlCell wrapper for num_timers

 docs/devel/rust.rst                           |   2 +-
 include/qapi/error-internal.h                 |  27 ++
 rust/wrapper.h                                |   1 +
 hw/timer/hpet.c                               |  21 +-
 util/error.c                                  |  20 +-
 rust/Cargo.lock                               |  17 +
 rust/Cargo.toml                               |   1 +
 rust/hw/char/pl011/src/device.rs              |   5 +-
 rust/hw/timer/hpet/src/device.rs              |  62 ++-
 rust/hw/timer/hpet/src/fw_cfg.rs              |   7 +-
 rust/meson.build                              |   4 +
 rust/qemu-api/Cargo.toml                      |   2 +
 rust/qemu-api/meson.build                     |   3 +-
 rust/qemu-api/src/error.rs                    | 403 ++++++++++++++++++
 rust/qemu-api/src/lib.rs                      |   3 +
 rust/qemu-api/src/qdev.rs                     |  10 +-
 scripts/archive-source.sh                     |   5 +-
 scripts/make-release                          |   5 +-
 subprojects/.gitignore                        |   2 +
 subprojects/anyhow-1-rs.wrap                  |   7 +
 subprojects/foreign-0.3-rs.wrap               |   7 +
 .../packagefiles/anyhow-1.0-rs/meson.build    |  33 ++
 .../packagefiles/foreign-0.3-rs/meson.build   |  26 ++
 23 files changed, 602 insertions(+), 71 deletions(-)
 create mode 100644 include/qapi/error-internal.h
 create mode 100644 rust/qemu-api/src/error.rs
 create mode 100644 subprojects/anyhow-1-rs.wrap
 create mode 100644 subprojects/foreign-0.3-rs.wrap
 create mode 100644 subprojects/packagefiles/anyhow-1.0-rs/meson.build
 create mode 100644 subprojects/packagefiles/foreign-0.3-rs/meson.build

-- 
2.49.0
Re: [PATCH v2 00/14] rust: bindings for Error
Posted by Markus Armbruster 5 months, 2 weeks ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> As explained for v1, the impetus for this series is to remove BqlCell<>
> from HPETState::num_timers.  However, it's also an important step for QAPI:
> error propagation is pretty central for example to QMP, and the series
> is also a first example of two-way conversion between C and native-Rust
> structs (i.e. not using bindgen-generated structs or their opaque wrappers).
>
> As an aside, support for NUL-terminated file is now scheduled for
> inclusion in Rust as "panic::Location::file_with_nul()", but it will be
> quite a while before QEMU can use it.  For more information, see
> https://github.com/rust-lang/rust/issues/141727.

Doen't apply for me on current master (3e82ddaa8db).  What's your base?
Re: [PATCH v2 00/14] rust: bindings for Error
Posted by Paolo Bonzini 5 months, 2 weeks ago
On 6/2/25 09:49, Markus Armbruster wrote:
> Paolo Bonzini <pbonzini@redhat.com> writes:
> 
>> As explained for v1, the impetus for this series is to remove BqlCell<>
>> from HPETState::num_timers.  However, it's also an important step for QAPI:
>> error propagation is pretty central for example to QMP, and the series
>> is also a first example of two-way conversion between C and native-Rust
>> structs (i.e. not using bindgen-generated structs or their opaque wrappers).
>>
>> As an aside, support for NUL-terminated file is now scheduled for
>> inclusion in Rust as "panic::Location::file_with_nul()", but it will be
>> quite a while before QEMU can use it.  For more information, see
>> https://github.com/rust-lang/rust/issues/141727.
> 
> Doen't apply for me on current master (3e82ddaa8db).  What's your base?

I have a few more patches queued before this series.  For something that 
applies directly on top of master, you can check branch rust-next at 
https://gitlab.com/bonzini/qemu.

You'll also need Meson 1.8.1, which you can install via pip, because 
Daniel preferred not to have such a new version required for everyone.

Paolo
Re: [PATCH v2 00/14] rust: bindings for Error
Posted by Zhao Liu 5 months, 2 weeks ago
On Fri, May 30, 2025 at 10:02:52AM +0200, Paolo Bonzini wrote:
> Date: Fri, 30 May 2025 10:02:52 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH v2 00/14] rust: bindings for Error
> X-Mailer: git-send-email 2.49.0
> 
> As explained for v1, the impetus for this series is to remove BqlCell<>
> from HPETState::num_timers.  However, it's also an important step for QAPI:
> error propagation is pretty central for example to QMP, and the series
> is also a first example of two-way conversion between C and native-Rust
> structs (i.e. not using bindgen-generated structs or their opaque wrappers).
> 
> As an aside, support for NUL-terminated file is now scheduled for
> inclusion in Rust as "panic::Location::file_with_nul()", but it will be
> quite a while before QEMU can use it.  For more information, see
> https://github.com/rust-lang/rust/issues/141727.

Apart from Markus's comments, the rest of the code (the specific
implementation of error binding) looks great to me. The interaction with
Foreign crate is quite insightful. I'll go through other patches on the
rust-next branch.

Thanks,
Zhao