From 21785dba6f6ddee67f75bdd8f8287802d505aba5 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Fri, 12 May 2023 18:07:07 +0200 Subject: [PATCH] Fix constant type collection (#2505) --- crates/libs/bindgen/src/standalone.rs | 6 ++++-- crates/tests/standalone/build.rs | 9 +++++++++ crates/tests/standalone/src/b_constant_types.rs | 13 +++++++++++++ crates/tests/standalone/src/lib.rs | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 crates/tests/standalone/src/b_constant_types.rs diff --git a/crates/libs/bindgen/src/standalone.rs b/crates/libs/bindgen/src/standalone.rs index 7fc44efeaa..161db4fdd6 100644 --- a/crates/libs/bindgen/src/standalone.rs +++ b/crates/libs/bindgen/src/standalone.rs @@ -67,8 +67,10 @@ fn standalone_imp(gen: &mut Gen, names: &[&str]) -> String { .find(|field| gen.reader.field_name(*field) == type_name.name) { constants.insert(field); - gen.reader - .type_collect_standalone(&gen.reader.field_type(field, None), &mut types); + gen.reader.type_collect_standalone( + &gen.reader.field_type(field, None).to_const_type(), + &mut types, + ); } if let Some(field) = gen diff --git a/crates/tests/standalone/build.rs b/crates/tests/standalone/build.rs index e41a6c80ad..762f337b9b 100644 --- a/crates/tests/standalone/build.rs +++ b/crates/tests/standalone/build.rs @@ -127,6 +127,15 @@ fn main() { "src/b_overloads.rs", &["Windows.Win32.NetworkManagement.NetManagement.AE_RESACCESS"], ); + + // Ensures that constant types are properly collected + write_sys( + "src/b_constant_types.rs", + &[ + "Windows.Win32.UI.WindowsAndMessaging.IDC_UPARROW", + "Windows.Win32.Security.Cryptography.CMC_ADD_ATTRIBUTES", + ], + ); } fn write_sys(filename: &str, apis: &[&str]) { diff --git a/crates/tests/standalone/src/b_constant_types.rs b/crates/tests/standalone/src/b_constant_types.rs new file mode 100644 index 0000000000..bf1174f86e --- /dev/null +++ b/crates/tests/standalone/src/b_constant_types.rs @@ -0,0 +1,13 @@ +// Bindings generated by `windows-bindgen` 0.49.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] +pub const CMC_ADD_ATTRIBUTES: PCSTR = 63i32 as _; +pub const IDC_UPARROW: PCWSTR = 32516u16 as _; +pub type PCSTR = *const u8; +pub type PCWSTR = *const u16; diff --git a/crates/tests/standalone/src/lib.rs b/crates/tests/standalone/src/lib.rs index f0ad750ea7..90c9d4e1a3 100644 --- a/crates/tests/standalone/src/lib.rs +++ b/crates/tests/standalone/src/lib.rs @@ -5,6 +5,7 @@ mod b_arch; mod b_arch_dependencies; mod b_bstr; mod b_calendar; +mod b_constant_types; mod b_depends; mod b_enumeration; mod b_enumerator;