-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Define distribution system for native libraries in Pub and/or Flutter #36712
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
Comments
I have done FFI wrappers for libsodium and was disappointed when I realised that just putting the dynamic library into the package doesn't work. I mean, it works locally inside sodium and it passes all tests. But it doesn't work when sodium is a dependency of another package because as it seems the dll has to be inside the same package as the executable. That of course defeats the purpose of dependency management. |
@MarvinHannott What platform/OS are you running on? |
@sjindel-google Windows. But I strongly assume that the same should be true for Linux. As far as I understand, it is because of the way the path to a dynamic library gets resolved. The path has to be static and Dart libraries don't have any information about their own location on the disk like Node.js scripts do. And that's why the programm will look at the environment it gets executed in. As for now I don't see any practical way to ship any kind of native dependencies. The user would have to manually manage the DLLs and nobody wants that. |
Most likely native dependencies will be managed by Flutter tools. On Android and iOS this means that native dependencies will be distributed via Gradle repos and Cocoa pods. The story for desktop platforms is till unclear though. |
@sjindel-google What I wouldn't like were something like node-gyp which only causes problems and is complicated. Ideally Dart libraries could be shipped with pre-compiled dynamic libraries for various platforms so that dependencies don't have to be build on the target device. |
Solved for Flutter via flutter/flutter#33227 We don't have a story for packaging native code inside Dart packages independently of Flutter yet, and we're not prioritizing it this year. See https://github.com/flutter/flutter/wiki/Binding-to-native-code-via-FFI /cc @mit-mit |
Anyone following or finding this issue looking for windows / linux support with flutter I eventually figured something out by looking at how objectbox does it: https://github.com/objectbox/objectbox-dart. It would be easier to have an official way of bundling libraries in dart itself so you don't have to create a plugin just to include the libraries, but I guess this is how we have to do it for now. |
@sjindel-google you mentioned that this is solved for Flutter, but is that still the case now that Flutter supports desktop? Eg. for Desktop Linux, if I have a Flutter plugin that makes use of a pure Dart package that provides a FFI binding to a C library (pre built binary, not compiled from src in the package or plugin), how should the Flutter plugin locate the C library? Ideally I'd like to bundle the library with the Flutter app for standalone distribution rather than relying on end-users to have it installed via system package managers. @dcharkes I saw on one of the linked issues to this one that you mentioned you were working on a solution for this, is that still in-progress? |
@TimWhiting I did something similar. It requires the libs to be built every time a flutter project uses them which to me is completely unnecessary and defeats the purpose of distribution. Does anyone know what pluginClass does and if it's unique? |
The pluginClass is picked up by the flutter build system and triggers it to include native code and to hook up method channels. For FFI, we don't need the method channels, but we do need the native code to be included. This is an open issue. |
We are working towards a solution, this is being tracked in: |
Update 2020-03-24:
For Flutter plugins we can package binaries with with Cocoapods or Gradle.
For stand alone Dart packages there are two options:
We would like a better solution, but this is the way to do it for now.
======================================
(Not reviving dart-lang/pub#39 because it contains little relevant context)
We need to define a distribution method in Pub, integrated with Flutter, which enables uses to create packages that depend on "native" libraries.
See go/dart-ffi-flutter-distribution for brainstorming on Flutter integration.
The text was updated successfully, but these errors were encountered: