[ffigen] Add API availability propagation and block trampoline annotations#3141
[ffigen] Add API availability propagation and block trampoline annotations#3141sagar-h007 wants to merge 1 commit intodart-lang:mainfrom
Conversation
PR HealthLicense Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
This check can be disabled by tagging the PR with 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.
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with |
liamappelbe
left a comment
There was a problem hiding this comment.
Overall this looks pretty good, but it needs tests. Try writing ObjC blocks that contain each of the types you've added a non-trivial computeAvailability method to. You'll need to create a new test similar to pkgs/ffigen/test/native_objc_test/transitive_test.dart. That is, unlike most of the tests in the pkgs/ffigen/test/native_objc_test, this is one of the ones that doesn't actually need to run the native code. Instead you'll be generating the native bindings, and checking that the generated .m file contains the expected availability annotations.
The PR also needs a changelog entry
| } | ||
|
|
||
| return PlatformAvailability( | ||
| name: a.name ?? b.name, |
There was a problem hiding this comment.
assert(a.name == b.name)
| final PlatformAvailability? macos; | ||
|
|
||
| late final Availability availability; | ||
| final ExternalVersions? _externalVersions; |
There was a problem hiding this comment.
externalVersions comes from the config, which is stored in the context. Rather than storing it here, you should pass Context to the merge method and get it from there. It will mean a bit more plumbing, but it's a cleaner solution.
Fixes #2942
This PR improves FFIgen’s Objective-C generation by correctly propagating API availability information and emitting attribute((availability(...))) annotations on generated block trampolines.
Previously, block trampolines didn’t carry availability constraints, which could lead to build warnings or errors when APIs restricted to newer OS versions appeared inside block signatures. This change ensures generated bindings reflect the correct platform availability.
What changed
Availability merging
Availability propagation through types
Block trampoline annotations
PR Checklist
dart tool/ci.dart --alllocally and resolved all issues identified. This ensures the PR is formatted, has no lint errors, and ran all code generators. This applies to the packages part of the toplevelpubspec.yamlworkspace.CHANGELOG.mdfor the relevant packages. (Not needed for small changes such as doc typos).