Skip to content

Commit

Permalink
deep references
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Dec 4, 2024
1 parent b6deb8f commit 8115db5
Show file tree
Hide file tree
Showing 26 changed files with 1,257 additions and 333 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ jobs:
run: cargo clippy -p test_query_signature
- name: Clippy test_readme
run: cargo clippy -p test_readme
- name: Clippy test_reference
run: cargo clippy -p test_reference
- name: Clippy test_reference_client
run: cargo clippy -p test_reference_client
- name: Clippy test_reference_float
run: cargo clippy -p test_reference_float
- name: Clippy test_registry
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/raw-dylib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,18 @@ jobs:
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_readme
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_float
run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_registry
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_registry_default
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reserved
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_resources
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,18 @@ jobs:
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_readme
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
run: cargo test -p test_reference_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_float
run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_registry
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_registry_default
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reserved
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_resources
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ where

let reader = Reader::new(expand_input(&input));
let filter = Filter::new(reader, &include, &exclude);
let types = TypeMap::filter(reader, &filter);
let references = References::new(reader, references);
let types = TypeMap::filter(reader, &filter, &references);
let derive = Derive::new(reader, &types, &derive);

let config = Box::leak(Box::new(Config {
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct Reference {
pub style: ReferenceStyle, // how to generate the type path
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct References(Vec<Reference>);

impl References {
Expand All @@ -74,7 +74,7 @@ impl References {
.into_iter()
.map(|stage| {
let filter = Filter::new(reader, &[&stage.path], &[]);
let types = TypeMap::filter(reader, &filter);
let types = TypeMap::filter(reader, &filter, &References::default());

Reference {
name: stage.name,
Expand Down
15 changes: 13 additions & 2 deletions crates/libs/bindgen/src/type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl TypeMap {
Self(HashMap::new())
}

pub fn filter(reader: &'static Reader, filter: &Filter) -> Self {
pub fn filter(reader: &'static Reader, filter: &Filter, references: &References) -> Self {
let mut dependencies = Self::new();

for namespace in reader.keys() {
Expand All @@ -33,7 +33,7 @@ impl TypeMap {
continue;
}

dependencies.combine(&item_dependencies);
dependencies.combine_references(&item_dependencies, references);
}
}
}
Expand All @@ -46,6 +46,17 @@ impl TypeMap {
self.0.entry(ty.type_name()).or_default().insert(ty)
}

fn combine_references(&mut self, other: &Self, references: &References) {
for (tn, types) in &other.0 {
if references.contains(*tn).is_none() {
let set = self.0.entry(*tn).or_default();
types.iter().for_each(|ty| {
set.insert(ty.clone());
});
}
}
}

pub fn combine(&mut self, other: &Self) {
for (name, types) in &other.0 {
let set = self.0.entry(*name).or_default();
Expand Down
6 changes: 5 additions & 1 deletion crates/tests/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ pub mod interface_sys;
pub mod interface_sys_no_core;
pub mod multi;
pub mod multi_sys;
pub mod reference_async_action;
pub mod reference_async_action_reference;
pub mod reference_async_info_no_status;
pub mod reference_async_info_status_filter;
pub mod reference_async_info_status_reference;
pub mod reference_dependency_flat;
pub mod reference_dependency_full;
pub mod reference_dependency_skip_root;
pub mod reference_dependent_flat;
pub mod reference_dependent_full;
pub mod reference_dependent_skip_root;
pub mod reference_windows;
pub mod sort;
pub mod struct_cpp_sys;
pub mod struct_cpp_win;
Expand Down
230 changes: 230 additions & 0 deletions crates/tests/bindgen/src/reference_async_action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]

windows_core::imp::define_interface!(
IAsyncAction,
IAsyncAction_Vtbl,
0x5a648006_843a_4da9_865b_9d26e5dfad7b
);
impl windows_core::RuntimeType for IAsyncAction {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
windows_core::imp::interface_hierarchy!(
IAsyncAction,
windows_core::IUnknown,
windows_core::IInspectable
);
windows_core::imp::required_hierarchy!(IAsyncAction, IAsyncInfo);
impl IAsyncAction {
pub fn GetResults(&self) -> windows_core::Result<()> {
let this = self;
unsafe {
(windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(
this,
))
.ok()
}
}
pub fn Id(&self) -> windows_core::Result<u32> {
let this = &windows_core::Interface::cast::<IAsyncInfo>(self)?;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).Id)(
windows_core::Interface::as_raw(this),
&mut result__,
)
.map(|| result__)
}
}
pub fn ErrorCode(&self) -> windows_core::Result<windows_core::HRESULT> {
let this = &windows_core::Interface::cast::<IAsyncInfo>(self)?;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).ErrorCode)(
windows_core::Interface::as_raw(this),
&mut result__,
)
.map(|| result__)
}
}
pub fn Cancel(&self) -> windows_core::Result<()> {
let this = &windows_core::Interface::cast::<IAsyncInfo>(self)?;
unsafe {
(windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this))
.ok()
}
}
pub fn Close(&self) -> windows_core::Result<()> {
let this = &windows_core::Interface::cast::<IAsyncInfo>(self)?;
unsafe {
(windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this))
.ok()
}
}
}
unsafe impl Send for IAsyncAction {}
unsafe impl Sync for IAsyncAction {}
impl windows_core::RuntimeName for IAsyncAction {
const NAME: &'static str = "Windows.Foundation.IAsyncAction";
}
pub trait IAsyncAction_Impl: IAsyncInfo_Impl {
fn GetResults(&self) -> windows_core::Result<()>;
}
impl IAsyncAction_Vtbl {
pub const fn new<Identity: IAsyncAction_Impl, const OFFSET: isize>() -> Self {
unsafe extern "system" fn GetResults<Identity: IAsyncAction_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
IAsyncAction_Impl::GetResults(this).into()
}
Self {
base__: windows_core::IInspectable_Vtbl::new::<Identity, IAsyncAction, OFFSET>(),
put_Completed: 0,
get_Completed: 0,
GetResults: GetResults::<Identity, OFFSET>,
}
}
pub fn matches(iid: &windows_core::GUID) -> bool {
iid == &<IAsyncAction as windows_core::Interface>::IID
}
}
#[repr(C)]
pub struct IAsyncAction_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
put_Completed: usize,
get_Completed: usize,
pub GetResults: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT,
}
windows_core::imp::define_interface!(
IAsyncInfo,
IAsyncInfo_Vtbl,
0x00000036_0000_0000_c000_000000000046
);
impl windows_core::RuntimeType for IAsyncInfo {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
windows_core::imp::interface_hierarchy!(
IAsyncInfo,
windows_core::IUnknown,
windows_core::IInspectable
);
impl IAsyncInfo {
pub fn Id(&self) -> windows_core::Result<u32> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).Id)(
windows_core::Interface::as_raw(this),
&mut result__,
)
.map(|| result__)
}
}
pub fn ErrorCode(&self) -> windows_core::Result<windows_core::HRESULT> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).ErrorCode)(
windows_core::Interface::as_raw(this),
&mut result__,
)
.map(|| result__)
}
}
pub fn Cancel(&self) -> windows_core::Result<()> {
let this = self;
unsafe {
(windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this))
.ok()
}
}
pub fn Close(&self) -> windows_core::Result<()> {
let this = self;
unsafe {
(windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this))
.ok()
}
}
}
impl windows_core::RuntimeName for IAsyncInfo {
const NAME: &'static str = "Windows.Foundation.IAsyncInfo";
}
pub trait IAsyncInfo_Impl: windows_core::IUnknownImpl {
fn Id(&self) -> windows_core::Result<u32>;
fn ErrorCode(&self) -> windows_core::Result<windows_core::HRESULT>;
fn Cancel(&self) -> windows_core::Result<()>;
fn Close(&self) -> windows_core::Result<()>;
}
impl IAsyncInfo_Vtbl {
pub const fn new<Identity: IAsyncInfo_Impl, const OFFSET: isize>() -> Self {
unsafe extern "system" fn Id<Identity: IAsyncInfo_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
result__: *mut u32,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IAsyncInfo_Impl::Id(this) {
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
windows_core::HRESULT(0)
}
Err(err) => err.into(),
}
}
unsafe extern "system" fn ErrorCode<Identity: IAsyncInfo_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
result__: *mut windows_core::HRESULT,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IAsyncInfo_Impl::ErrorCode(this) {
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
windows_core::HRESULT(0)
}
Err(err) => err.into(),
}
}
unsafe extern "system" fn Cancel<Identity: IAsyncInfo_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
IAsyncInfo_Impl::Cancel(this).into()
}
unsafe extern "system" fn Close<Identity: IAsyncInfo_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
IAsyncInfo_Impl::Close(this).into()
}
Self {
base__: windows_core::IInspectable_Vtbl::new::<Identity, IAsyncInfo, OFFSET>(),
Id: Id::<Identity, OFFSET>,
get_Status: 0,
ErrorCode: ErrorCode::<Identity, OFFSET>,
Cancel: Cancel::<Identity, OFFSET>,
Close: Close::<Identity, OFFSET>,
}
}
pub fn matches(iid: &windows_core::GUID) -> bool {
iid == &<IAsyncInfo as windows_core::Interface>::IID
}
}
#[repr(C)]
pub struct IAsyncInfo_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub Id: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT,
get_Status: usize,
pub ErrorCode: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut windows_core::HRESULT,
) -> windows_core::HRESULT,
pub Cancel: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT,
pub Close: unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT,
}
Loading

0 comments on commit 8115db5

Please sign in to comment.