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

@Natives and @ResourceIdentifier #1085

Open
dcharkes opened this issue Apr 9, 2024 · 2 comments
Open

@Natives and @ResourceIdentifier #1085

dcharkes opened this issue Apr 9, 2024 · 2 comments

Comments

@dcharkes
Copy link
Collaborator

dcharkes commented Apr 9, 2024

We should consider making @Natives automatically be mapped to @ResourceIdentifiers.

@Natives have a symbol and assetId (both possibly inferred).
https://api.dart.dev/stable/3.3.3/dart-ffi/Native-class.html

@ResourceIdentifiers only have a Object? metadata.
https://pub.dev/documentation/meta/latest/meta/ResourceIdentifier/ResourceIdentifier.html

A possible mapping would be

@Native<>(assetId: 'foo', symbol: 'bar')

->

@ResourceIdentifier({
  'assetId': 'foo',
  'symbol': 'bar',
})

Alternatively, we can make FFIgen generate the resource identifier annotations. Are there any cases where we don't want the resource identifier information? Maybe if a package only supports dylibs, so tree shaking cannot be used anyways, then it should run FFIgen without adding the annotations.

(If we want to do the mapping automatically in the Dart SDK, we should move this issue there. If we want to generate the annotations in FFIgen, we should keep it here.)

cc @mosuem thoughts?

@mosuem
Copy link
Member

mosuem commented Apr 9, 2024

SGTM - I think I prefer using the approach of adding ResourceIdentifier in ffigen, it makes the process a bit more visible for an otherwise already very opaque feature. Also, it pollutes the resources.json file less.

@dcharkes
Copy link
Collaborator Author

dcharkes commented Apr 9, 2024

One slight issue is that the assetId might not entirely be obvious when generating.
So maybe assetId should be optional.

Something along the lines of:

# ffigen.yaml
native:
  assetId: package:my_package/src/bindings_generated.dart
  resource-identifers: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants