From 1c788648ad51caa1e1a637f94bbf68db4578a5f3 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 10 Jan 2024 07:34:50 -0600 Subject: [PATCH] depends --- crates/libs/bindgen/src/rust/standalone.rs | 13 +- crates/tests/standalone/build.rs | 6 + crates/tests/standalone/src/b_variant.rs | 490 +++++++++++++++++++++ crates/tests/standalone/src/lib.rs | 2 + 4 files changed, 503 insertions(+), 8 deletions(-) create mode 100644 crates/tests/standalone/src/b_variant.rs diff --git a/crates/libs/bindgen/src/rust/standalone.rs b/crates/libs/bindgen/src/rust/standalone.rs index 21daa55180..90820ba575 100644 --- a/crates/libs/bindgen/src/rust/standalone.rs +++ b/crates/libs/bindgen/src/rust/standalone.rs @@ -145,12 +145,10 @@ fn type_collect_standalone(ty: &metadata::Type, set: &mut std::collections::BTre return; } - let metadata::Type::TypeDef(def, generics) = &ty else { + let metadata::Type::TypeDef(def, generics) = ty.to_underlying_type() else { return; }; - let def = *def; - // Ensure that we collect all the typedefs of the same name. We need to // do this in the case where the user specifies a top level item that // references a typedef by name, but that name resolves to more than 1 @@ -167,7 +165,7 @@ fn type_collect_standalone(ty: &metadata::Type, set: &mut std::collections::BTre } } - for generic in generics { + for generic in &generics { type_collect_standalone(generic, set); } for field in def.fields() { @@ -184,7 +182,7 @@ fn type_collect_standalone(ty: &metadata::Type, set: &mut std::collections::BTre if method.name() == ".ctor" { continue; } - let signature = metadata::method_def_signature(def.namespace(), method, generics); + let signature = metadata::method_def_signature(def.namespace(), method, &generics); type_collect_standalone(&signature.return_type, set); signature.params.iter().for_each(|param| type_collect_standalone(¶m.ty, set)); } @@ -204,15 +202,14 @@ fn type_collect_standalone_nested(td: metadata::TypeDef, set: &mut std::collecti for field in nested.fields() { let ty = field.ty(Some(nested)); - if let metadata::Type::TypeDef(def, _) = &ty { + if let metadata::Type::TypeDef(def, _) = ty.to_underlying_type() { // Skip the fields that actually refer to the anonymous nested // type, otherwise it will get added to the typeset and emitted if def.namespace().is_empty() { continue; } - - type_collect_standalone(&ty, set); } + type_collect_standalone(&ty, set); } } } diff --git a/crates/tests/standalone/build.rs b/crates/tests/standalone/build.rs index 9ed95c152a..ba1b452a67 100644 --- a/crates/tests/standalone/build.rs +++ b/crates/tests/standalone/build.rs @@ -142,6 +142,12 @@ fn main() { "src/b_include_me.rs", &["Windows.Win32.System.SystemInformation.GetVersion"], ); + + // Ensure that contained types behind pointers are resolved as dependencies. + write_sys( + "src/b_variant.rs", + &["Windows.Win32.System.Variant.VARIANT"], + ); } fn write_sys(output: &str, filter: &[&str]) { diff --git a/crates/tests/standalone/src/b_variant.rs b/crates/tests/standalone/src/b_variant.rs new file mode 100644 index 0000000000..9a541965d7 --- /dev/null +++ b/crates/tests/standalone/src/b_variant.rs @@ -0,0 +1,490 @@ +// Bindings generated by `windows-bindgen` 0.52.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] +pub type ADVANCED_FEATURE_FLAGS = u16; +#[repr(C)] +pub struct ARRAYDESC { + pub tdescElem: TYPEDESC, + pub cDims: u16, + pub rgbounds: [SAFEARRAYBOUND; 1], +} +impl ::core::marker::Copy for ARRAYDESC {} +impl ::core::clone::Clone for ARRAYDESC { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union BINDPTR { + pub lpfuncdesc: *mut FUNCDESC, + pub lpvardesc: *mut VARDESC, + pub lptcomp: ITypeComp, +} +impl ::core::marker::Copy for BINDPTR {} +impl ::core::clone::Clone for BINDPTR { + fn clone(&self) -> Self { + *self + } +} +pub type BOOL = i32; +pub type BSTR = *const u16; +pub type CALLCONV = i32; +#[repr(C)] +pub union CY { + pub Anonymous: CY_0, + pub int64: i64, +} +impl ::core::marker::Copy for CY {} +impl ::core::clone::Clone for CY { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct CY_0 { + pub Lo: u32, + pub Hi: i32, +} +impl ::core::marker::Copy for CY_0 {} +impl ::core::clone::Clone for CY_0 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct DECIMAL { + pub wReserved: u16, + pub Anonymous1: DECIMAL_0, + pub Hi32: u32, + pub Anonymous2: DECIMAL_1, +} +impl ::core::marker::Copy for DECIMAL {} +impl ::core::clone::Clone for DECIMAL { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union DECIMAL_0 { + pub Anonymous: DECIMAL_0_0, + pub signscale: u16, +} +impl ::core::marker::Copy for DECIMAL_0 {} +impl ::core::clone::Clone for DECIMAL_0 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct DECIMAL_0_0 { + pub scale: u8, + pub sign: u8, +} +impl ::core::marker::Copy for DECIMAL_0_0 {} +impl ::core::clone::Clone for DECIMAL_0_0 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union DECIMAL_1 { + pub Anonymous: DECIMAL_1_0, + pub Lo64: u64, +} +impl ::core::marker::Copy for DECIMAL_1 {} +impl ::core::clone::Clone for DECIMAL_1 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct DECIMAL_1_0 { + pub Lo32: u32, + pub Mid32: u32, +} +impl ::core::marker::Copy for DECIMAL_1_0 {} +impl ::core::clone::Clone for DECIMAL_1_0 { + fn clone(&self) -> Self { + *self + } +} +pub type DESCKIND = i32; +pub type DISPATCH_FLAGS = u16; +#[repr(C)] +pub struct DISPPARAMS { + pub rgvarg: *mut VARIANT, + pub rgdispidNamedArgs: *mut i32, + pub cArgs: u32, + pub cNamedArgs: u32, +} +impl ::core::marker::Copy for DISPPARAMS {} +impl ::core::clone::Clone for DISPPARAMS { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct ELEMDESC { + pub tdesc: TYPEDESC, + pub Anonymous: ELEMDESC_0, +} +impl ::core::marker::Copy for ELEMDESC {} +impl ::core::clone::Clone for ELEMDESC { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union ELEMDESC_0 { + pub idldesc: IDLDESC, + pub paramdesc: PARAMDESC, +} +impl ::core::marker::Copy for ELEMDESC_0 {} +impl ::core::clone::Clone for ELEMDESC_0 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct EXCEPINFO { + pub wCode: u16, + pub wReserved: u16, + pub bstrSource: BSTR, + pub bstrDescription: BSTR, + pub bstrHelpFile: BSTR, + pub dwHelpContext: u32, + pub pvReserved: *mut ::core::ffi::c_void, + pub pfnDeferredFillIn: LPEXCEPFINO_DEFERRED_FILLIN, + pub scode: i32, +} +impl ::core::marker::Copy for EXCEPINFO {} +impl ::core::clone::Clone for EXCEPINFO { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct FUNCDESC { + pub memid: i32, + pub lprgscode: *mut i32, + pub lprgelemdescParam: *mut ELEMDESC, + pub funckind: FUNCKIND, + pub invkind: INVOKEKIND, + pub callconv: CALLCONV, + pub cParams: i16, + pub cParamsOpt: i16, + pub oVft: i16, + pub cScodes: i16, + pub elemdescFunc: ELEMDESC, + pub wFuncFlags: FUNCFLAGS, +} +impl ::core::marker::Copy for FUNCDESC {} +impl ::core::clone::Clone for FUNCDESC { + fn clone(&self) -> Self { + *self + } +} +pub type FUNCFLAGS = u16; +pub type FUNCKIND = i32; +#[repr(C)] +pub struct GUID { + pub data1: u32, + pub data2: u16, + pub data3: u16, + pub data4: [u8; 8], +} +impl ::core::marker::Copy for GUID {} +impl ::core::clone::Clone for GUID { + fn clone(&self) -> Self { + *self + } +} +impl GUID { + pub const fn from_u128(uuid: u128) -> Self { + Self { + data1: (uuid >> 96) as u32, + data2: (uuid >> 80 & 0xffff) as u16, + data3: (uuid >> 64 & 0xffff) as u16, + data4: (uuid as u64).to_be_bytes(), + } + } +} +pub type HRESULT = i32; +#[repr(C)] +pub struct IDLDESC { + pub dwReserved: usize, + pub wIDLFlags: IDLFLAGS, +} +impl ::core::marker::Copy for IDLDESC {} +impl ::core::clone::Clone for IDLDESC { + fn clone(&self) -> Self { + *self + } +} +pub type IDLFLAGS = u16; +pub type IDispatch = *mut ::core::ffi::c_void; +pub type IMPLTYPEFLAGS = i32; +pub type INVOKEKIND = i32; +pub type IRecordInfo = *mut ::core::ffi::c_void; +pub type ITypeComp = *mut ::core::ffi::c_void; +pub type ITypeInfo = *mut ::core::ffi::c_void; +pub type ITypeLib = *mut ::core::ffi::c_void; +pub type IUnknown = *mut ::core::ffi::c_void; +pub type LPEXCEPFINO_DEFERRED_FILLIN = + ::core::option::Option HRESULT>; +#[repr(C)] +pub struct PARAMDESC { + pub pparamdescex: *mut PARAMDESCEX, + pub wParamFlags: PARAMFLAGS, +} +impl ::core::marker::Copy for PARAMDESC {} +impl ::core::clone::Clone for PARAMDESC { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct PARAMDESCEX { + pub cBytes: u32, + pub varDefaultValue: VARIANT, +} +impl ::core::marker::Copy for PARAMDESCEX {} +impl ::core::clone::Clone for PARAMDESCEX { + fn clone(&self) -> Self { + *self + } +} +pub type PARAMFLAGS = u16; +pub type PCWSTR = *const u16; +pub type PSTR = *mut u8; +pub type PWSTR = *mut u16; +#[repr(C)] +pub struct SAFEARRAY { + pub cDims: u16, + pub fFeatures: ADVANCED_FEATURE_FLAGS, + pub cbElements: u32, + pub cLocks: u32, + pub pvData: *mut ::core::ffi::c_void, + pub rgsabound: [SAFEARRAYBOUND; 1], +} +impl ::core::marker::Copy for SAFEARRAY {} +impl ::core::clone::Clone for SAFEARRAY { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct SAFEARRAYBOUND { + pub cElements: u32, + pub lLbound: i32, +} +impl ::core::marker::Copy for SAFEARRAYBOUND {} +impl ::core::clone::Clone for SAFEARRAYBOUND { + fn clone(&self) -> Self { + *self + } +} +pub type SYSKIND = i32; +#[repr(C)] +pub struct TLIBATTR { + pub guid: GUID, + pub lcid: u32, + pub syskind: SYSKIND, + pub wMajorVerNum: u16, + pub wMinorVerNum: u16, + pub wLibFlags: u16, +} +impl ::core::marker::Copy for TLIBATTR {} +impl ::core::clone::Clone for TLIBATTR { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct TYPEATTR { + pub guid: GUID, + pub lcid: u32, + pub dwReserved: u32, + pub memidConstructor: i32, + pub memidDestructor: i32, + pub lpstrSchema: PWSTR, + pub cbSizeInstance: u32, + pub typekind: TYPEKIND, + pub cFuncs: u16, + pub cVars: u16, + pub cImplTypes: u16, + pub cbSizeVft: u16, + pub cbAlignment: u16, + pub wTypeFlags: u16, + pub wMajorVerNum: u16, + pub wMinorVerNum: u16, + pub tdescAlias: TYPEDESC, + pub idldescType: IDLDESC, +} +impl ::core::marker::Copy for TYPEATTR {} +impl ::core::clone::Clone for TYPEATTR { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct TYPEDESC { + pub Anonymous: TYPEDESC_0, + pub vt: VARENUM, +} +impl ::core::marker::Copy for TYPEDESC {} +impl ::core::clone::Clone for TYPEDESC { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union TYPEDESC_0 { + pub lptdesc: *mut TYPEDESC, + pub lpadesc: *mut ARRAYDESC, + pub hreftype: u32, +} +impl ::core::marker::Copy for TYPEDESC_0 {} +impl ::core::clone::Clone for TYPEDESC_0 { + fn clone(&self) -> Self { + *self + } +} +pub type TYPEKIND = i32; +#[repr(C)] +pub struct VARDESC { + pub memid: i32, + pub lpstrSchema: PWSTR, + pub Anonymous: VARDESC_0, + pub elemdescVar: ELEMDESC, + pub wVarFlags: VARFLAGS, + pub varkind: VARKIND, +} +impl ::core::marker::Copy for VARDESC {} +impl ::core::clone::Clone for VARDESC { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union VARDESC_0 { + pub oInst: u32, + pub lpvarValue: *mut VARIANT, +} +impl ::core::marker::Copy for VARDESC_0 {} +impl ::core::clone::Clone for VARDESC_0 { + fn clone(&self) -> Self { + *self + } +} +pub type VARENUM = u16; +pub type VARFLAGS = u16; +#[repr(C)] +pub struct VARIANT { + pub Anonymous: VARIANT_0, +} +impl ::core::marker::Copy for VARIANT {} +impl ::core::clone::Clone for VARIANT { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union VARIANT_0 { + pub Anonymous: VARIANT_0_0, + pub decVal: DECIMAL, +} +impl ::core::marker::Copy for VARIANT_0 {} +impl ::core::clone::Clone for VARIANT_0 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct VARIANT_0_0 { + pub vt: VARENUM, + pub wReserved1: u16, + pub wReserved2: u16, + pub wReserved3: u16, + pub Anonymous: VARIANT_0_0_0, +} +impl ::core::marker::Copy for VARIANT_0_0 {} +impl ::core::clone::Clone for VARIANT_0_0 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub union VARIANT_0_0_0 { + pub llVal: i64, + pub lVal: i32, + pub bVal: u8, + pub iVal: i16, + pub fltVal: f32, + pub dblVal: f64, + pub boolVal: VARIANT_BOOL, + pub __OBSOLETE__VARIANT_BOOL: VARIANT_BOOL, + pub scode: i32, + pub cyVal: CY, + pub date: f64, + pub bstrVal: BSTR, + pub punkVal: IUnknown, + pub pdispVal: IDispatch, + pub parray: *mut SAFEARRAY, + pub pbVal: *mut u8, + pub piVal: *mut i16, + pub plVal: *mut i32, + pub pllVal: *mut i64, + pub pfltVal: *mut f32, + pub pdblVal: *mut f64, + pub pboolVal: *mut VARIANT_BOOL, + pub __OBSOLETE__VARIANT_PBOOL: *mut VARIANT_BOOL, + pub pscode: *mut i32, + pub pcyVal: *mut CY, + pub pdate: *mut f64, + pub pbstrVal: *mut BSTR, + pub ppunkVal: *mut IUnknown, + pub ppdispVal: *mut IDispatch, + pub pparray: *mut *mut SAFEARRAY, + pub pvarVal: *mut VARIANT, + pub byref: *mut ::core::ffi::c_void, + pub cVal: i8, + pub uiVal: u16, + pub ulVal: u32, + pub ullVal: u64, + pub intVal: i32, + pub uintVal: u32, + pub pdecVal: *mut DECIMAL, + pub pcVal: PSTR, + pub puiVal: *mut u16, + pub pulVal: *mut u32, + pub pullVal: *mut u64, + pub pintVal: *mut i32, + pub puintVal: *mut u32, + pub Anonymous: VARIANT_0_0_0_0, +} +impl ::core::marker::Copy for VARIANT_0_0_0 {} +impl ::core::clone::Clone for VARIANT_0_0_0 { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +pub struct VARIANT_0_0_0_0 { + pub pvRecord: *mut ::core::ffi::c_void, + pub pRecInfo: IRecordInfo, +} +impl ::core::marker::Copy for VARIANT_0_0_0_0 {} +impl ::core::clone::Clone for VARIANT_0_0_0_0 { + fn clone(&self) -> Self { + *self + } +} +pub type VARIANT_BOOL = i16; +pub type VARKIND = i32; diff --git a/crates/tests/standalone/src/lib.rs b/crates/tests/standalone/src/lib.rs index dbe58b79ab..5ad4018b0c 100644 --- a/crates/tests/standalone/src/lib.rs +++ b/crates/tests/standalone/src/lib.rs @@ -25,7 +25,9 @@ mod b_stringable; mod b_test; mod b_unknown; mod b_uri; +mod b_variant; mod b_win_enumerator; + #[allow(non_snake_case)] mod included { include!("b_include_me.rs");