Description
Build hooks and code assets support in Dart standalone is available in preview on the main channel. (In Dart 3.2 and later it was available behind an experimental flag: dart --enable-experiment=native-assets run [path/to/script.dart]
.)
Current ongoing work can be tracked in: Native Assets
This is a high level "feature" issue that we can refer to from various places.
The current way of bundling native code with Dart packages is far from ideal, we will introduce "Native Assets" to Dart.
Problem
As of right now, one can do one (or more) of the following:
- ship sources in a Dart standalone package and let users run a build by calling
dart run <your-package>/setup.dart
see webcrypto, or - make your
bin/setup.dart
download the native library, or - ship sources a flutter plugins with
flutter create --template=plugin_ffi --platform=...
, or - ship a script that downloads the native library during flutter build see realm_flutter.
This leads to pain for both package developers (options 1-4) and package users (option 1-2). Moreover, there is currently no way to make a package with native code that works both for flutter and Dart standalone.
High level solution
We introduce the concept of "Native Assets" to the Dart eco system.
A native asset is a native library (compiled from native source code).
Three components of the "Native Assets" solution in Dart:
- A standardized way to build or download native assets. This will be done by a CLI.
- A transparent way to find native symbols in these native assets in Dart.
- Integration with all the
dart
andflutter
tooling to link the above two together.
Try now
Native assets support in Dart standalone is available in Dart 3.2 behind an experimental flag : dart --enable-experiment=native-assets run [path/to/script.dart]
.
Native assets support in Flutter is in development. Progress can be tracked in flutter/flutter#129757.
An example on how to use native assets can be found here.
Checklist
- Basic Dart support: [vm/ffi] Native asset resolution by the Dart VM for
FfiNative
s #49803 - Flutter support: ☂️ Build hooks & Code assets flutter/flutter#129757
- Refine core support:
- [vm/ffi] Make
FfiNative
s more concise #50097 - Allow access to global variables in ffi static binding #50551
- Allow getting address of native symbols when using static ffi binding #50552
- [ffi] tree-shaking does not remove dependency .so library from the build #52970
- [vm/ffi] Explore using
FfiNative
for static linking #49418 - dart compile exe support static linking of C code #47718
- [vm/ffi]
FfiNative
return types treatment inconsistent withasFunction
#49518 - [native_assets][resource_identifiers] Deferred loading and assets #55809
- [native_assets] Support
dart pub global run
#56044 - [native_assets] Hot restart native libs #55850
- [vm/ffi] Make
- Graduate out from experiment flag (
--enable-experiment=native-assets
)