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

Define distribution system for native libraries in Pub and/or Flutter #36712

Closed
sjindel-google opened this issue Apr 23, 2019 · 11 comments
Closed
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-ffi

Comments

@sjindel-google
Copy link
Contributor

sjindel-google commented Apr 23, 2019

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:

  1. Check in the C/C++ source and provide (preferably cross-platform) build instructions. This is how our samples work.
  2. Check in pre-built binaries to pub for the supported platforms. For example the tflite_native package.

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.

@sjindel-google sjindel-google added area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-ffi labels Apr 23, 2019
@sjindel-google sjindel-google added this to 1.0 in Dart VM FFI via automation Apr 23, 2019
@sjindel-google sjindel-google self-assigned this Jun 11, 2019
@MarvinHannott
Copy link

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.

@sjindel-google
Copy link
Contributor Author

@MarvinHannott What platform/OS are you running on?

@MarvinHannott
Copy link

@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.

@sjindel-google
Copy link
Contributor Author

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.

@MarvinHannott
Copy link

@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.

@sjindel-google
Copy link
Contributor Author

sjindel-google commented Aug 23, 2019

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

@TimWhiting
Copy link

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.

@maks
Copy link

maks commented Oct 25, 2021

@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?

@Clashkid155
Copy link

Clashkid155 commented Oct 27, 2021

@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.
Just developed and published my first plugin and you can imagine the shock i had when it didn't compile in my flutter app.
Now I've to tweak Cmake which I'm not good at and it keeps failing.

Does anyone know what pluginClass does and if it's unique?
linux:
- pluginClass

@dcharkes
Copy link
Contributor

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.

@dcharkes
Copy link
Contributor

We are working towards a solution, this is being tracked in:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-ffi
Projects
None yet
Development

No branches or pull requests

6 participants