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

Intention to deprecate and remove plugin_ffi template #131209

Open
3 tasks
dcharkes opened this issue Jul 24, 2023 · 0 comments
Open
3 tasks

Intention to deprecate and remove plugin_ffi template #131209

dcharkes opened this issue Jul 24, 2023 · 0 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter P2 Important issues not at the top of the work list team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team

Comments

@dcharkes
Copy link
Contributor

Removing plugin_ffi template

In the native assets we will create a way to bundle native code without the boilerplate code for every OS. Moreover, the packages with native assets will be regular Dart packages, removing the split between Dart packages and Flutter plugins with native code. (For example package:realm and package:realm_dart.)

Therefore, once we have support for native assets, the intention is to first deprecate and then remove the FFI plugin template.

Once native assets come out of experimental, we would mark the FFI plugin as deprecated, and subsequently remove it one or two Flutter versions later.

All the documentation and code labs that currently refer to FFI plugins need to be migrated in that time frame.

Potentially adding package_ffi template

Packages with native assets are much simpler than the FFI plugins due to having less boilerplate code (example). They are basically a

  1. dart package,
  2. with a pubspec.yaml dependency on https://pub.dev/packages/native_assets_cli and https://pub.dev/packages/native_toolchain_c,
  3. a toplevel build.dart doing the native build,
  4. an ffigen.yaml for the bindings, and
  5. a src/some_c_code.c with the native code.

It could suffice to have this in dart create, instead of adding a template to flutter create. However, the downside would be that dart create would not have a flutter sample app invoking the native code. And this sample app working out of the box means that our users know the building/bundling works for the target OS/arch they are working on.

It could suffice to have this as a sample (both a package with native assets as well as an example app using it), instead of flutter create. The downside over a template would be that changing the name from the sample is error prone. (And checking out the sample with git clone is more work than running flutter create.)

The extra steps that users have to do also have to be duplicated in our documentation and code lab.

Since we are intending to remove flutter create -t plugin_ffi, maybe we should consider whether we should add flutter create -t package_ffi.

Context:

cc @stuartmorgan @vashworth @zanderso

@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team c: new feature Nothing broken; request for a new capability tool Affects the "flutter" command-line tool. See also t: labels. c: proposal A detailed proposal for a change to Flutter team-tool Owned by Flutter Tool team and removed in triage Presently being triaged by the triage team labels Jul 25, 2023
@christopherfujino christopherfujino added P2 Important issues not at the top of the work list triaged-tool Triaged by Flutter Tool team labels Jul 25, 2023
auto-submit bot pushed a commit that referenced this issue Sep 10, 2023
Support for FFI calls with `@Native external` functions through Native assets on MacOS and iOS. This enables bundling native code without any build-system boilerplate code.

For more info see:

* #129757

### Implementation details for MacOS and iOS.

Dylibs are bundled by (1) making them fat binaries if multiple architectures are targeted, (2) code signing these, and (3) copying them to the frameworks folder. These steps are done manual rather than via CocoaPods. CocoaPods would have done the same steps, but (a) needs the dylibs to be there before the `xcodebuild` invocation (we could trick it, by having a minimal dylib in the place and replace it during the build process, that works), and (b) can't deal with having no dylibs to be bundled (we'd have to bundle a dummy dylib or include some dummy C code in the build file).

The dylibs are build as a new target inside flutter assemble, as that is the moment we know what build-mode and architecture to target.

The mapping from asset id to dylib-path is passed in to every kernel compilation path. The interesting case is hot-restart where the initial kernel file is compiled by the "inner" flutter assemble, while after hot restart the "outer" flutter run compiled kernel file is pushed to the device. Both kernel files need to contain the mapping. The "inner" flutter assemble gets its mapping from the NativeAssets target which builds the native assets. The "outer" flutter run get its mapping from a dry-run invocation. Since this hot restart can be used for multiple target devices (`flutter run -d all`) it contains the mapping for all known targets.

### Example vs template

The PR includes a new template that uses the new native assets in a package and has an app importing that. Separate discussion in: #131209.

### Tests

This PR adds new tests to cover the various use cases.

* dev/devicelab/bin/tasks/native_assets_ios.dart
  * Runs an example app with native assets in all build modes, doing hot reload and hot restart in debug mode.
* dev/devicelab/bin/tasks/native_assets_ios_simulator.dart
  * Runs an example app with native assets, doing hot reload and hot restart.
* packages/flutter_tools/test/integration.shard/native_assets_test.dart
  * Runs (incl hot reload/hot restart), builds, builds frameworks for iOS, MacOS and flutter-tester.
* packages/flutter_tools/test/general.shard/build_system/targets/native_assets_test.dart
  * Unit tests the new Target in the backend.
* packages/flutter_tools/test/general.shard/ios/native_assets_test.dart
* packages/flutter_tools/test/general.shard/macos/native_assets_test.dart
  * Unit tests the native assets being packaged on a iOS/MacOS build.

It also extends various existing tests:

* dev/devicelab/bin/tasks/module_test_ios.dart
   * Exercises the add2app scenario.
* packages/flutter_tools/test/general.shard/features_test.dart
   * Unit test the new feature flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter P2 Important issues not at the top of the work list team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team
Projects
None yet
Development

No branches or pull requests

3 participants