-
Notifications
You must be signed in to change notification settings - Fork 282
Look into use the new Dart / Flutter FFI under development #58
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'll keep this issue open as a reminder. |
i think that its a long way of btw. But still keep in mind long term i guess. |
They recently released an alpha preview for developers to test. |
Flutter Dart FFI has now landed in Master This means you can write Flutter Plugins in golang, and compile them as a shard lib as c. The opportunity is that go-flutter can be the go to place for golang programmers that want to use Flutter, and by embracing the Official Flutter Desktop using FFI we have no performance issues. But in the end the FFI means no speed slow downs and Same code for plugins everywhere, so its going to be the way forward. I think there are a few good libraries around to make it easy to take a golang lib and generate the golang code with the "import c" and the header lib. Gotta do some more research. I hope that this is welcomed and not seen as undermining the efforts here. LINKS: Official Example: https://github.com/dart-lang/sdk/blob/master/samples/ffi/sqlite/README.md Use golang shared libs with Dart FFI and flutter-desktop. Watching: https://github.com/asyncapi/parser/blob/master/cparser/cparser.go
FFI Forum: Mongo DB Realm using Dart FFI This would mean we can use Google Official Flutter Desktop, because the Desktop Plugins API can hook into the golang shared lib. Example of many languages hooking into golang shared lib. |
FFI looks very promising. Sadly I don't have the time to take an in-depth look into it now. If @gedw99 or anyone else is interested in FFI, please submit a PR, @GeertJohan, and I will be happy to review it! |
At first I want to say I'm new to go-flutter, but I know that the project exists for some time. If I understood it correctly it should be possible to compile the go plugins to shared libraries and use them using the new dart FFI? Then it would be possible to use them even with the "official" embedder right? I'm not sure why we need to compile the plugins for mobile, because almost all plugins are only for mobile yet and this project has the focus on desktop and it's plugins extend the existing plugins for mobile to desktop. |
@jld3103 as my last comment said, I have no idea how dart FFI works.
Yes I thinks it's right, but at the moment only C/C++ integration is possible. Just to clarify, plugin made to work on
Not sure if it's possible, but yes, from my understanding the I'm repeating myself, but, I have absolutely no plan to work on |
Some examples: https://github.com/mjohnsullivan/ffi |
First, from the following Cpp code: // filename: hello_world.cpp
#include<iostream>
#include<stdio.h>
extern "C" {
void helloWorld() {
std::cout<<"Hello World !"<<std::endl;
}
} I've compiled it: # mac (.dylib)
g++ -dynamiclib -o ./libHelloWorld.dylib ./hello_world.cpp
# Linux (.so) if Android, have to compile for arm64 or arm
g++ -shared -fPIC -o ./libHelloWorld.so ./hello_world.cpp
# windows (.dll) (using TDM-GCC-64, GCC 5.1.0)
g++ -shared -o HelloWorld.dll .\hello_world.cpp Secondly I've thrown the Lastly using the following import 'package:flutter/foundation.dart'
show debugDefaultTargetPlatformOverride;
import 'package:flutter/material.dart';
import "dart:ffi" as ffi;
import 'dart:io' show Platform;
import "package:path/path.dart" show join;
import 'dart:io';
ffi.DynamicLibrary _dlopenPlatformSpecific(String name, {String path}) {
String fullPath = _platformPath(name, path: path);
return ffi.DynamicLibrary.open(fullPath);
}
String _platformPath(String name, {String path = ''}) {
if (Platform.isMacOS) return path + "lib" + name + ".dylib";
if (Platform.isLinux || Platform.isAndroid)
return path + "lib" + name + ".so";
if (Platform.isWindows) return path + name + ".dll";
throw Exception("Platform not implemented");
}
void main() {
final libHelloWorld = _dlopenPlatformSpecific('HelloWorld',
path: join(
Directory(Platform.resolvedExecutable).parent.path,
'assets/',
));
final helloWorld = libHelloWorld
.lookupFunction<ffi.Void Function(), void Function()>("helloWorld");
helloWorld();
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
runApp(MaterialApp(home: Scaffold(body: Text("FFI!"))));
} I call the shared lib from a flutter app (
Putting the shared lib into the into the The path to the shared lib in dart |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@pchampio Your setup works fine for including dynamic libraries intended to be used with FFI. But, is there any way to include assets splitted by the platform? In your solution, .so, .dll, and .dylib will all be bundled with all platforms. Any workaround for that? |
If you are using a go-flutter plugin you can put the compiled library in the dlib folder (symlinks also work). Then run |
@pchampio maybe we should add an example for that? I already created such an project with ffi and would only need to modify minor things |
@davidmartos96 The project @jld3103 I'm still not fixed with how the plugin dlib folder work. |
@jld3103 Thanks for the response! Yes I tried using a plugin, but with my current project setup I think it won't work. I am placing custom plugins in a folder called go-plugins at the root of the git repo, so when fetching such local plugin with the dynamic libraries, it fails because it tries to fetch it from remote. Maybe that is a bug in the @pchampio Does that mean I can include the intermediates folder in my git repo? Or should it be ignored? |
@jld3103 I'm still not fixed with how the plugin dlib folder work. #311 @davidmartos96 yep, |
Please check #498 |
flutter/flutter#7053
Basically it will mean you can take your golang code and compile it to a shared lib for Mobile and Desktop.
Why its a feasible approach:
when ?
Q1 2019 they say.
The text was updated successfully, but these errors were encountered: