Skip to content

Commit

Permalink
Standalone code generation should collect pointer types (#2785)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Jan 10, 2024
1 parent 7c400dc commit bcd7d88
Show file tree
Hide file tree
Showing 4 changed files with 503 additions and 8 deletions.
13 changes: 5 additions & 8 deletions crates/libs/bindgen/src/rust/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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(&param.ty, set));
}
Expand All @@ -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);
}
}
}
6 changes: 6 additions & 0 deletions crates/tests/standalone/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
Loading

0 comments on commit bcd7d88

Please sign in to comment.