This inverts the dependency from hwcore to system, replacing it with a dependency from system to hwcore. It also matches how hw/core/sysbus.h is part of the system-sys crate, and hw/core/sysbus.c is part of system_ss on the C side.
This fixes a linker error in hwcore integration tests on msys2. Signed-off-by: Paolo Bonzini <[email protected]> --- rust/hw/core/Cargo.toml | 1 - rust/hw/core/meson.build | 2 +- rust/hw/core/src/irq.rs | 4 ++-- rust/hw/core/src/lib.rs | 3 --- rust/hw/core/src/prelude.rs | 5 ----- rust/hw/core/tests/tests.rs | 4 ++-- rust/meson.build | 2 +- rust/system/Cargo.toml | 1 + rust/system/meson.build | 2 +- rust/system/src/lib.rs | 3 +++ rust/system/src/prelude.rs | 5 +++++ rust/{hw/core => system}/src/sysbus.rs | 7 ++----- 12 files changed, 18 insertions(+), 21 deletions(-) rename rust/{hw/core => system}/src/sysbus.rs (96%) diff --git a/rust/hw/core/Cargo.toml b/rust/hw/core/Cargo.toml index 8cc514da202..d1ff71d5c37 100644 --- a/rust/hw/core/Cargo.toml +++ b/rust/hw/core/Cargo.toml @@ -21,7 +21,6 @@ bql = { path = "../../bql" } qom = { path = "../../qom" } chardev = { path = "../../chardev" } migration = { path = "../../migration" } -system = { path = "../../system" } util = { path = "../../util" } [lints] diff --git a/rust/hw/core/meson.build b/rust/hw/core/meson.build index 28ea00cdb4f..6d1bfd4d204 100644 --- a/rust/hw/core/meson.build +++ b/rust/hw/core/meson.build @@ -3,7 +3,7 @@ _hwcore_rs = static_library( 'src/lib.rs', override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', - link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _system_rs, _util_rs], + link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _util_rs], dependencies: [glib_sys_rs, qemu_macros, common_rs, hwcore_sys_rs], ) diff --git a/rust/hw/core/src/irq.rs b/rust/hw/core/src/irq.rs index e0d7784d97b..2a1ac9e6264 100644 --- a/rust/hw/core/src/irq.rs +++ b/rust/hw/core/src/irq.rs @@ -87,11 +87,11 @@ pub fn set(&self, level: T) { } } - pub(crate) const fn as_ptr(&self) -> *mut *mut bindings::IRQState { + pub const fn as_ptr(&self) -> *mut *mut bindings::IRQState { self.cell.as_ptr() } - pub(crate) const fn slice_as_ptr(slice: &[Self]) -> *mut *mut bindings::IRQState { + pub const fn slice_as_ptr(slice: &[Self]) -> *mut *mut bindings::IRQState { assert!(!slice.is_empty()); slice[0].as_ptr() } diff --git a/rust/hw/core/src/lib.rs b/rust/hw/core/src/lib.rs index 76689fe7db1..6701dc52b65 100644 --- a/rust/hw/core/src/lib.rs +++ b/rust/hw/core/src/lib.rs @@ -14,6 +14,3 @@ mod qdev; pub use qdev::*; - -mod sysbus; -pub use sysbus::*; diff --git a/rust/hw/core/src/prelude.rs b/rust/hw/core/src/prelude.rs index 13f7dfc6809..45e86e178b1 100644 --- a/rust/hw/core/src/prelude.rs +++ b/rust/hw/core/src/prelude.rs @@ -9,9 +9,4 @@ pub use crate::qdev::ResettablePhasesImpl; pub use crate::qdev::ResetType; -pub use crate::sysbus::SysBusDevice; -pub use crate::sysbus::SysBusDeviceClassExt; -pub use crate::sysbus::SysBusDeviceImpl; -pub use crate::sysbus::SysBusDeviceMethods; - pub use crate::irq::InterruptSource; diff --git a/rust/hw/core/tests/tests.rs b/rust/hw/core/tests/tests.rs index 115dd7a860d..05aa5d4a377 100644 --- a/rust/hw/core/tests/tests.rs +++ b/rust/hw/core/tests/tests.rs @@ -142,7 +142,7 @@ fn test_cast() { let obj_ref: &Object = p_ref.upcast(); assert_eq!(addr_of!(*obj_ref), p_ptr.cast()); - let sbd_ref: Option<&SysBusDevice> = obj_ref.dynamic_cast(); + let sbd_ref: Option<&DummyChildState> = obj_ref.dynamic_cast(); assert!(sbd_ref.is_none()); let dev_ref: Option<&DeviceState> = obj_ref.downcast(); @@ -150,7 +150,7 @@ fn test_cast() { // SAFETY: the cast is wrong, but the value is only used for comparison unsafe { - let sbd_ref: &SysBusDevice = obj_ref.unsafe_cast(); + let sbd_ref: &DummyChildState = obj_ref.unsafe_cast(); assert_eq!(addr_of!(*sbd_ref), p_ptr.cast()); } } diff --git a/rust/meson.build b/rust/meson.build index 3a3e10d7b97..b6711fe77dd 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -42,9 +42,9 @@ subdir('util') subdir('bql') subdir('migration') subdir('qom') -subdir('system') subdir('chardev') subdir('hw/core') +subdir('system') subdir('tests') subdir('trace') subdir('hw') diff --git a/rust/system/Cargo.toml b/rust/system/Cargo.toml index f7fde9782ea..d6217370317 100644 --- a/rust/system/Cargo.toml +++ b/rust/system/Cargo.toml @@ -16,6 +16,7 @@ rust-version.workspace = true common = { path = "../common" } system-sys = { path = "../bindings/system-sys" } bql = { path = "../bql" } +hwcore = { path = "../hw/core" } migration = { path = "../migration" } qom = { path = "../qom" } util = { path = "../util" } diff --git a/rust/system/meson.build b/rust/system/meson.build index 4cbd63cbbd7..89c1f2b84d1 100644 --- a/rust/system/meson.build +++ b/rust/system/meson.build @@ -1,7 +1,7 @@ _system_rs = static_library( 'system', 'src/lib.rs', - link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs], + link_with: [_bql_rs, _hwcore_rs, _migration_rs, _qom_rs, _util_rs], dependencies: [glib_sys_rs, common_rs, qemu_macros, system_sys_rs], ) diff --git a/rust/system/src/lib.rs b/rust/system/src/lib.rs index 10741e0ee0a..3b1666e62ce 100644 --- a/rust/system/src/lib.rs +++ b/rust/system/src/lib.rs @@ -9,3 +9,6 @@ // for prelude-like modules #[rustfmt::skip] pub mod prelude; + +mod sysbus; +pub use sysbus::*; diff --git a/rust/system/src/prelude.rs b/rust/system/src/prelude.rs index 2d98524c36e..5a8688ca343 100644 --- a/rust/system/src/prelude.rs +++ b/rust/system/src/prelude.rs @@ -6,3 +6,8 @@ pub use crate::memory::MemoryRegionOps; pub use crate::memory::MemoryRegionOpsBuilder; pub use crate::memory::MemTxAttrs; + +pub use crate::sysbus::SysBusDevice; +pub use crate::sysbus::SysBusDeviceClassExt; +pub use crate::sysbus::SysBusDeviceImpl; +pub use crate::sysbus::SysBusDeviceMethods; diff --git a/rust/hw/core/src/sysbus.rs b/rust/system/src/sysbus.rs similarity index 96% rename from rust/hw/core/src/sysbus.rs rename to rust/system/src/sysbus.rs index 7db09a82c63..3c9aff51be0 100644 --- a/rust/hw/core/src/sysbus.rs +++ b/rust/system/src/sysbus.rs @@ -7,15 +7,12 @@ use std::ffi::CStr; use common::Opaque; +use hwcore::{prelude::*, IRQState}; use qom::prelude::*; -use system::MemoryRegion; pub use system_sys::SysBusDeviceClass; use util::{Error, Result}; -use crate::{ - irq::{IRQState, InterruptSource}, - qdev::{DeviceClassExt, DeviceImpl, DeviceState}, -}; +use crate::MemoryRegion; /// A safe wrapper around [`system_sys::SysBusDevice`]. #[repr(transparent)] -- 2.52.0
