diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 8af27305b2..afc3bf8d3e 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -107,6 +107,7 @@ jobs: cargo clippy -p test_helpers && cargo clippy -p test_implement && cargo clippy -p test_interface && + cargo clippy -p test_interface_core && cargo clippy -p test_interop && cargo clippy -p test_lib && cargo clippy -p test_literals && diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c82b41f82..01c49cb8af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -107,14 +107,15 @@ jobs: cargo test -p test_dispatch && cargo test -p test_does_not_return && cargo test -p test_enums && - cargo clean && cargo test -p test_error && + cargo clean && cargo test -p test_event && cargo test -p test_extensions && cargo test -p test_handles && cargo test -p test_helpers && cargo test -p test_implement && cargo test -p test_interface && + cargo test -p test_interface_core && cargo test -p test_interop && cargo test -p test_lib && cargo test -p test_literals && diff --git a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs b/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs index 68c492f8b2..bba54c4a53 100644 --- a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs +++ b/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/Iterable.rs @@ -1,4 +1,4 @@ -#[::windows_implement::implement(IIterable)] +#[windows_core::implement(IIterable)] struct StockIterable where T: windows_core::RuntimeType + 'static, @@ -25,7 +25,7 @@ where } } -#[::windows_implement::implement(IIterator)] +#[windows_core::implement(IIterator)] struct StockIterator where T: windows_core::RuntimeType + 'static, diff --git a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs b/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs index a6a8268d27..beceb9b4fa 100644 --- a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs +++ b/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/MapView.rs @@ -1,4 +1,4 @@ -#[::windows_implement::implement(IMapView, IIterable>)] +#[windows_core::implement(IMapView, IIterable>)] struct StockMapView where K: windows_core::RuntimeType + 'static, @@ -60,7 +60,7 @@ where } } -#[::windows_implement::implement(IIterator>)] +#[windows_core::implement(IIterator>)] struct StockMapViewIterator<'a, K, V> where K: windows_core::RuntimeType + 'static, @@ -129,7 +129,7 @@ where } } -#[::windows_implement::implement(IKeyValuePair)] +#[windows_core::implement(IKeyValuePair)] struct StockKeyValuePair where K: windows_core::RuntimeType + 'static, diff --git a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs b/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs index a9ca7829b7..7cc82f2b0b 100644 --- a/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs +++ b/crates/libs/bindgen/src/rust/extensions/impl/Foundation/Collections/VectorView.rs @@ -1,4 +1,4 @@ -#[::windows_implement::implement(IVectorView, IIterable)] +#[windows_core::implement(IVectorView, IIterable)] struct StockVectorView where T: windows_core::RuntimeType + 'static, @@ -61,7 +61,7 @@ where } } -#[::windows_implement::implement(IIterator)] +#[windows_core::implement(IIterator)] struct StockVectorViewIterator where T: windows_core::RuntimeType + 'static, diff --git a/crates/libs/core/Cargo.toml b/crates/libs/core/Cargo.toml index e639b19206..b42cf062f5 100644 --- a/crates/libs/core/Cargo.toml +++ b/crates/libs/core/Cargo.toml @@ -25,6 +25,6 @@ path = "../targets" version = "0.1.0" path = "../result" -[features] -default = [] -implement = [] +[dependencies] +windows-implement = { path = "../implement", version = "0.53.0" } +windows-interface = { path = "../interface", version = "0.53.0" } diff --git a/crates/libs/core/src/inspectable.rs b/crates/libs/core/src/inspectable.rs index f051dcfe31..8d8821ee1c 100644 --- a/crates/libs/core/src/inspectable.rs +++ b/crates/libs/core/src/inspectable.rs @@ -50,7 +50,6 @@ impl RuntimeType for IInspectable { impl RuntimeName for IInspectable {} -#[cfg(feature = "implement")] impl IInspectable_Vtbl { pub const fn new() -> Self { unsafe extern "system" fn GetIids(_: *mut std::ffi::c_void, count: *mut u32, values: *mut *mut GUID) -> HRESULT { diff --git a/crates/libs/core/src/lib.rs b/crates/libs/core/src/lib.rs index c9b4d03f78..e5ad41ee83 100644 --- a/crates/libs/core/src/lib.rs +++ b/crates/libs/core/src/lib.rs @@ -44,6 +44,8 @@ pub use strings::*; pub use unknown::*; pub use variant::*; pub use weak::*; +pub use windows_implement::implement; +pub use windows_interface::interface; pub use windows_result::*; /// Attempts to load the factory object for the given WinRT class. diff --git a/crates/libs/core/src/unknown.rs b/crates/libs/core/src/unknown.rs index be5ae80726..c14a40dda1 100644 --- a/crates/libs/core/src/unknown.rs +++ b/crates/libs/core/src/unknown.rs @@ -85,7 +85,6 @@ pub trait IUnknownImpl { unsafe fn GetTrustLevel(&self, value: *mut i32) -> HRESULT; } -#[cfg(feature = "implement")] impl IUnknown_Vtbl { pub const fn new() -> Self { unsafe extern "system" fn QueryInterface(this: *mut std::ffi::c_void, iid: *const GUID, interface: *mut *mut std::ffi::c_void) -> HRESULT { diff --git a/crates/libs/implement/Cargo.toml b/crates/libs/implement/Cargo.toml index 2d2a6e0c20..2a65037c99 100644 --- a/crates/libs/implement/Cargo.toml +++ b/crates/libs/implement/Cargo.toml @@ -3,7 +3,7 @@ name = "windows-implement" version = "0.53.0" authors = ["Microsoft"] edition = "2021" -rust-version = "1.64" +rust-version = "1.62" license = "MIT OR Apache-2.0" description = "The implement macro for the windows crate" repository = "https://github.com/microsoft/windows-rs" diff --git a/crates/libs/implement/src/lib.rs b/crates/libs/implement/src/lib.rs index 7cea47ca52..15ad9cace5 100644 --- a/crates/libs/implement/src/lib.rs +++ b/crates/libs/implement/src/lib.rs @@ -40,7 +40,7 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: let identity_type = if let Some(first) = attributes.implement.first() { first.to_ident() } else { - quote! { ::windows::core::IInspectable } + quote! { ::windows_core::IInspectable } }; let original_type2 = original_type.clone(); @@ -97,11 +97,11 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: unsafe { ::core::mem::transmute(vtable_ptr) } } } - impl #generics ::windows::core::AsImpl<#original_ident::#generics> for #interface_ident where #constraints { + impl #generics ::windows_core::AsImpl<#original_ident::#generics> for #interface_ident where #constraints { // SAFETY: the offset is guranteed to be in bounds, and the implementation struct // is guaranteed to live at least as long as `self`. unsafe fn as_impl(&self) -> &#original_ident::#generics { - let this = ::windows::core::Interface::as_raw(self); + let this = ::windows_core::Interface::as_raw(self); // Subtract away the vtable offset plus 1, for the `identity` field, to get // to the impl struct which contains that original implementation type. let this = (this as *mut *mut ::core::ffi::c_void).sub(1 + #offset) as *mut #impl_ident::#generics; @@ -114,38 +114,38 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: let tokens = quote! { #[repr(C)] struct #impl_ident #generics where #constraints { - identity: *const ::windows::core::IInspectable_Vtbl, + identity: *const ::windows_core::IInspectable_Vtbl, vtables: (#(*const #vtbl_idents,)*), this: #original_ident::#generics, - count: ::windows::core::imp::WeakRefCount, + count: ::windows_core::imp::WeakRefCount, } impl #generics #impl_ident::#generics where #constraints { const VTABLES: (#(#vtbl_idents2,)*) = (#(#vtable_news,)*); - const IDENTITY: ::windows::core::IInspectable_Vtbl = ::windows::core::IInspectable_Vtbl::new::(); + const IDENTITY: ::windows_core::IInspectable_Vtbl = ::windows_core::IInspectable_Vtbl::new::(); fn new(this: #original_ident::#generics) -> Self { Self { identity: &Self::IDENTITY, vtables:(#(&Self::VTABLES.#offset,)*), this, - count: ::windows::core::imp::WeakRefCount::new(), + count: ::windows_core::imp::WeakRefCount::new(), } } } - impl #generics ::windows::core::IUnknownImpl for #impl_ident::#generics where #constraints { + impl #generics ::windows_core::IUnknownImpl for #impl_ident::#generics where #constraints { type Impl = #original_ident::#generics; fn get_impl(&self) -> &Self::Impl { &self.this } - unsafe fn QueryInterface(&self, iid: *const ::windows::core::GUID, interface: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT { + unsafe fn QueryInterface(&self, iid: *const ::windows_core::GUID, interface: *mut *mut ::core::ffi::c_void) -> ::windows_core::HRESULT { if iid.is_null() || interface.is_null() { - return ::windows::core::HRESULT(-2147467261); // E_POINTER + return ::windows_core::HRESULT(-2147467261); // E_POINTER } let iid = &*iid; - *interface = if iid == &<::windows::core::IUnknown as ::windows::core::Interface>::IID - || iid == &<::windows::core::IInspectable as ::windows::core::Interface>::IID - || iid == &<::windows::core::imp::IAgileObject as ::windows::core::Interface>::IID { + *interface = if iid == &<::windows_core::IUnknown as ::windows_core::Interface>::IID + || iid == &<::windows_core::IInspectable as ::windows_core::Interface>::IID + || iid == &<::windows_core::imp::IAgileObject as ::windows_core::Interface>::IID { &self.identity as *const _ as *mut _ } #(#queries)* else { ::core::ptr::null_mut() @@ -153,15 +153,15 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: if !(*interface).is_null() { self.count.add_ref(); - return ::windows::core::HRESULT(0); + return ::windows_core::HRESULT(0); } *interface = self.count.query(iid, &self.identity as *const _ as *mut _); if (*interface).is_null() { - ::windows::core::HRESULT(-2147467262) // E_NOINTERFACE + ::windows_core::HRESULT(-2147467262) // E_NOINTERFACE } else { - ::windows::core::HRESULT(0) + ::windows_core::HRESULT(0) } } fn AddRef(&self) -> u32 { @@ -174,12 +174,12 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: } remaining } - unsafe fn GetTrustLevel(&self, value: *mut i32) -> ::windows::core::HRESULT { + unsafe fn GetTrustLevel(&self, value: *mut i32) -> ::windows_core::HRESULT { if value.is_null() { - return ::windows::core::HRESULT(-2147467261); // E_POINTER + return ::windows_core::HRESULT(-2147467261); // E_POINTER } *value = #trust_level; - ::windows::core::HRESULT(0) + ::windows_core::HRESULT(0) } } impl #generics #original_ident::#generics where #constraints { @@ -189,14 +189,14 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: /// /// This function can only be safely called if `self` has been heap allocated and pinned using /// the mechanisms provided by `implement` macro. - unsafe fn cast(&self) -> ::windows::core::Result { + unsafe fn cast(&self) -> ::windows_core::Result { let boxed = (self as *const _ as *const *mut ::core::ffi::c_void).sub(1 + #interfaces_len) as *mut #impl_ident::#generics; let mut result = ::std::ptr::null_mut(); - _ = <#impl_ident::#generics as ::windows::core::IUnknownImpl>::QueryInterface(&*boxed, &I::IID, &mut result); - ::windows::core::Type::from_abi(result) + _ = <#impl_ident::#generics as ::windows_core::IUnknownImpl>::QueryInterface(&*boxed, &I::IID, &mut result); + ::windows_core::Type::from_abi(result) } } - impl #generics ::core::convert::From<#original_ident::#generics> for ::windows::core::IUnknown where #constraints { + impl #generics ::core::convert::From<#original_ident::#generics> for ::windows_core::IUnknown where #constraints { fn from(this: #original_ident::#generics) -> Self { let this = #impl_ident::#generics::new(this); let boxed = ::core::mem::ManuallyDrop::new(::std::boxed::Box::new(this)); @@ -205,7 +205,7 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: } } } - impl #generics ::core::convert::From<#original_ident::#generics> for ::windows::core::IInspectable where #constraints { + impl #generics ::core::convert::From<#original_ident::#generics> for ::windows_core::IInspectable where #constraints { fn from(this: #original_ident::#generics) -> Self { let this = #impl_ident::#generics::new(this); let boxed = ::core::mem::ManuallyDrop::new(::std::boxed::Box::new(this)); @@ -237,7 +237,7 @@ impl ImplementType { fn to_vtbl_ident(&self) -> proc_macro2::TokenStream { let ident = self.to_ident(); quote! { - <#ident as ::windows::core::Interface>::Vtable + <#ident as ::windows_core::Interface>::Vtable } } } diff --git a/crates/libs/interface/Cargo.toml b/crates/libs/interface/Cargo.toml index 2952604c07..0c6e38d06d 100644 --- a/crates/libs/interface/Cargo.toml +++ b/crates/libs/interface/Cargo.toml @@ -3,7 +3,7 @@ name = "windows-interface" version = "0.53.0" authors = ["Microsoft"] edition = "2021" -rust-version = "1.64" +rust-version = "1.62" license = "MIT OR Apache-2.0" description = "The interface macro for the windows crate" repository = "https://github.com/microsoft/windows-rs" diff --git a/crates/libs/interface/src/lib.rs b/crates/libs/interface/src/lib.rs index 21f8fbaf5a..198e984fd4 100644 --- a/crates/libs/interface/src/lib.rs +++ b/crates/libs/interface/src/lib.rs @@ -98,11 +98,11 @@ impl Interface { #(#docs)* #vis struct #name(#parent); #implementation - unsafe impl ::windows::core::Interface for #name { + unsafe impl ::windows_core::Interface for #name { type Vtable = #vtable_name; - const IID: ::windows::core::GUID = #guid; + const IID: ::windows_core::GUID = #guid; } - impl ::windows::core::RuntimeName for #name {} + impl ::windows_core::RuntimeName for #name {} #com_trait #vtable @@ -132,7 +132,7 @@ impl Interface { let ret = &m.ret; quote! { #vis unsafe fn #name(&self, #(#args),*) #ret { - (::windows::core::Interface::vtable(self).#name)(::windows::core::Interface::as_raw(self), #(#params),*) + (::windows_core::Interface::vtable(self).#name)(::windows_core::Interface::as_raw(self), #(#params),*) } } }) @@ -211,7 +211,7 @@ impl Interface { let ret = &m.ret; if parent_vtable.is_some() { quote! { - unsafe extern "system" fn #name, Impl: #trait_name, const OFFSET: isize>(this: *mut ::core::ffi::c_void, #(#args),*) #ret { + unsafe extern "system" fn #name, Impl: #trait_name, const OFFSET: isize>(this: *mut ::core::ffi::c_void, #(#args),*) #ret { let this = (this as *const *const ()).offset(OFFSET) as *const Identity; let this = (*this).get_impl(); this.#name(#(#params),*).into() @@ -220,7 +220,7 @@ impl Interface { } else { quote! { unsafe extern "system" fn #name(this: *mut ::core::ffi::c_void, #(#args),*) #ret { - let this = (this as *mut *mut ::core::ffi::c_void) as *const ::windows::core::ScopedHeap; + let this = (this as *mut *mut ::core::ffi::c_void) as *const ::windows_core::ScopedHeap; let this = (*this).this as *const Impl; (*this).#name(#(#params),*).into() } @@ -255,13 +255,13 @@ impl Interface { #(#vtable_entries)* } impl #vtable_name { - pub const fn new, Impl: #trait_name, const OFFSET: isize>() -> Self { + pub const fn new, Impl: #trait_name, const OFFSET: isize>() -> Self { #(#functions)* Self { base__: #parent_vtable::new::<#parent_vtable_generics>(), #(#entries),* } } - pub fn matches(iid: &windows::core::GUID) -> bool { - iid == &<#name as ::windows::core::Interface>::IID + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &<#name as ::windows_core::Interface>::IID } } } @@ -283,10 +283,10 @@ impl Interface { const VTABLE: #vtable_name = #vtable_name::new::(); } impl #name { - fn new<'a, T: #trait_name>(this: &'a T) -> ::windows::core::ScopedInterface<'a, #name> { - let this = ::windows::core::ScopedHeap { vtable: &#implvtbl_name::::VTABLE as *const _ as *const _, this: this as *const _ as *const _ }; + fn new<'a, T: #trait_name>(this: &'a T) -> ::windows_core::ScopedInterface<'a, #name> { + let this = ::windows_core::ScopedHeap { vtable: &#implvtbl_name::::VTABLE as *const _ as *const _, this: this as *const _ as *const _ }; let this = ::std::mem::ManuallyDrop::new(::std::boxed::Box::new(this)); - unsafe { ::windows::core::ScopedInterface::new(::std::mem::transmute(&this.vtable)) } + unsafe { ::windows_core::ScopedInterface::new(::std::mem::transmute(&this.vtable)) } } } } @@ -298,12 +298,12 @@ impl Interface { let name = &self.name; let name_string = format!("{name}"); quote! { - impl ::core::convert::From<#name> for ::windows::core::IUnknown { + impl ::core::convert::From<#name> for ::windows_core::IUnknown { fn from(value: #name) -> Self { unsafe { ::core::mem::transmute(value) } } } - impl ::core::convert::From<&#name> for ::windows::core::IUnknown { + impl ::core::convert::From<&#name> for ::windows_core::IUnknown { fn from(value: &#name) -> Self { ::core::convert::From::from(::core::clone::Clone::clone(value)) } @@ -460,7 +460,7 @@ impl Guid { let data4_7 = hex_lit(data4_7); let data4_8 = hex_lit(data4_8); Ok(quote! { - ::windows::core::GUID { + ::windows_core::GUID { data1: #data1, data2: #data2, data3: #data3, @@ -469,7 +469,7 @@ impl Guid { }) } else { Ok(quote! { - ::windows::core::GUID::zeroed() + ::windows_core::GUID::zeroed() }) } } diff --git a/crates/libs/windows/Cargo.toml b/crates/libs/windows/Cargo.toml index 07d2f9a64d..1d48c54e6a 100644 --- a/crates/libs/windows/Cargo.toml +++ b/crates/libs/windows/Cargo.toml @@ -24,14 +24,12 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] windows-core = { path = "../core", version = "0.55.0" } windows-targets = { path = "../targets", version = "0.52.4" } -windows-implement = { path = "../implement", version = "0.53.0", optional = true } -windows-interface = { path = "../interface", version = "0.53.0", optional = true } [features] default = [] docs = [] deprecated = [] -implement = ["windows-implement", "windows-interface", "windows-core/implement"] +implement = [] # generated features AI = ["Foundation"] AI_MachineLearning = ["AI"] diff --git a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs index b963aaedb5..040745f1c3 100644 --- a/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs +++ b/crates/libs/windows/src/Windows/Foundation/Collections/impl.rs @@ -708,7 +708,7 @@ impl IVectorView_Vtbl { iid == & as windows_core::Interface>::IID } } -#[::windows_implement::implement(IIterable)] +#[windows_core::implement(IIterable)] struct StockIterable where T: windows_core::RuntimeType + 'static, @@ -731,7 +731,7 @@ where } } -#[::windows_implement::implement(IIterator)] +#[windows_core::implement(IIterator)] struct StockIterator where T: windows_core::RuntimeType + 'static, @@ -798,7 +798,7 @@ where Ok(StockIterable { values }.into()) } } -#[::windows_implement::implement(IMapView, IIterable>)] +#[windows_core::implement(IMapView, IIterable>)] struct StockMapView where K: windows_core::RuntimeType + 'static, @@ -849,7 +849,7 @@ where } } -#[::windows_implement::implement(IIterator>)] +#[windows_core::implement(IIterator>)] struct StockMapViewIterator<'a, K, V> where K: windows_core::RuntimeType + 'static, @@ -908,7 +908,7 @@ where } } -#[::windows_implement::implement(IKeyValuePair)] +#[windows_core::implement(IKeyValuePair)] struct StockKeyValuePair where K: windows_core::RuntimeType + 'static, @@ -948,7 +948,7 @@ where Ok(StockMapView { map }.into()) } } -#[::windows_implement::implement(IVectorView, IIterable)] +#[windows_core::implement(IVectorView, IIterable)] struct StockVectorView where T: windows_core::RuntimeType + 'static, @@ -1004,7 +1004,7 @@ where } } -#[::windows_implement::implement(IIterator)] +#[windows_core::implement(IIterator)] struct StockVectorViewIterator where T: windows_core::RuntimeType + 'static, diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index 9e74cd8360..a75f9c3dba 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -13,14 +13,6 @@ Learn more about Rust for Windows here: HRESULT; +} + +#[implement(ITest)] +struct Test; + +impl ITest_Impl for Test { + unsafe fn Test(&self) -> HRESULT { + HRESULT(123) + } +} + +#[test] +fn test() { + unsafe { + let test: ITest = Test.into(); + assert_eq!(test.Test(), HRESULT(123)); + } +} diff --git a/crates/tests/no_use/Cargo.toml b/crates/tests/no_use/Cargo.toml index ec9e792824..4088cd46de 100644 --- a/crates/tests/no_use/Cargo.toml +++ b/crates/tests/no_use/Cargo.toml @@ -10,3 +10,6 @@ features = [ "implement", "Foundation", ] + +[dependencies.windows-core] +path = "../../libs/core"