From a7e4ebdd72883601e8b70874e2bd4100471b08fb Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 31 Mar 2023 10:48:20 -0500 Subject: [PATCH 1/2] cfg --- crates/libs/bindgen/src/lib.rs | 53 ++++++++++++++++++++++++++++++++ crates/tests/standalone/build.rs | 5 --- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/crates/libs/bindgen/src/lib.rs b/crates/libs/bindgen/src/lib.rs index 1c9095e4ba..a175e96d2a 100644 --- a/crates/libs/bindgen/src/lib.rs +++ b/crates/libs/bindgen/src/lib.rs @@ -241,10 +241,63 @@ pub fn standalone(names: &[&str]) -> String { } }); + let mut type_names = BTreeSet::new(); + for name in names { let type_name = TypeName::parse(name); let mut found = false; + if let Some(def) = reader.get(type_name).next() { + found = true; + type_names.insert(type_name); + for def in reader.type_def_cfg(def, &[]).types.values().flatten() { + type_names.insert(reader.type_def_type_name(*def)); + } + } + + if !found { + if let Some(def) = reader + .get(TypeName::new(type_name.namespace, "Apis")) + .next() + { + for method in gen.reader.type_def_methods(def) { + if found { + break; + } + let name = gen.reader.method_def_name(method); + if name == type_name.name { + found = true; + type_names.insert(type_name); + for def in reader + .signature_cfg(&reader.method_def_signature(method, &[])) + .types + .values() + .flatten() + { + type_names.insert(reader.type_def_type_name(*def)); + } + } + } + for field in gen.reader.type_def_fields(def) { + if found { + break; + } + let name = gen.reader.field_name(field); + if name == type_name.name { + found = true; + type_names.insert(type_name); + for def in reader.field_cfg(field).types.values().flatten() { + type_names.insert(reader.type_def_type_name(*def)); + } + } + } + } + } + } + + for type_name in type_names { + let mut found = false; + for def in reader.get(type_name) { found = true; let kind = gen.reader.type_def_kind(def); diff --git a/crates/tests/standalone/build.rs b/crates/tests/standalone/build.rs index a18ebdc59d..3d94523c2d 100644 --- a/crates/tests/standalone/build.rs +++ b/crates/tests/standalone/build.rs @@ -1,11 +1,6 @@ fn main() { let apis = [ - "Windows.Win32.Foundation.BOOL", "Windows.Win32.Foundation.CloseHandle", - "Windows.Win32.Foundation.HANDLE", - "Windows.Win32.Foundation.WIN32_ERROR", - "Windows.Win32.Security.SECURITY_ATTRIBUTES", - "Windows.Win32.System.Com.CLSCTX", "Windows.Win32.System.Com.CoCreateInstance", "Windows.Win32.System.Com.STGTY_REPEAT", "Windows.Win32.System.Threading.CreateEventW", From e961f8da66d8c1375ba43b50cf2a5e087dc32733 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 31 Mar 2023 10:56:27 -0500 Subject: [PATCH 2/2] fmt --- crates/tests/standalone/build.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/tests/standalone/build.rs b/crates/tests/standalone/build.rs index 3d94523c2d..7c3936b3cb 100644 --- a/crates/tests/standalone/build.rs +++ b/crates/tests/standalone/build.rs @@ -1,13 +1,5 @@ fn main() { - let apis = [ - "Windows.Win32.Foundation.CloseHandle", - "Windows.Win32.System.Com.CoCreateInstance", - "Windows.Win32.System.Com.STGTY_REPEAT", - "Windows.Win32.System.Threading.CreateEventW", - "Windows.Win32.System.Threading.SetEvent", - "Windows.Win32.System.Threading.WaitForSingleObject", - "Windows.Win32.UI.Animation.UIAnimationManager", - ]; + let apis = ["Windows.Win32.Foundation.CloseHandle", "Windows.Win32.System.Com.CoCreateInstance", "Windows.Win32.System.Com.STGTY_REPEAT", "Windows.Win32.System.Threading.CreateEventW", "Windows.Win32.System.Threading.SetEvent", "Windows.Win32.System.Threading.WaitForSingleObject", "Windows.Win32.UI.Animation.UIAnimationManager"]; let bindings = windows_bindgen::standalone(&apis); std::fs::write("src/bindings.rs", bindings).unwrap();