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

Introduce windows-core crate #2475

Merged
merged 19 commits into from
Apr 25, 2023
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jobs:
cargo clippy -p test_win32_arrays &&
cargo clippy -p test_window_long &&
cargo clippy -p test_winrt &&
cargo clippy -p tool_core &&
cargo clippy -p tool_gnu &&
cargo clippy -p tool_lib &&
cargo clippy -p tool_license &&
Expand All @@ -132,6 +133,7 @@ jobs:
cargo clippy -p tool_yml &&
cargo clippy -p windows &&
cargo clippy -p windows-bindgen &&
cargo clippy -p windows-core &&
cargo clippy -p windows-implement &&
cargo clippy -p windows-interface &&
cargo clippy -p windows-metadata &&
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
tool: [windows, sys, yml, license]
tool: [windows, sys, yml, license, core]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ jobs:
cargo test -p test_does_not_return &&
cargo test -p test_enums &&
cargo test -p test_error &&
cargo clean &&
cargo test -p test_event &&
cargo clean &&
cargo test -p test_extensions &&
cargo test -p test_handles &&
cargo test -p test_helpers &&
Expand Down Expand Up @@ -130,6 +130,7 @@ jobs:
cargo test -p test_win32_arrays &&
cargo test -p test_window_long &&
cargo test -p test_winrt &&
cargo test -p tool_core &&
cargo test -p tool_gnu &&
cargo test -p tool_lib &&
cargo test -p tool_license &&
Expand All @@ -139,6 +140,7 @@ jobs:
cargo test -p tool_yml &&
cargo test -p windows &&
cargo test -p windows-bindgen &&
cargo test -p windows-core &&
cargo test -p windows-implement &&
cargo test -p windows-interface &&
cargo test -p windows-metadata &&
Expand Down
27 changes: 13 additions & 14 deletions crates/libs/bindgen/src/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ fn gen_class(gen: &Gen, def: TypeDef) -> TokenStream {
return Some(quote! {
#hidden
#features
pub fn #interface_type<R, F: FnOnce(&#interface_type) -> ::windows::core::Result<R>>(
pub fn #interface_type<R, F: FnOnce(&#interface_type) -> ::windows_core::Result<R>>(
callback: F,
) -> ::windows::core::Result<R> {
static SHARED: ::windows::imp::FactoryCache<#name, #interface_type> =
::windows::imp::FactoryCache::new();
) -> ::windows_core::Result<R> {
static SHARED: ::windows_core::imp::FactoryCache<#name, #interface_type> =
::windows_core::imp::FactoryCache::new();
SHARED.call(callback)
}
});
Expand All @@ -83,14 +83,14 @@ fn gen_class(gen: &Gen, def: TypeDef) -> TokenStream {
if gen.reader.type_def_has_default_interface(def) {
let new = if gen.reader.type_def_has_default_constructor(def) {
quote! {
pub fn new() -> ::windows::core::Result<Self> {
pub fn new() -> ::windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
}
fn IActivationFactory<R, F: FnOnce(&::windows::imp::IGenericFactory) -> ::windows::core::Result<R>>(
fn IActivationFactory<R, F: FnOnce(&::windows_core::imp::IGenericFactory) -> ::windows_core::Result<R>>(
callback: F,
) -> ::windows::core::Result<R> {
static SHARED: ::windows::imp::FactoryCache<#name, ::windows::imp::IGenericFactory> =
::windows::imp::FactoryCache::new();
) -> ::windows_core::Result<R> {
static SHARED: ::windows_core::imp::FactoryCache<#name, ::windows_core::imp::IGenericFactory> =
::windows_core::imp::FactoryCache::new();
SHARED.call(callback)
}
}
Expand All @@ -102,7 +102,7 @@ fn gen_class(gen: &Gen, def: TypeDef) -> TokenStream {
#doc
#features
#[repr(transparent)]
pub struct #name(::windows::core::IUnknown);
pub struct #name(::windows_core::IUnknown);
#features
impl #name {
#new
Expand Down Expand Up @@ -176,7 +176,7 @@ fn gen_conversions(
let features = gen.cfg_features(cfg);
let mut tokens = quote! {
#features
::windows::imp::interface_hierarchy!(#name, ::windows::core::IUnknown, ::windows::core::IInspectable);
::windows_core::imp::interface_hierarchy!(#name, ::windows_core::IUnknown, ::windows_core::IInspectable);
};

for interface in interfaces {
Expand All @@ -192,12 +192,11 @@ fn gen_conversions(
}

let into = gen.type_name(&interface.ty);
// TODO: simplify - maybe provide + operator?
let features = gen.cfg_features(&cfg.union(&gen.reader.type_cfg(&interface.ty)));

tokens.combine(&quote! {
#features
impl ::windows::core::CanTryInto<#into> for #name {}
impl ::windows_core::CanTryInto<#into> for #name {}
});
}

Expand All @@ -207,7 +206,7 @@ fn gen_conversions(

tokens.combine(&quote! {
#features
impl ::windows::core::CanTryInto<#into> for #name {}
impl ::windows_core::CanTryInto<#into> for #name {}
});
}

Expand Down
44 changes: 22 additions & 22 deletions crates/libs/bindgen/src/com_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub fn gen(
let params = gen.win32_params(&signature.params, kind);
let generics = expand_generics(generics, quote!(T));
let where_clause =
expand_where_clause(where_clause, quote!(T: ::windows::core::ComInterface));
expand_where_clause(where_clause, quote!(T: ::windows_core::ComInterface));

quote! {
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows::core::Result<T> #where_clause {
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<T> #where_clause {
let mut result__ = ::std::ptr::null_mut();
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args).from_abi(result__)
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).from_abi(result__)
}
}
}
Expand All @@ -52,13 +52,13 @@ pub fn gen(
let params = gen.win32_params(&signature.params, kind);
let generics = expand_generics(generics, quote!(T));
let where_clause =
expand_where_clause(where_clause, quote!(T: ::windows::core::ComInterface));
expand_where_clause(where_clause, quote!(T: ::windows_core::ComInterface));

quote! {
#doc
#features
pub unsafe fn #name<#generics>(&self, #params result__: *mut ::core::option::Option<T>) -> ::windows::core::Result<()> #where_clause {
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args).ok()
pub unsafe fn #name<#generics>(&self, #params result__: *mut ::core::option::Option<T>) -> ::windows_core::Result<()> #where_clause {
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).ok()
}
}
}
Expand All @@ -71,9 +71,9 @@ pub fn gen(
quote! {
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows::core::Result<#return_type> #where_clause {
let mut result__ = ::windows::core::zeroed::<#return_type>();
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args).from_abi(result__)
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<#return_type> #where_clause {
let mut result__ = ::windows_core::zeroed::<#return_type>();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).from_abi(result__)
}
}
}
Expand All @@ -84,8 +84,8 @@ pub fn gen(
quote! {
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows::core::Result<()> #where_clause {
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args).ok()
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<()> #where_clause {
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).ok()
}
}
}
Expand All @@ -100,19 +100,19 @@ pub fn gen(
quote! {
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows::core::Result<#return_type> #where_clause {
let mut result__ = ::windows::core::zeroed::<#return_type>();
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args);
::windows::core::from_abi(result__)
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<#return_type> #where_clause {
let mut result__ = ::windows_core::zeroed::<#return_type>();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args);
::windows_core::from_abi(result__)
}
}
} else {
quote! {
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> #return_type #where_clause {
let mut result__ = ::windows::core::zeroed::<#return_type>();
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args);
let mut result__ = ::windows_core::zeroed::<#return_type>();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args);
::std::mem::transmute(result__)
}
}
Expand All @@ -128,7 +128,7 @@ pub fn gen(
#features
pub unsafe fn #name<#generics>(&self, #params) -> #return_type #where_clause {
let mut result__: #return_type = ::core::mem::zeroed();
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), &mut result__, #args);
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), &mut result__, #args);
result__
}
}
Expand All @@ -142,7 +142,7 @@ pub fn gen(
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) #return_type #where_clause {
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args)
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args)
}
}
}
Expand All @@ -154,7 +154,7 @@ pub fn gen(
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) #where_clause {
(::windows::core::Interface::vtable(self)#bases.#vname)(::windows::core::Interface::as_raw(self), #args)
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args)
}
}
}
Expand All @@ -175,7 +175,7 @@ pub fn gen_upcall(gen: &Gen, sig: &Signature, inner: TokenStream) -> TokenStream
::core::result::Result::Ok(ok__) => {
// use `core::ptr::write` since the result could be uninitialized
::core::ptr::write(#result, ::core::mem::transmute(ok__));
::windows::core::HRESULT(0)
::windows_core::HRESULT(0)
}
::core::result::Result::Err(err) => err.into()
}
Expand Down Expand Up @@ -223,7 +223,7 @@ fn gen_win32_invoke_arg(gen: &Gen, param: &SignatureParam) -> TokenStream {
.contains(ParamAttributes::INPUT)
&& gen.reader.type_is_nullable(&param.ty)
{
quote! { ::windows::core::from_raw_borrowed(&#name) }
quote! { ::windows_core::from_raw_borrowed(&#name) }
} else if (!param.ty.is_pointer() && gen.reader.type_is_nullable(&param.ty))
|| (gen
.reader
Expand Down
20 changes: 10 additions & 10 deletions crates/libs/bindgen/src/delegates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ fn gen_win_delegate(gen: &Gen, def: TypeDef) -> TokenStream {
#doc
#features
#[repr(transparent)]
pub struct #ident(pub ::windows::core::IUnknown, #phantoms) where #constraints;
pub struct #ident(pub ::windows_core::IUnknown, #phantoms) where #constraints;
#features
impl<#constraints> #ident {
pub fn new<#fn_constraint>(invoke: F) -> Self {
let com = #boxed::<#generic_names F> {
vtable: &#boxed::<#generic_names F>::VTABLE,
count: ::windows::imp::RefCount::new(1),
count: ::windows_core::imp::RefCount::new(1),
invoke,
};
unsafe {
Expand All @@ -103,21 +103,21 @@ fn gen_win_delegate(gen: &Gen, def: TypeDef) -> TokenStream {
struct #boxed<#generic_names #fn_constraint> where #constraints {
vtable: *const #vtbl<#generic_names>,
invoke: F,
count: ::windows::imp::RefCount,
count: ::windows_core::imp::RefCount,
}
#features
impl<#constraints #fn_constraint> #boxed<#generic_names F> {
const VTABLE: #vtbl<#generic_names> = #vtbl::<#generic_names>{
base__: ::windows::core::IUnknown_Vtbl{QueryInterface: Self::QueryInterface, AddRef: Self::AddRef, Release: Self::Release},
base__: ::windows_core::IUnknown_Vtbl{QueryInterface: Self::QueryInterface, AddRef: Self::AddRef, Release: Self::Release},
Invoke: Self::Invoke,
#(#named_phantoms)*
};
unsafe extern "system" fn QueryInterface(this: *mut ::core::ffi::c_void, iid: &::windows::core::GUID, interface: *mut *const ::core::ffi::c_void) -> ::windows::core::HRESULT {
unsafe extern "system" fn QueryInterface(this: *mut ::core::ffi::c_void, iid: &::windows_core::GUID, interface: *mut *const ::core::ffi::c_void) -> ::windows_core::HRESULT {
let this = this as *mut *mut ::core::ffi::c_void as *mut Self;

*interface = if iid == &<#ident as ::windows::core::ComInterface>::IID ||
iid == &<::windows::core::IUnknown as ::windows::core::ComInterface>::IID ||
iid == &<::windows::imp::IAgileObject as ::windows::core::ComInterface>::IID {
*interface = if iid == &<#ident as ::windows_core::ComInterface>::IID ||
iid == &<::windows_core::IUnknown as ::windows_core::ComInterface>::IID ||
iid == &<::windows_core::imp::IAgileObject as ::windows_core::ComInterface>::IID {
&mut (*this).vtable as *mut _ as _
} else {
::core::ptr::null_mut()
Expand All @@ -126,10 +126,10 @@ fn gen_win_delegate(gen: &Gen, def: TypeDef) -> TokenStream {
// TODO: implement IMarshal

if (*interface).is_null() {
::windows::core::HRESULT(-2147467262) // E_NOINTERFACE
::windows_core::HRESULT(-2147467262) // E_NOINTERFACE
} else {
(*this).count.add_ref();
::windows::core::HRESULT(0)
::windows_core::HRESULT(0)
}
}
unsafe extern "system" fn AddRef(this: *mut ::core::ffi::c_void) -> u32 {
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/bindgen/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ pub fn gen(gen: &Gen, def: TypeDef) -> TokenStream {
let name = type_name.name;
tokens.combine(&quote! {
#features
impl ::windows::core::TypeKind for #ident {
type TypeKind = ::windows::core::CopyType;
impl ::windows_core::TypeKind for #ident {
type TypeKind = ::windows_core::CopyType;
}
#features
impl ::core::fmt::Debug for #ident {
Expand Down Expand Up @@ -192,8 +192,8 @@ pub fn gen(gen: &Gen, def: TypeDef) -> TokenStream {

tokens.combine(&quote! {
#features
impl ::windows::core::RuntimeType for #ident {
const SIGNATURE: ::windows::imp::ConstBuffer = ::windows::imp::ConstBuffer::from_slice(#signature);
impl ::windows_core::RuntimeType for #ident {
const SIGNATURE: ::windows_core::imp::ConstBuffer = ::windows_core::imp::ConstBuffer::from_slice(#signature);
}
});
}
Expand Down
Loading