Closed maks closed 2 years ago
@mit-mit - do we have a standard place where we track template work/requests?
Here's fine, cc @dcharkes
Yes we'd very much like to do this.
Even more so, we'd like to have a template that both works for Flutter and Dart. Instead of duplicating packages for the Dart and Flutter eco systems (e.g. https://pub.dev/packages/realm_dart https://pub.dev/packages/realm).
We will have a flutter create --template plugin_ffi
for the Flutter side starting from the next version of Flutter.
In Flutter land we can always build the native code with the native compilers required by the Flutter toolchain.
@maks how do your packages work? Do you ship the native libraries with them? Do you expect the dll/so/dylib to be available on PATH
?
nit:
analyzer: exclude: - "lib/src/libgit2_generated_bindings.dart"
I'd suggest generating lint ignores within the file instead using the preamble
.
That's awesome news @dcharkes ! 🎉
Currently I just document that users need to have the native library installed, as I remember seeing somewhere (on dart.dev ?) and I think in some issue comments here as well that it's recommended by the Dart team that dev's not ship binaries inside Dart packages on pub.dev. Is that still the case?
And thank you for that tip, I had completely missed the preamble
config property, so I guess I want to use it to add // ignore_for_file: type=lint
?
And thank you for that tip, I had completely missed the
preamble
config property, so I guess I want to use it to add// ignore_for_file: type=lint
?
I'd list the specific lints, so that the rest is checked. For example:
Is that still the case?
At some point we need a solution for the binaries. Because when packages transitively start depending on each other, it becomes hard to figure which native libraries a user has to install. We might settle on a bin/setup.dart
that would either build or download the native dependencies with a standardized command line interface so that we can run it for all packages which have native dependencies in a project.
And thank you for that tip, I had completely missed the
preamble
config property, so I guess I want to use it to add// ignore_for_file: type=lint
?I'd list the specific lints, so that the rest is checked. For example:
- https://github.com/google/webcrypto.dart/blob/master/lib/src/third_party/boringssl/ffigen.yaml#L261-L264
- https://github.com/google/webcrypto.dart/blob/master/lib/src/third_party/boringssl/generated_bindings.dart#L52-L55
Is that still the case?
At some point we need a solution for the binaries. Because when packages transitively start depending on each other, it becomes hard to figure which native libraries a user has to install. We might settle on a
bin/setup.dart
that would either build or download the native dependencies with a standardized command line interface so that we can run it for all packages which have native dependencies in a project.
Yes,this is great. It would be great for packages that do need to compile some extra code for the lack of asynchronous callbacks on Dart, and for the lack of file descriptors to RawSockets, et all.
@dcharkes even though it was done for Flutter, I think https://github.com/flutter/flutter/pull/96225 pretty much addresses what I was asking for when I opened this issue, so I think it can be closed now that the plugin_ffi
template is available in Flutter.
I have found myself making FFI wrapper packages quite a lot lately.
So I have been some repetitive steps setting up each package with a few common steps to set up FFI on top of the
package-simple
template, so it would be nice to have this as a template as I suspect that this is becoming a more common use case for Dart packages as FFI has matured into a very useful feature. I think this would also be a good opportunity to provide developers with FFI "best practises" in the template.Some of the things that I do pretty consistently for all new FFI package projects are:
ffigen
dev dependency and a basic ffigen config in pubspec.yaml, eg.Create a wrapper file that calls the generated code, eg:
Create example file with a main calling the above:
Having a template to do all the above would be nice.
Above examples are from one of my recently started FFI binding packages but of course you can see my cargo-culting the above sort of recipe on several other FFI wrapper packages I have made.