]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
rust: re-export qemu macros from common/qom/hwcore
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Mon, 8 Sep 2025 10:50:02 +0000 (12:50 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 17 Sep 2025 17:00:58 +0000 (19:00 +0200)
This is just a bit nicer.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Link: https://lore.kernel.org/r/20250827104147.717203-22-marcandre.lureau@redhat.com
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
34 files changed:
docs/devel/rust.rst
rust/Cargo.lock
rust/chardev/Cargo.toml
rust/chardev/meson.build
rust/chardev/src/chardev.rs
rust/common/Cargo.toml
rust/common/meson.build
rust/common/src/lib.rs
rust/common/src/opaque.rs
rust/hw/char/pl011/Cargo.toml
rust/hw/char/pl011/meson.build
rust/hw/char/pl011/src/device.rs
rust/hw/char/pl011/src/registers.rs
rust/hw/core/Cargo.toml
rust/hw/core/meson.build
rust/hw/core/src/irq.rs
rust/hw/core/src/lib.rs
rust/hw/core/src/qdev.rs
rust/hw/core/src/sysbus.rs
rust/hw/core/tests/tests.rs
rust/hw/timer/hpet/Cargo.toml
rust/hw/timer/hpet/meson.build
rust/hw/timer/hpet/src/device.rs
rust/meson.build
rust/migration/Cargo.toml
rust/qom/src/lib.rs
rust/qom/src/qom.rs
rust/system/Cargo.toml
rust/system/meson.build
rust/system/src/memory.rs
rust/tests/Cargo.toml
rust/util/Cargo.toml
rust/util/meson.build
rust/util/src/timer.rs

index 20d15347defb43b9801f1fe3c0f08b5d34067a6f..29eb48af35b519c5d23f5be1fcfe17085a6bab1d 100644 (file)
@@ -278,7 +278,7 @@ a raw pointer, for use in calls to C functions.  It can be used for
 example as follows::
 
     #[repr(transparent)]
-    #[derive(Debug, qemu_api_macros::Wrapper)]
+    #[derive(Debug, common::Wrapper)]
     pub struct Object(Opaque<bindings::Object>);
 
 where the special ``derive`` macro provides useful methods such as
index ac79c6a34a96724d2d869f4f9d1cfe6d0dd63d4d..eea928621a7db5855fd0c4fcd4b9bf98825b2c37 100644 (file)
@@ -58,7 +58,6 @@ dependencies = [
  "bql",
  "common",
  "migration",
- "qemu_macros",
  "qom",
  "util",
 ]
@@ -68,6 +67,7 @@ name = "common"
 version = "0.1.0"
 dependencies = [
  "libc",
+ "qemu_macros",
 ]
 
 [[package]]
@@ -93,7 +93,6 @@ dependencies = [
  "common",
  "hwcore",
  "migration",
- "qemu_macros",
  "qom",
  "system",
  "util",
@@ -133,7 +132,6 @@ name = "migration"
 version = "0.1.0"
 dependencies = [
  "common",
- "qemu_macros",
  "util",
 ]
 
@@ -149,7 +147,6 @@ dependencies = [
  "common",
  "hwcore",
  "migration",
- "qemu_macros",
  "qom",
  "system",
  "util",
@@ -232,7 +229,6 @@ name = "system"
 version = "0.1.0"
 dependencies = [
  "common",
- "qemu_macros",
  "qom",
  "util",
 ]
@@ -246,7 +242,6 @@ dependencies = [
  "common",
  "hwcore",
  "migration",
- "qemu_macros",
  "qom",
  "system",
  "util",
@@ -266,7 +261,6 @@ dependencies = [
  "common",
  "foreign",
  "libc",
- "qemu_macros",
 ]
 
 [[package]]
index c13917730786b4eeddf7022758d50a21a6a6b508..3e77972546eb63fc603678c8f7453735815b8afc 100644 (file)
@@ -18,7 +18,6 @@ bql = { path = "../bql" }
 migration = { path = "../migration" }
 qom = { path = "../qom" }
 util = { path = "../util" }
-qemu_macros = { path = "../qemu-macros" }
 
 [lints]
 workspace = true
index a2fa3268d21cf76042763ed793944d0ff41b5b7b..370895c111fd0fddbc276bda36cdfed84329e8a6 100644 (file)
@@ -38,4 +38,4 @@ _chardev_rs = static_library(
   dependencies: [common_rs, qemu_macros],
 )
 
-chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [qemu_macros, chardev, qemuutil])
+chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [chardev, qemuutil])
index cb6f99398eb3053e2ad0da5f907b30feeb44f0d6..2014479674f28d46088c400d756ccb5c8fc22279 100644 (file)
@@ -26,7 +26,7 @@ use crate::bindings;
 
 /// A safe wrapper around [`bindings::Chardev`].
 #[repr(transparent)]
-#[derive(qemu_macros::Wrapper)]
+#[derive(common::Wrapper)]
 pub struct Chardev(Opaque<bindings::Chardev>);
 
 pub type ChardevClass = bindings::ChardevClass;
index 5e106427e80a2ed4e3440490ba64c6652e9c9e28..0e1b4fc5050273074f7b9150a7dfe8d4a59257c4 100644 (file)
@@ -14,6 +14,7 @@ rust-version.workspace = true
 
 [dependencies]
 libc.workspace = true
+qemu_macros = { path = "../qemu-macros" }
 
 [lints]
 workspace = true
index 230a967760dce770c48c729f6d62ef124704c94a..b805e0faf573d8e928724172adf1962be40fe27a 100644 (file)
@@ -19,7 +19,7 @@ _common_rs = static_library(
   override_options: ['rust_std=2021', 'build.rust_std=2021'],
   rust_abi: 'rust',
   rust_args: _common_cfg,
-  dependencies: [libc_rs],
+  dependencies: [libc_rs, qemu_macros],
 )
 
 common_rs = declare_dependency(link_with: [_common_rs])
index 25216503aab28405ac1784388226a6cd45c6077d..8311bf945da84a36011ee89f93a44485da0a970e 100644 (file)
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
+pub use qemu_macros::{TryInto, Wrapper};
+
 pub mod assertions;
 
 pub mod bitops;
index 3b3263acaa340dad6fb719c8325a01cbf9fed536..c941fb45462d88b599944165814784531f610728 100644 (file)
@@ -192,7 +192,7 @@ impl<T: Default> Opaque<T> {
 
 /// Annotates [`Self`] as a transparent wrapper for another type.
 ///
-/// Usually defined via the [`qemu_macros::Wrapper`] derive macro.
+/// Usually defined via the [`crate::Wrapper`] derive macro.
 ///
 /// # Examples
 ///
@@ -227,8 +227,6 @@ impl<T: Default> Opaque<T> {
 /// ```
 ///
 /// They are not defined here to allow them to be `const`.
-///
-/// [`qemu_macros::Wrapper`]: ../../qemu_macros/derive.Wrapper.html
 pub unsafe trait Wrapper {
     type Wrapped;
 }
index 285d25c21788a84625c47b3c8f85781c4273c594..b2418abc4bfe9772522e5f25ea4293c8a4914472 100644 (file)
@@ -24,7 +24,6 @@ qom = { path = "../../../qom" }
 chardev = { path = "../../../chardev" }
 system = { path = "../../../system" }
 hwcore = { path = "../../../hw/core" }
-qemu_macros = { path = "../../../qemu-macros" }
 
 [lints]
 workspace = true
index a14993f6921c5866d90bb0d32baf26be16b3699e..628a5238702213181ec4718ece18213563dbf245 100644 (file)
@@ -35,7 +35,6 @@ _libpl011_rs = static_library(
     util_rs,
     migration_rs,
     bql_rs,
-    qemu_macros,
     qom_rs,
     chardev_rs,
     system_rs,
index 85626a969d41fa36f3aac71dbe17f8a31ed79a9d..1b4587d5f6071b297b3fd3a14486ec1e22038ffb 100644 (file)
@@ -97,7 +97,7 @@ pub struct PL011Registers {
 }
 
 #[repr(C)]
-#[derive(qemu_macros::Object, qemu_macros::Device)]
+#[derive(qom::Object, hwcore::Device)]
 /// PL011 Device Model in QEMU
 pub struct PL011State {
     pub parent_obj: ParentField<SysBusDevice>,
@@ -683,7 +683,7 @@ pub unsafe extern "C" fn pl011_create(
 }
 
 #[repr(C)]
-#[derive(qemu_macros::Object, qemu_macros::Device)]
+#[derive(qom::Object, hwcore::Device)]
 /// PL011 Luminary device model.
 pub struct PL011Luminary {
     parent_obj: ParentField<PL011State>,
index a1c41347ed5bff31eced9a2c9e7ee08ea3bc2011..0c3a4d7d214e51b812698a40a17b7933c6a83859 100644 (file)
@@ -16,7 +16,7 @@ use migration::{impl_vmstate_bitsized, impl_vmstate_forward};
 #[doc(alias = "offset")]
 #[allow(non_camel_case_types)]
 #[repr(u64)]
-#[derive(Debug, Eq, PartialEq, qemu_macros::TryInto)]
+#[derive(Debug, Eq, PartialEq, common::TryInto)]
 pub enum RegisterOffset {
     /// Data Register
     ///
index 0eb9ffee2638c97814b785e667bf58d6b2ee5211..9a9aa517082ed64773598f69bebc2696861c7cea 100644 (file)
@@ -13,6 +13,7 @@ repository.workspace = true
 rust-version.workspace = true
 
 [dependencies]
+qemu_macros = { path = "../../qemu-macros" }
 common = { path = "../../common" }
 bql = { path = "../../bql" }
 qom = { path = "../../qom" }
@@ -20,7 +21,6 @@ chardev = { path = "../../chardev" }
 migration = { path = "../../migration" }
 system = { path = "../../system" }
 util = { path = "../../util" }
-qemu_macros = { path = "../../qemu-macros" }
 
 [lints]
 workspace = true
index 67eacf854fe7fefaf0c243ef33bec7a9cd338825..81d8c77f9ad7a358d47c4683af77e243e050d794 100644 (file)
@@ -71,7 +71,7 @@ test('rust-hwcore-rs-integration',
         override_options: ['rust_std=2021', 'build.rust_std=2021'],
         rust_args: ['--test'],
         install: false,
-        dependencies: [common_rs, hwcore_rs, bql_rs, migration_rs, qemu_macros, util_rs]),
+        dependencies: [common_rs, hwcore_rs, bql_rs, migration_rs, util_rs]),
     args: [
         '--test', '--test-threads', '1',
         '--format', 'pretty',
index d8d964cad27a2523103fc6d880c97dbc9c4f7392..e0d7784d97bcc76851d90f71439712682d9fb178 100644 (file)
@@ -18,7 +18,7 @@ use crate::bindings::{self, qemu_set_irq};
 
 /// An opaque wrapper around [`bindings::IRQState`].
 #[repr(transparent)]
-#[derive(Debug, qemu_macros::Wrapper)]
+#[derive(Debug, common::Wrapper)]
 pub struct IRQState(Opaque<bindings::IRQState>);
 
 /// Interrupt sources are used by devices to pass changes to a value (typically
index c5588d9bc279cce93c058396e342edc976f26e8f..b40801eb843f7ad537dd1991be5e7e24d2deb9fb 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
+pub use qemu_macros::Device;
 pub use qom;
 
 pub mod bindings;
index c9faf44a71d363ccc47c59be3d7164a2df2aa342..71b9ef141c3a4fd3c82f39ef2979f0e461a1acc0 100644 (file)
@@ -23,7 +23,7 @@ use crate::{
 
 /// A safe wrapper around [`bindings::Clock`].
 #[repr(transparent)]
-#[derive(Debug, qemu_macros::Wrapper)]
+#[derive(Debug, common::Wrapper)]
 pub struct Clock(Opaque<bindings::Clock>);
 
 unsafe impl Send for Clock {}
@@ -31,7 +31,7 @@ unsafe impl Sync for Clock {}
 
 /// A safe wrapper around [`bindings::DeviceState`].
 #[repr(transparent)]
-#[derive(Debug, qemu_macros::Wrapper)]
+#[derive(Debug, common::Wrapper)]
 pub struct DeviceState(Opaque<bindings::DeviceState>);
 
 unsafe impl Send for DeviceState {}
index 92c7449b802d485735105588107be632e7e69579..282315fce99ffc2738ec22b45b6f857ed28704be 100644 (file)
@@ -19,7 +19,7 @@ use crate::{
 
 /// A safe wrapper around [`bindings::SysBusDevice`].
 #[repr(transparent)]
-#[derive(Debug, qemu_macros::Wrapper)]
+#[derive(Debug, common::Wrapper)]
 pub struct SysBusDevice(Opaque<bindings::SysBusDevice>);
 
 unsafe impl Send for SysBusDevice {}
index 2f08b8f3bfebfc01a00669e4e09669ca43af03a4..247d812866dffad14da086518d4c554bb34034dc 100644 (file)
@@ -17,7 +17,7 @@ pub const VMSTATE: VMStateDescription<DummyState> = VMStateDescriptionBuilder::<
     .build();
 
 #[repr(C)]
-#[derive(qemu_macros::Object, qemu_macros::Device)]
+#[derive(qom::Object, hwcore::Device)]
 pub struct DummyState {
     parent: ParentField<DeviceState>,
     #[property(rename = "migrate-clk", default = true)]
@@ -54,7 +54,7 @@ impl DeviceImpl for DummyState {
 }
 
 #[repr(C)]
-#[derive(qemu_macros::Object, qemu_macros::Device)]
+#[derive(qom::Object, hwcore::Device)]
 pub struct DummyChildState {
     parent: ParentField<DummyState>,
 }
index 08bf97af55324d482943db2a3c236eda05ab84b9..f781b28d8b3caef52600a3c1922fcaa1b2049814 100644 (file)
@@ -17,7 +17,6 @@ migration = { path = "../../../migration" }
 bql = { path = "../../../bql" }
 qom = { path = "../../../qom" }
 system = { path = "../../../system" }
-qemu_macros = { path = "../../../qemu-macros" }
 hwcore = { path = "../../../hw/core" }
 
 [lints]
index 8ab26630d959cb52fc80b0485401958c8a486d5e..b6bb9477f0c7d2eed498cd5331fbce2701e11cda 100644 (file)
@@ -8,7 +8,6 @@ _libhpet_rs = static_library(
     util_rs,
     migration_rs,
     bql_rs,
-    qemu_macros,
     qom_rs,
     system_rs,
     hwcore_rs,
index 07e0f639fc4cb41481ee26d949827720c1e5b957..3cfbe9c32bb18003e832f78632a3fbfc6a98e074 100644 (file)
@@ -97,7 +97,7 @@ const HPET_TN_CFG_FSB_CAP_SHIFT: usize = 15;
 /// Timer N Interrupt Routing Capability (bits 32:63)
 const HPET_TN_CFG_INT_ROUTE_CAP_SHIFT: usize = 32;
 
-#[derive(qemu_macros::TryInto)]
+#[derive(common::TryInto)]
 #[repr(u64)]
 #[allow(non_camel_case_types)]
 /// Timer registers, masked by 0x18
@@ -110,7 +110,7 @@ enum TimerRegister {
     ROUTE = 16,
 }
 
-#[derive(qemu_macros::TryInto)]
+#[derive(common::TryInto)]
 #[repr(u64)]
 #[allow(non_camel_case_types)]
 /// Global registers
@@ -520,7 +520,7 @@ impl HPETTimer {
 
 /// HPET Event Timer Block Abstraction
 #[repr(C)]
-#[derive(qemu_macros::Object)]
+#[derive(qom::Object)]
 pub struct HPETState {
     parent_obj: ParentField<SysBusDevice>,
     iomem: MemoryRegion,
index bd9b9cb83eaaa9714c262cdc98c3c4c934fe4f1c..c7bd6aba45f45792592c50a6ba3c3937c2a5707a 100644 (file)
@@ -20,8 +20,9 @@ proc_macro2_rs_native = dependency('proc-macro2-1-rs', native: true)
 
 genrs = []
 
-subdir('common')
 subdir('qemu-macros')
+
+subdir('common')
 subdir('bits')
 subdir('util')
 subdir('migration')
index 66af81e0a35b5d5ffc7d7042111eb25f6be39e43..708bfaaa68256f8d626e3f17a207ead05f2a9cef 100644 (file)
@@ -15,7 +15,6 @@ rust-version.workspace = true
 [dependencies]
 common = { path = "../common" }
 util = { path = "../util" }
-qemu_macros = { path = "../qemu-macros" }
 
 [lints]
 workspace = true
index 204c6fea2ffea0c35a281d314767474337ef00df..24c44fc2afb50652f4945607c79fba75f2039f48 100644 (file)
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
+pub use qemu_macros::Object;
+
 pub mod bindings;
 
 // preserve one-item-per-"use" syntax, it is clearer
index 2cd1d850112013d3a013485a6423144be1ad0a8e..5808051cd77ec290bd892d61df8b43c382e71af5 100644 (file)
@@ -112,7 +112,7 @@ pub use crate::bindings::{type_register_static, ObjectClass};
 
 /// A safe wrapper around [`bindings::Object`].
 #[repr(transparent)]
-#[derive(Debug, qemu_macros::Wrapper)]
+#[derive(Debug, common::Wrapper)]
 pub struct Object(Opaque<bindings::Object>);
 
 unsafe impl Send for Object {}
@@ -173,7 +173,7 @@ macro_rules! qom_isa {
 ///
 /// ```ignore
 /// #[repr(C)]
-/// #[derive(qemu_macros::Object)]
+/// #[derive(qom::Object)]
 /// pub struct MyDevice {
 ///     parent: ParentField<DeviceState>,
 ///     ...
index d8338c8348d594e58f84570c9109034ac2f7987e..7fd369b9e32399173c4e8ea413c89809c16454f8 100644 (file)
@@ -16,7 +16,6 @@ rust-version.workspace = true
 common = { path = "../common" }
 qom = { path = "../qom" }
 util = { path = "../util" }
-qemu_macros = { path = "../qemu-macros" }
 
 [lints]
 workspace = true
index 9f88166f3d394ca9f5315e8753d627be600c3b71..3ec140de018776229c6c41a84d2838768a1a8336 100644 (file)
@@ -39,4 +39,4 @@ _system_rs = static_library(
 )
 
 system_rs = declare_dependency(link_with: [_system_rs],
-  dependencies: [qemu_macros, hwcore])
+  dependencies: [hwcore])
index 7312f809f51b3f6390cfb49b72da9399401f2bfd..02aa3af7b130c07880f97f596399582223459160 100644 (file)
@@ -129,7 +129,7 @@ impl<T> Default for MemoryRegionOpsBuilder<T> {
 
 /// A safe wrapper around [`bindings::MemoryRegion`].
 #[repr(transparent)]
-#[derive(qemu_macros::Wrapper)]
+#[derive(common::Wrapper)]
 pub struct MemoryRegion(Opaque<bindings::MemoryRegion>);
 
 unsafe impl Send for MemoryRegion {}
index 8d106d896d77a1f95ccfb99330a723ebe1a683ca..d47dc3314d81bcc96ccd9365d3768a6aac8df0d4 100644 (file)
@@ -19,7 +19,6 @@ hwcore = { path = "../hw/core" }
 migration = { path = "../migration" }
 util = { path = "../util" }
 bql = { path = "../bql" }
-qemu_macros = { path = "../qemu-macros" }
 qom = { path = "../qom" }
 system = { path = "../system" }
 
index 18e6619ca0662a8ec0081b36ae0bf6dc4378f852..1f6767ed9d102161baaf316289aba1b35e5ce801 100644 (file)
@@ -17,7 +17,6 @@ anyhow = { workspace = true }
 foreign = { workspace = true }
 libc = { workspace = true }
 common = { path = "../common" }
-qemu_macros = { path = "../qemu-macros" }
 
 [lints]
 workspace = true
index 197872c9b23ac01db70e297a776045dccb30494b..87a893673d23b0a80652a3138166508d94ea6a7c 100644 (file)
@@ -39,7 +39,7 @@ _util_rs = static_library(
   ),
   override_options: ['rust_std=2021', 'build.rust_std=2021'],
   rust_abi: 'rust',
-  dependencies: [anyhow_rs, libc_rs, foreign_rs, common_rs, qemu_macros, qom, qemuutil],
+  dependencies: [anyhow_rs, libc_rs, foreign_rs, common_rs, qom, qemuutil],
 )
 
 util_rs = declare_dependency(link_with: [_util_rs], dependencies: [qemuutil, qom])
index 622b6ee30976d2563abbeb79601ce3b98b1ef3f8..c6b3e4088ecb1e1b59bfd51b6f254730237dca7d 100644 (file)
@@ -15,14 +15,14 @@ use crate::bindings::{
 
 /// A safe wrapper around [`bindings::QEMUTimer`].
 #[repr(transparent)]
-#[derive(Debug, qemu_macros::Wrapper)]
+#[derive(Debug, common::Wrapper)]
 pub struct Timer(Opaque<bindings::QEMUTimer>);
 
 unsafe impl Send for Timer {}
 unsafe impl Sync for Timer {}
 
 #[repr(transparent)]
-#[derive(qemu_macros::Wrapper)]
+#[derive(common::Wrapper)]
 pub struct TimerListGroup(Opaque<bindings::QEMUTimerListGroup>);
 
 unsafe impl Send for TimerListGroup {}