Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve class hierarchy support #3212

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ jobs:
run: cargo clippy -p test_calling_convention
- name: Clippy test_cfg_generic
run: cargo clippy -p test_cfg_generic
- name: Clippy test_class_hierarchy
run: cargo clippy -p test_class_hierarchy
- name: Clippy test_collections
run: cargo clippy -p test_collections
- name: Clippy test_component
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ jobs:
run: cargo test -p test_calling_convention --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_cfg_generic
run: cargo test -p test_cfg_generic --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_class_hierarchy
run: cargo test -p test_class_hierarchy --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_collections
run: cargo test -p test_collections --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_component
Expand Down Expand Up @@ -253,10 +255,10 @@ jobs:
run: cargo test -p test_standalone --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_string_param
run: cargo test -p test_string_param --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_strings
run: cargo test -p test_strings --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_strings
run: cargo test -p test_strings --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_structs
run: cargo test -p test_structs --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_sys
Expand Down
22 changes: 16 additions & 6 deletions crates/libs/bindgen/src/rust/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,32 @@ fn gen_conversions(
cfg: &cfg::Cfg,
) -> TokenStream {
let features = writer.cfg_features(cfg);
let mut tokens = quote! {
#features
windows_core::imp::interface_hierarchy!(#ident, windows_core::IUnknown, windows_core::IInspectable);

let mut tokens = if let Some(default) = interfaces.iter().find(|interface| {
!type_is_exclusive(&interface.ty) && interface.kind == metadata::InterfaceKind::Default
}) {
let default = writer.type_name(&default.ty);
quote! {
#features
windows_core::imp::interface_hierarchy!(#ident, windows_core::IUnknown, windows_core::IInspectable, #default);
}
} else {
quote! {
#features
windows_core::imp::interface_hierarchy!(#ident, windows_core::IUnknown, windows_core::IInspectable);
}
};

let mut hierarchy = format!("windows_core::imp::required_hierarchy!({ident}");
let mut hierarchy_cfg = cfg.clone();
let mut hierarchy_added = false;

for interface in interfaces {
if type_is_exclusive(&interface.ty) {
if type_is_exclusive(&interface.ty) || interface.kind == metadata::InterfaceKind::Default {
continue;
}

if interface.kind != metadata::InterfaceKind::Default
&& interface.kind != metadata::InterfaceKind::None
if interface.kind != metadata::InterfaceKind::None
&& interface.kind != metadata::InterfaceKind::Base
{
continue;
Expand Down
182 changes: 90 additions & 92 deletions crates/libs/windows/src/Windows/ApplicationModel/Activation/mod.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1835,8 +1835,7 @@ unsafe impl Sync for AppointmentManagerForUser {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct AppointmentOrganizer(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(AppointmentOrganizer, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(AppointmentOrganizer, IAppointmentParticipant);
windows_core::imp::interface_hierarchy!(AppointmentOrganizer, windows_core::IUnknown, windows_core::IInspectable, IAppointmentParticipant);
impl AppointmentOrganizer {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down
58 changes: 20 additions & 38 deletions crates/libs/windows/src/Windows/ApplicationModel/Background/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,8 +2180,8 @@ unsafe impl Sync for BackgroundTaskProgressEventArgs {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct BackgroundTaskRegistration(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(BackgroundTaskRegistration, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(BackgroundTaskRegistration, IBackgroundTaskRegistration, IBackgroundTaskRegistration2, IBackgroundTaskRegistration3);
windows_core::imp::interface_hierarchy!(BackgroundTaskRegistration, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTaskRegistration);
windows_core::imp::required_hierarchy!(BackgroundTaskRegistration, IBackgroundTaskRegistration2, IBackgroundTaskRegistration3);
impl BackgroundTaskRegistration {
pub fn TaskId(&self) -> windows_core::Result<windows_core::GUID> {
let this = self;
Expand Down Expand Up @@ -2806,8 +2806,7 @@ impl windows_core::RuntimeName for ContentPrefetchTrigger {
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct ConversationalAgentTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(ConversationalAgentTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(ConversationalAgentTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(ConversationalAgentTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl ConversationalAgentTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -3421,8 +3420,7 @@ impl windows_core::RuntimeName for MediaProcessingTrigger {
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct MobileBroadbandDeviceServiceNotificationTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(MobileBroadbandDeviceServiceNotificationTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(MobileBroadbandDeviceServiceNotificationTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(MobileBroadbandDeviceServiceNotificationTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl MobileBroadbandDeviceServiceNotificationTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand All @@ -3447,8 +3445,7 @@ unsafe impl Sync for MobileBroadbandDeviceServiceNotificationTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct MobileBroadbandPcoDataChangeTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(MobileBroadbandPcoDataChangeTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(MobileBroadbandPcoDataChangeTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(MobileBroadbandPcoDataChangeTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl MobileBroadbandPcoDataChangeTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand All @@ -3473,8 +3470,7 @@ unsafe impl Sync for MobileBroadbandPcoDataChangeTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct MobileBroadbandPinLockStateChangeTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(MobileBroadbandPinLockStateChangeTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(MobileBroadbandPinLockStateChangeTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(MobileBroadbandPinLockStateChangeTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl MobileBroadbandPinLockStateChangeTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand All @@ -3499,8 +3495,7 @@ unsafe impl Sync for MobileBroadbandPinLockStateChangeTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct MobileBroadbandRadioStateChangeTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(MobileBroadbandRadioStateChangeTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(MobileBroadbandRadioStateChangeTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(MobileBroadbandRadioStateChangeTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl MobileBroadbandRadioStateChangeTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand All @@ -3525,8 +3520,7 @@ unsafe impl Sync for MobileBroadbandRadioStateChangeTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct MobileBroadbandRegistrationStateChangeTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(MobileBroadbandRegistrationStateChangeTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(MobileBroadbandRegistrationStateChangeTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(MobileBroadbandRegistrationStateChangeTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl MobileBroadbandRegistrationStateChangeTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand All @@ -3551,8 +3545,7 @@ unsafe impl Sync for MobileBroadbandRegistrationStateChangeTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct NetworkOperatorDataUsageTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(NetworkOperatorDataUsageTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(NetworkOperatorDataUsageTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(NetworkOperatorDataUsageTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl NetworkOperatorDataUsageTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -3636,8 +3629,7 @@ impl windows_core::RuntimeName for NetworkOperatorNotificationTrigger {
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct PaymentAppCanMakePaymentTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(PaymentAppCanMakePaymentTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(PaymentAppCanMakePaymentTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(PaymentAppCanMakePaymentTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl PaymentAppCanMakePaymentTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -3708,8 +3700,7 @@ unsafe impl Sync for PhoneTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct PushNotificationTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(PushNotificationTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(PushNotificationTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(PushNotificationTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl PushNotificationTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -3955,8 +3946,7 @@ impl windows_core::RuntimeName for SmartCardTrigger {
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct SmsMessageReceivedTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(SmsMessageReceivedTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(SmsMessageReceivedTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(SmsMessageReceivedTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl SmsMessageReceivedTrigger {
#[cfg(feature = "Devices_Sms")]
pub fn Create<P0>(filterrules: P0) -> windows_core::Result<SmsMessageReceivedTrigger>
Expand Down Expand Up @@ -3989,8 +3979,7 @@ unsafe impl Sync for SmsMessageReceivedTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct SocketActivityTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(SocketActivityTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(SocketActivityTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(SocketActivityTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl SocketActivityTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -4022,8 +4011,7 @@ unsafe impl Sync for SocketActivityTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct StorageLibraryChangeTrackerTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(StorageLibraryChangeTrackerTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(StorageLibraryChangeTrackerTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(StorageLibraryChangeTrackerTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl StorageLibraryChangeTrackerTrigger {
#[cfg(feature = "Storage")]
pub fn Create<P0>(tracker: P0) -> windows_core::Result<StorageLibraryChangeTrackerTrigger>
Expand Down Expand Up @@ -4175,8 +4163,7 @@ impl windows_core::RuntimeName for SystemTrigger {
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct TetheringEntitlementCheckTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(TetheringEntitlementCheckTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(TetheringEntitlementCheckTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(TetheringEntitlementCheckTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl TetheringEntitlementCheckTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -4243,8 +4230,7 @@ impl windows_core::RuntimeName for TimeTrigger {
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct ToastNotificationActionTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(ToastNotificationActionTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(ToastNotificationActionTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(ToastNotificationActionTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl ToastNotificationActionTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -4280,8 +4266,7 @@ unsafe impl Sync for ToastNotificationActionTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct ToastNotificationHistoryChangedTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(ToastNotificationHistoryChangedTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(ToastNotificationHistoryChangedTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(ToastNotificationHistoryChangedTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl ToastNotificationHistoryChangedTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down Expand Up @@ -4317,8 +4302,7 @@ unsafe impl Sync for ToastNotificationHistoryChangedTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct UserNotificationChangedTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(UserNotificationChangedTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(UserNotificationChangedTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(UserNotificationChangedTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl UserNotificationChangedTrigger {
#[cfg(feature = "UI_Notifications")]
pub fn Create(notificationkinds: super::super::UI::Notifications::NotificationKinds) -> windows_core::Result<UserNotificationChangedTrigger> {
Expand Down Expand Up @@ -4348,8 +4332,7 @@ unsafe impl Sync for UserNotificationChangedTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct WiFiOnDemandHotspotConnectTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(WiFiOnDemandHotspotConnectTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(WiFiOnDemandHotspotConnectTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(WiFiOnDemandHotspotConnectTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl WiFiOnDemandHotspotConnectTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand All @@ -4374,8 +4357,7 @@ unsafe impl Sync for WiFiOnDemandHotspotConnectTrigger {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct WiFiOnDemandHotspotUpdateMetadataTrigger(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(WiFiOnDemandHotspotUpdateMetadataTrigger, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(WiFiOnDemandHotspotUpdateMetadataTrigger, IBackgroundTrigger);
windows_core::imp::interface_hierarchy!(WiFiOnDemandHotspotUpdateMetadataTrigger, windows_core::IUnknown, windows_core::IInspectable, IBackgroundTrigger);
impl WiFiOnDemandHotspotUpdateMetadataTrigger {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2706,8 +2706,7 @@ unsafe impl Sync for ContactEmail {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct ContactField(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(ContactField, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(ContactField, IContactField);
windows_core::imp::interface_hierarchy!(ContactField, windows_core::IUnknown, windows_core::IInspectable, IContactField);
impl ContactField {
pub fn Type(&self) -> windows_core::Result<ContactFieldType> {
let this = self;
Expand Down Expand Up @@ -2776,8 +2775,8 @@ unsafe impl Sync for ContactField {}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct ContactFieldFactory(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(ContactFieldFactory, windows_core::IUnknown, windows_core::IInspectable);
windows_core::imp::required_hierarchy!(ContactFieldFactory, IContactFieldFactory, IContactInstantMessageFieldFactory, IContactLocationFieldFactory);
windows_core::imp::interface_hierarchy!(ContactFieldFactory, windows_core::IUnknown, windows_core::IInspectable, IContactFieldFactory);
windows_core::imp::required_hierarchy!(ContactFieldFactory, IContactInstantMessageFieldFactory, IContactLocationFieldFactory);
impl ContactFieldFactory {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
Expand Down
Loading