Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone code generation now includes dependencies automatically #2416

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 1 addition & 14 deletions crates/tests/standalone/build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
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",
"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();
Expand Down