Skip to content

[ffigen] feat: generate cpp class constructor bindings#3395

Merged
liamappelbe merged 2 commits into
dart-lang:mainfrom
Hassnaa9:generate-cpp-ctr-bindings
May 28, 2026
Merged

[ffigen] feat: generate cpp class constructor bindings#3395
liamappelbe merged 2 commits into
dart-lang:mainfrom
Hassnaa9:generate-cpp-ctr-bindings

Conversation

@Hassnaa9
Copy link
Copy Markdown
Contributor

No description provided.

@liamappelbe liamappelbe self-requested a review May 28, 2026 00:29
@github-actions
Copy link
Copy Markdown

Package publishing

Package Version Status Publish tag (post-merge)
package:code_assets 1.2.0 already published at pub.dev
package:data_assets 0.20.0 already published at pub.dev
package:ffi 2.2.0 already published at pub.dev
package:hooks 2.0.0 already published at pub.dev
package:hooks_runner 1.4.0 already published at pub.dev
package:jni_flutter 1.0.1 already published at pub.dev
package:native_toolchain_c 0.19.1 already published at pub.dev
package:record_use 0.6.1-wip WIP (no publish necessary)
package:swift2objc 0.2.0 already published at pub.dev
package:swiftgen 0.1.3 ready to publish swiftgen-v0.1.3

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.


final ctorInfos = [
for (var i = 0; i < constructors.length; i++)
(ctor: constructors[i], suffix: constructors.length == 1 ? '' : '_$i'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the existing Scope and Symbol infra for this? Change CppMethod.name to a Symbol, wire it up in the visitors etc, and set the base name of all the constructors to the glueName below (without the suffix, so I guess ${name}_new?)

p.name,
objCRetain: false,
objCAutorelease: false,
localVariables: LocalVariables(localScope),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructing LocalVariables inline like this means you're never actually writing the local variables it creates. I think once you start dealing with memory management stuff, you'll need to deal with LocalVariables properly, since safely unwrapping a pointer from a NativeFinalizer requires creating a temporary local variable.

Take a look at how other bindings generators deal with LocalVariables. You'll basically need to create one LocalVariables instance per method, do all your conversions (but don't write them to your bindings yet), then call LocalVariables.generateDeclarations() and write the string to your bindings, then write the conversion strings. Basically, the local variable declarations need to be written to the bindings before the conversions that use those local variables.

Example of writing LocalVariables to the bindings. Example showing how LocalVariables are being used for pointer unwrapping (you'll need to do this sort of thing when you start doing memory management). This bug and this one explain why this unwrapping step is needed, if you want to read more about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have tried to follow the links you mentioned; let me know if there are any other enhancements

@Hassnaa9 Hassnaa9 requested a review from liamappelbe May 28, 2026 02:50
@liamappelbe liamappelbe merged commit 14f4ce6 into dart-lang:main May 28, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants