aboutsummaryrefslogtreecommitdiff
path: root/rust
AgeCommit message (Collapse)AuthorFilesLines
2025-08-27rust: move dependencies to rust/Cargo.tomlPaolo Bonzini2-3/+8
As more crates start using the same dependencies, it's better to not repeat the versions and move the dependency declarations to the workspace. Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-08-27rust: declare self as qemu_api for proc-macrosManos Pitsidianakis2-8/+10
Fix an outstanding TODO. Declaring `extern crate self as qemu_api` allows use of `qemu_api` within the qemu_api crate; this allows the Wrapper derive macro and future proc macros to be used interchangeably in the qemu_api crate and other crates. This is not required currently and is only for future-proofing. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Link: https://lore.kernel.org/r/20250728-self-as-qemu_api-v1-1-001c339cccc8@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-08-27rust/qemu-api-macros: make derive(Object) friendly when missing parentMarc-André Lureau1-1/+9
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250826133132.4064478-5-marcandre.lureau@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-08-27subprojects: update proc-macro2 and synPaolo Bonzini1-4/+4
syn 2.0.69 adds Punctuated::get(). The serde and attrs crate also need a newer version. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-08-27rust: qemu-api-macros: support matching more than one errorPaolo Bonzini1-3/+3
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-08-27rust: disable borrow_as_ptr warningPaolo Bonzini1-1/+0
This is pretty noisy, but it was not visible until now because it only shows up if the rust-version has "&raw const". Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-22rust/pl011: merge device_class.rs into device.rsManos Pitsidianakis3-111/+96
The split was a relic of early development and is not necessary. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Link: https://lore.kernel.org/r/20250718-rust-pl011-cleanup-v1-1-c71b1d6a69a5@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-22rust: devices are not staticlibsPaolo Bonzini2-6/+0
This is only cosmetic for now, but hopefully later on Meson will parse more of Cargo.toml. Devices are linked into a staticlib but are not staticlibs themselves. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-16Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu ↵Stefan Hajnoczi1-1/+2
into staging virtio,pci,pc: features, fixes, tests SPCR acpi table can now be disabled vhost-vdpa can now report hashing capability to guest PPTT acpi table now tells guest vCPUs are identical vost-user-blk now shuts down faster loongarch64 now supports bios-tables-test intel_iommu now supports ATS cxl now supports DCD Fabric Management Command Set arm now supports acpi pci hotplug fixes, cleanups Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # -----BEGIN PGP SIGNATURE----- # # iQFDBAABCgAtFiEEXQn9CHHI+FuUyooNKB8NuNKNVGkFAmh1+7APHG1zdEByZWRo # YXQuY29tAAoJECgfDbjSjVRpcZ8H/2udpCZ49vjPB8IwQAGdFTw2TWVdxUQFHexQ # pOsCGyFBNAXqD1bmb8lwWyYVJ08WELyL6xWsQ5tfVPiXpKYYHPHl4rNr/SPoyNcv # joY++tagudmOki2DU7nfJ+rPIIuigOTUHbv4TZciwcHle6f65s0iKXhR1sL0cj4i # TS6iJlApSuJInrBBUxuxSUomXk79mFTNKRiXj1k58LRw6JOUEgYvtIW8i+mOUcTg # h1dZphxEQr/oG+a2pM8GOVJ1AFaBPSfgEnRM4kTX9QuTIDCeMAKUBo/mwOk6PV7z # ZhSrDPLrea27XKGL++EJm0fFJ/AsHF1dTks2+c0rDrSK+UV87Zc= # =sktm # -----END PGP SIGNATURE----- # gpg: Signature made Tue 15 Jul 2025 02:56:48 EDT # gpg: using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469 # gpg: issuer "mst@redhat.com" # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [full] # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" [full] # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu: (97 commits) hw/cxl: mailbox-utils: 0x5605 - FMAPI Initiate DC Release hw/cxl: mailbox-utils: 0x5604 - FMAPI Initiate DC Add hw/cxl: Create helper function to create DC Event Records from extents hw/cxl: mailbox-utils: 0x5603 - FMAPI Get DC Region Extent Lists hw/cxl: mailbox-utils: 0x5602 - FMAPI Set DC Region Config hw/mem: cxl_type3: Add DC Region bitmap lock hw/cxl: Move definition for dynamic_capacity_uuid and enum for DC event types to header hw/cxl: mailbox-utils: 0x5601 - FMAPI Get Host Region Config hw/mem: cxl_type3: Add dsmas_flags to CXLDCRegion struct hw/cxl: mailbox-utils: 0x5600 - FMAPI Get DCD Info hw/cxl: fix DC extent capacity tracking tests: virt: Update expected ACPI tables for virt test hw/acpi/aml-build: Build a root node in the PPTT table hw/acpi/aml-build: Set identical implementation flag for PPTT processor nodes tests: virt: Allow changes to PPTT test table qtest/bios-tables-test: Generate reference blob for DSDT.acpipcihp qtest/bios-tables-test: Generate reference blob for DSDT.hpoffacpiindex tests/qtest/bios-tables-test: Add aarch64 ACPI PCI hotplug test tests/qtest/bios-tables-test: Prepare for addition of acpi pci hp tests hw/arm/virt: Let virt support pci hotplug/unplug GED event ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Conflicts: net/vhost-vdpa.c vhost_vdpa_set_steering_ebpf() was removed, resolve the context conflict.
2025-07-15rust: bindings: allow any number of paramsMichael S. Tsirkin1-1/+2
We are going to be adding more parameters, and this makes rust unhappy: Functions with lots of parameters are considered bad style and reduce readability (“what does the 5th parameter mean?”). Consider grouping some parameters into a new type. Specifically: error: this function has too many arguments (8/7) --> /builds/mstredhat/qemu/build/rust/qemu-api/rust-qemu-api-tests.p/structured/bindings.inc.rs:3840:5 | 3840 | / pub fn new_bitfield_1( 3841 | | secure: std::os::raw::c_uint, 3842 | | space: std::os::raw::c_uint, 3843 | | user: std::os::raw::c_uint, ... | 3848 | | address_type: std::os::raw::c_uint, 3849 | | ) -> __BindgenBitfieldUnit<[u8; 4usize]> { | |____________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `-D clippy::too-many-arguments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <e41344bd22248b0883752ef7a7c459090a3d9cfc.1752560127.git.mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2025-07-10rust/qemu-api: log: implement io::WritePaolo Bonzini1-8/+84
This makes it possible to lock the log file; it also makes log_mask_ln! not allocate memory when logging a constant string. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-10rust/qemu-api-macros: add unit testsManos Pitsidianakis3-0/+143
Add unit tests to check Derive macro output for expected error messages, or for expected correct codegen output. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250704-rust_add_derive_macro_unit_tests-v1-2-ebd47fa7f78f@linaro.org [Remove usage of MacroError. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-10rust/qemu-api-macros: normalize TryInto outputManos Pitsidianakis1-2/+2
Remove extraneous `;` and add missing trailing comma to TryInto derive macro to match rustfmt style. We will add a test in the followup commit and we would like the inlined output in the test body to be properly formatted as well. No functional changes intended. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250704-rust_add_derive_macro_unit_tests-v1-1-ebd47fa7f78f@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-10rust/bindings: allow unnecessary_transmutes (1.88)Manos Pitsidianakis1-0/+1
This is a new lint introduced in Rust 1.88. It does not affect compilation when using a previous version or our MSRV, 1.77. But with 1.88 compilation fails because we deny all warnings: error: unnecessary transmute --> rust/qemu-api/libqemu_api.rlib.p/structured/bindings.inc.rs:729:18 | 729 | unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 24u8) as u32) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this with: `u32::cast_signed(self._bitfield_1.get(0usize, 24u8) as u32)` | = note: `-D unnecessary-transmutes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unnecessary_transmutes)]` Allow this lint, which even though it does not exist in previous versions, it works because we allow for `unknown_lints` in rust/Cargo.toml. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Link: https://lore.kernel.org/r/20250703-rust_bindings_allow_unnecessary_transmutes-v1-1-692ca210d331@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-10rust/qemu-api-macros: use syn::Error directlyManos Pitsidianakis3-106/+64
Our MacroError type wraps syn::Error as a variant, and uses another variant for custom errors. Fortunately syn::Error can be used directly, avoiding extra code on our side, so change the proc macro crate to use it. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Link: https://lore.kernel.org/r/20250703-rust_macros-v1-1-b99f82febbbf@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-10rust/qemu-api: Fix binding path in source directoryZhao Liu1-5/+7
The build.rs had supported placing bindings.inc.rs in rust/qemu-api/src, but this "not encouraged" feature is broken. Considering that manually copying bindings.inc.rs to the development directory is also useful, fix the bindings.inc.rs path generation to give this feature another chance. Fixes: commit 1ae4ca0463d7 ("rust: move rust.bindgen to qemu-api crate") Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250623073436.1833357-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-20rust: hpet: fix new warningPaolo Bonzini1-1/+1
Nightly rustc complains that HPETAddrDecode has a lifetime but it is not clearly noted that it comes from &self. Apply the compiler's suggestion to shut it up. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-20rust: pl011: Add missing logging to match C versionBernhard Beschow1-0/+6
Co-developed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Bernhard Beschow <shentey@gmail.com> Link: https://lore.kernel.org/r/20250615112037.11992-4-shentey@gmail.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-20rust: pl011: Implement loggingBernhard Beschow1-4/+8
Now that there is logging support in Rust for QEMU, use it in the pl011 device. Signed-off-by: Bernhard Beschow <shentey@gmail.com> Link: https://lore.kernel.org/r/20250615112037.11992-3-shentey@gmail.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-20rust/qemu-api: Add initial logging support based on C APIBernhard Beschow5-0/+79
A log_mask_ln!() macro is provided which expects similar arguments as the C version. However, the formatting works as one would expect from Rust. To maximize code reuse the macro is just a thin wrapper around qemu_log(). Also, just the bare minimum of logging masks is provided which should suffice for the current use case of Rust in QEMU. Signed-off-by: Bernhard Beschow <shentey@gmail.com> Link: https://lore.kernel.org/r/20250615112037.11992-2-shentey@gmail.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-20rust: move rust.bindgen to qemu-api cratePaolo Bonzini4-2/+45
Once qemu-api is split in multiple crates, each of them will have its own invocation of bindgen. There cannot be only one, because there are occasional "impl" blocks for the bindgen-generated structs (e.g. VMStateFlags or QOM classes) that have to reside in the same crate as the bindgen-generated code. For now, prepare for this new organization by invoking bindgen within the qemu-api crate's build definitions; it's also a much better place to list enums that need specific treatment from bindgen. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-20rust: prepare variable definitions for multiple bindgen invocationsPaolo Bonzini2-2/+2
When splitting the QEMU Rust bindings into multiple crates, the bindgen-generated structs also have to be split so that it's possible to add "impl" blocks (e.g. for Sync/Send or Default, or even for utility methods in cases such as VMStateFlags). Tweak various variable definitions in meson.build, to avoid naming conflicts once there will be multiple bindgen invocations. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17rust: qom: change instance_init to take a ParentInit<>Paolo Bonzini5-57/+63
This removes undefined behavior associated to writing to uninitialized fields, and makes it possible to remove "unsafe" from the instance_init implementation. However, the init function itself is still unsafe, because it must promise (as a sort as MaybeUninit::assume_init) that all fields have been initialized. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17rust: qom: make ParentInit lifetime-invariantPaolo Bonzini1-4/+85
This is the trick that allows the parent-field initializer to be used only for the object that it's meant to be initialized. This way, the owner of a MemoryRegion must be the object that embeds it. More information is in the comments; it's best explained with a simplified example. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17rust: qom: introduce ParentInitPaolo Bonzini1-1/+95
This is a smart pointer for MaybeUninit; it can be upcasted to the already-initialized parent classes, or dereferenced to a MaybeUninit for the class that is being initialized. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17rust: hpet: fully initialize object during instance_initPaolo Bonzini1-17/+25
The array of BqlRefCell<HPETTimer> is not initialized yet at the end of instance_init. In particular, the "state" field is NonNull and therefore it is invalid to have it as zero bytes. Note that MaybeUninit is necessary because assigning to self.timers[index] would trigger Drop of the old value. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17rust: qemu_api: introduce MaybeUninit field projectionPaolo Bonzini3-0/+87
Add a macro that makes it possible to convert a MaybeUninit<> into another MaybeUninit<> for a single field within it. Furthermore, it is possible to use the resulting MaybeUninitField<> in APIs that take the parent object, such as memory_region_init_io(). This allows removing some of the undefined behavior from instance_init() functions, though this may not be the definitive implementation. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-06rust: make TryFrom macro more resilientPaolo Bonzini1-3/+4
If the enum includes values such as "Ok", "Err", or "Error", the TryInto macro can cause errors. Be careful and qualify identifiers with the full path, or in the case of TryFrom<>::Error do not use the associated type at all. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-06rust/hpet: Drop BqlCell wrapper for num_timersZhao Liu1-16/+11
Now that the num_timers field is initialized as a property, someone may change its default value using qdev_prop_set_uint8(), but the value is fixed after the Rust code sees it first. Since there is no need to modify it after realize(), it is not to be necessary to have a BqlCell wrapper. Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250520152750.2542612-4-zhao1.liu@intel.com [Remove .into() as well. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-06rust/hpet: return errors from realize if properties are incorrectPaolo Bonzini2-13/+10
Match the code in hpet.c; this also allows removing the BqlCell from the num_timers field. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-06rust/hpet: change type of num_timers to usizePaolo Bonzini1-12/+12
Remove the need to convert after every read of the BqlCell. Because the vmstate uses a u8 as the size of the VARRAY, this requires switching the VARRAY to use num_timers_save; which in turn requires ensuring that the num_timers_save is always there. For simplicity do this by removing support for version 1, which QEMU has not been producing for ~15 years. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-06rust: qdev: support returning errors from realizePaolo Bonzini3-8/+14
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-05rust: qemu-api: add tests for Error bindingsPaolo Bonzini1-0/+104
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-05rust: qemu-api: add bindings to ErrorPaolo Bonzini6-0/+336
Provide an implementation of std::error::Error that bridges the Rust anyhow::Error and std::panic::Location types with QEMU's Error*. It also has several utility methods, analogous to error_propagate(), that convert a Result into a return value + Error** pair. One important difference is that these propagation methods *panic* if *errp is NULL, unlike error_propagate() which eats subsequent errors[1]. The reason for this is that in C you have an error_set*() call at the site where the error is created, and calls to error_propagate() are relatively rare. In Rust instead, even though these functions do "propagate" a qemu_api::Error into a C Error**, there is no error_setg() anywhere that could check for non-NULL errp and call abort(). error_propagate()'s behavior of ignoring subsequent errors is generally considered weird, and there would be a bigger risk of triggering it from Rust code. [1] This is actually a violation of the preconditions of error_propagate(), so it should not happen. But you never know... Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-05util/error: expose Error definition to Rust codePaolo Bonzini1-0/+1
This is used to preserve the file and line in a roundtrip from C Error to Rust and back to C. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-05subprojects: add the foreign cratePaolo Bonzini2-1/+3
This is a cleaned up and separated version of the patches at https://lore.kernel.org/all/20240701145853.1394967-4-pbonzini@redhat.com/ https://lore.kernel.org/all/20240701145853.1394967-5-pbonzini@redhat.com/ Its first user will be the Error bindings; for example a QEMU Error ** can be converted to a Rust Option using unsafe { Option::<Error>::from_foreign(c_error) } Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-05subprojects: add the anyhow cratePaolo Bonzini2-1/+3
This is a standard replacement for Box<dyn Error> which is more efficient (it only occcupies one word) and provides a backtrace of the error. This could be plumbed into &error_abort in the future. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: qemu-api-macros: add from_bits and into_bits to #[derive(TryInto)]Paolo Bonzini1-8/+36
These const functions make it possible to use enums easily together with the bitfield-struct crate. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: pl011: use the bits macroPaolo Bonzini5-44/+49
This avoids the repeated ".0" when using the Interrupt struct. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: add "bits", a custom bitflags implementationPaolo Bonzini8-0/+728
One common thing that device emulation does is manipulate bitmasks, for example to check whether two bitmaps have common bits. One example in the pl011 crate is the checks for pending interrupts, where an interrupt cause corresponds to at least one interrupt source from a fixed set. Unfortunately, this is one case where Rust *can* provide some kind of abstraction but it does so with a rather Perl-ish There Is More Way To Do It. It is not something where a crate like "bilge" helps, because it only covers the packing of bits in a structure; operations like "are all bits of Y set in X" almost never make sense for bit-packed structs; you need something else, there are several crates that do it and of course we're going to roll our own. In particular I examined three: - bitmask (https://docs.rs/bitmask/0.5.0/bitmask/) does not support const at all. This is a showstopper because one of the ugly things in the current pl011 code is the ugliness of code that defines interrupt masks at compile time: pub const E: Self = Self(Self::OE.0 | Self::BE.0 | Self::PE.0 | Self::FE.0); or even worse: const IRQMASK: [u32; 6] = [ Interrupt::E.0 | Interrupt::MS.0 | Interrupt::RT.0 | Interrupt::TX.0 | Interrupt::RX.0, ... } You would have to use roughly the same code---"bitmask" only helps with defining the struct. - bitmask_enum (https://docs.rs/bitmask-enum/2.2.5/bitmask_enum/) does not have a good separation of "valid" and "invalid" bits, so for example "!x" will invert all 16 bits if you choose u16 as the representation -- even if you only defined 10 bits. This makes it easier to introduce subtle bugs in comparisons. - bitflags (https://docs.rs/bitflags/2.6.0/bitflags/) is generally the most used such crate and is the one that I took most inspiration from with respect to the syntax. It's a pretty sophisticated implementation, with a lot of bells and whistles such as an implementation of "Iter" that returns the bits one at a time. The main thing that all of them lack, however, is a way to simplify the ugly definitions like the above. "bitflags" includes const methods that perform AND/OR/XOR of masks (these are necessary because Rust operator overloading does not support const yet, and therefore overloaded operators cannot be used in the definition of a "static" variable), but they become even more verbose and unmanageable, like Interrupt::E.union(Interrupt::MS).union(Interrupt::RT).union(Interrupt::TX).union(Interrupt::RX) This was the main reason to create "bits", which allows something like bits!(Interrupt: E | MS | RT | TX | RX) and expands it 1) add "Interrupt::" in front of all identifiers 2) convert operators to the wordy const functions like "union". It supports boolean operators "&", "|", "^", "!" and parentheses, with a relatively simple recursive descent parser that's implemented in qemu_api_macros. Since I don't remember exactly how the macro was developed, I cannot exclude that it contains code from "bitflags". Therefore, I am conservatively leaving in the MIT and Apache 2.0 licenses from bitflags. In fact, I think there would be a benefit in being able to push code back to "bitflags" anyway whenever applicable, so that the two libraries do not diverge too much, so that's another reason to use this. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: use native Meson support for clippy and rustdocPaolo Bonzini3-16/+0
Meson 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. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: cell: remove support for running doctests with "cargo test --doc"Paolo Bonzini1-13/+9
This is not needed anymore now that tests link with libqemuutil. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: add qemu-api doctests to "meson test"Paolo Bonzini1-0/+9
Doctests 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. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: use "objects" for Rust executables as wellPaolo Bonzini2-22/+7
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. Reported-by: Bernhard Beschow <shentey@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03rust: bindings: allow ptr_offset_with_castPaolo Bonzini1-0/+1
This is produced by recent versions of bindgen: warning: use of `offset` with a `usize` casted to an `isize` --> /builds/bonzini/qemu/rust/target/debug/build/qemu_api-35cb647f4db404b8/out/bindings.inc.rs:39:21 | 39 | let byte = *(core::ptr::addr_of!((*this).storage) as *const u8).offset(byte_index as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(core::ptr::addr_of!((*this).storage) as *const u8).add(byte_index)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast = note: `#[warn(clippy::ptr_offset_with_cast)]` on by default warning: use of `offset` with a `usize` casted to an `isize` --> /builds/bonzini/qemu/rust/target/debug/build/qemu_api-35cb647f4db404b8/out/bindings.inc.rs:68:13 | 68 | (core::ptr::addr_of_mut!((*this).storage) as *mut u8).offset(byte_index as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(core::ptr::addr_of_mut!((*this).storage) as *mut u8).add(byte_index)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast This seems to be new in bindgen 0.71.0, possibly related to bindgen commit 33006185b7878 ("Add raw_ref_macros feature", 2024-11-22). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-28rust: make declaration of dependent crates more consistentPaolo Bonzini4-23/+23
Crates like "bilge" and "libc" can be shared by more than one directory, so declare them directly in rust/meson.build. While at it, make their variable names end with "_rs" and always add a subproject() statement (as that pinpoints the error better if the subproject is missing and cannot be downloaded). Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-27rust: hpet: rename hpet module to "device"Paolo Bonzini2-1/+1
Follow a similar convention as pl011. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-26rust: Fix the typos in docZhao Liu3-5/+5
These typos are found by "cargo spellcheck". Though it outputs a lot of noise and false positives, there still are some real typos. Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250520152750.2542612-6-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-26rust: Fix Zhao's email addressZhao Liu6-6/+6
No one could find Zhao Liu via zhai1.liu@intel.com. Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250520152750.2542612-5-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-14rust: pl011: Cut down amount of text quoted from PL011 TRMPeter Maydell1-210/+51
Currently the comments in the Rust pl011 register.rs file include large amounts of text from the PL011 TRM. This is much more commentary than we typically quote from a device reference manual, and much of it is not relevant to QEMU. Compress and rephrase the comments so that we are not quoting such a large volume of TRM text. We add a URL for the TRM; readers who need more detail on the function of the register bits can find it there, presented in context with the overall description of the hardware. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>