Skip to content

Commit

Permalink
Add VARIANT and PROPVARIANT support (#2786)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Jan 11, 2024
1 parent bcd7d88 commit e69e8e6
Show file tree
Hide file tree
Showing 176 changed files with 23,588 additions and 29,202 deletions.
1 change: 1 addition & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jobs:
cargo clippy -p test_sys &&
cargo clippy -p test_targets &&
cargo clippy -p test_unions &&
cargo clippy -p test_variant &&
cargo clippy -p test_wdk &&
cargo clippy -p test_weak &&
cargo clippy -p test_weak_ref &&
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ jobs:
cargo test -p test_enums &&
cargo test -p test_error &&
cargo test -p test_event &&
cargo clean &&
cargo test -p test_extensions &&
cargo clean &&
cargo test -p test_handles &&
cargo test -p test_helpers &&
cargo test -p test_implement &&
Expand Down Expand Up @@ -129,6 +129,7 @@ jobs:
cargo test -p test_sys &&
cargo test -p test_targets &&
cargo test -p test_unions &&
cargo test -p test_variant &&
cargo test -p test_wdk &&
cargo test -p test_weak &&
cargo test -p test_weak_ref &&
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 @@ -104,7 +104,7 @@ where
let output = canonicalize(output)?;

let input = read_input(&input)?;
let reader = metadata::Reader::filter(input, &include, &exclude);
let reader = metadata::Reader::filter(input, &include, &exclude, &config);

winmd::verify(reader)?;

Expand Down
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ fn method_def_last_error(row: MethodDef) -> bool {
pub fn type_is_borrowed(ty: &Type) -> bool {
match ty {
Type::TypeDef(row, _) => !type_def_is_blittable(*row),
Type::BSTR | Type::PCSTR | Type::PCWSTR | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => true,
Type::BSTR | Type::VARIANT | Type::PROPVARIANT | Type::PCSTR | Type::PCWSTR | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => true,
_ => false,
}
}
Expand Down Expand Up @@ -495,7 +495,7 @@ pub fn field_is_copyable(row: Field, enclosing: TypeDef) -> bool {
pub fn type_is_blittable(ty: &Type) -> bool {
match ty {
Type::TypeDef(row, _) => type_def_is_blittable(*row),
Type::String | Type::BSTR | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => false,
Type::String | Type::BSTR | Type::VARIANT | Type::PROPVARIANT | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => false,
Type::Win32Array(kind, _) => type_is_blittable(kind),
Type::WinrtArray(kind) => type_is_blittable(kind),
_ => true,
Expand All @@ -505,7 +505,7 @@ pub fn type_is_blittable(ty: &Type) -> bool {
fn type_is_copyable(ty: &Type) -> bool {
match ty {
Type::TypeDef(row, _) => type_def_is_copyable(*row),
Type::String | Type::BSTR | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => false,
Type::String | Type::BSTR | Type::VARIANT | Type::PROPVARIANT | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => false,
Type::Win32Array(kind, _) => type_is_copyable(kind),
Type::WinrtArray(kind) => type_is_copyable(kind),
_ => true,
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ fn namespace(writer: &Writer, tree: &Tree) -> String {
match item {
metadata::Item::Type(def) => {
let type_name = def.type_name();
if metadata::REMAP_TYPES.iter().any(|(x, _)| x == &type_name) {
if writer.reader.remap_types().any(|(x, _)| x == &type_name) {
continue;
}
if metadata::CORE_TYPES.iter().any(|(x, _)| x == &type_name) {
if writer.reader.core_types().any(|(x, _)| x == &type_name) {
continue;
}
let name = type_name.name;
Expand Down Expand Up @@ -241,7 +241,7 @@ fn namespace_impl(writer: &Writer, tree: &Tree) -> String {
for item in writer.reader.namespace_items(tree.namespace) {
if let metadata::Item::Type(def) = item {
let type_name = def.type_name();
if metadata::CORE_TYPES.iter().any(|(x, _)| x == &type_name) {
if writer.reader.core_types().any(|(x, _)| x == &type_name) {
continue;
}
if def.kind() != metadata::TypeKind::Interface {
Expand Down
14 changes: 14 additions & 0 deletions crates/libs/bindgen/src/rust/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ impl Writer {
let crate_name = self.crate_name();
quote! { #crate_name BSTR }
}
metadata::Type::VARIANT => {
let crate_name = self.crate_name();
quote! { #crate_name VARIANT }
}
metadata::Type::PROPVARIANT => {
let crate_name = self.crate_name();
quote! { #crate_name PROPVARIANT }
}
metadata::Type::IInspectable => {
let crate_name = self.crate_name();
quote! { #crate_name IInspectable }
Expand Down Expand Up @@ -198,6 +206,12 @@ impl Writer {
metadata::Type::BSTR => {
quote! { ::std::mem::MaybeUninit<::windows_core::BSTR> }
}
metadata::Type::VARIANT => {
quote! { ::std::mem::MaybeUninit<::windows_core::VARIANT> }
}
metadata::Type::PROPVARIANT => {
quote! { ::std::mem::MaybeUninit<::windows_core::PROPVARIANT> }
}
metadata::Type::Win32Array(kind, len) => {
let name = self.type_abi_name(kind);
let len = Literal::usize_unsuffixed(*len);
Expand Down
Loading

0 comments on commit e69e8e6

Please sign in to comment.