Description
When developers have native code that lends itself to compilation to WASM, this native code could be used in Dart Web through JS interop.
However, we do not have a unified API for interacting with the same native library on Dart Native through dart:ffi
, and on Dart Web through JS interop.
We envision such native libraries to be used in the following way:
Compile to WASM only for Dart Web, and keep using C dynamic libraries for Dart Native:
- Dart Web: Dart <-
JS interop
-> JS <-> WASM - Dart Native: Dart <-
dart:ffi
-> C (package:ffigen
can auto-generate bindings)
First, it would convenient if we would have a code generator that would generate the JS interop bindings for a package compiled to WASM.
Second, it would be convenient if we had some kind of unified API that could both target dart:ffi
's types and the generated WASM bindings, if it would be at all possible to have a unified API. The language runtimes of C and Assembly are different, so it might not fully be possible. So this requires exploration.
(An alternative approach would be to also combine the C libraries to WASM for Dart Native:
- Dart Web: Dart <-
JS interop
-> JS <-> WASM - Dart Native: Dart <-
package:wasm
-> WASM (package:wasm
internally does: Dart <-dart:ffi
-> C <-Wasmer runtime
-> WASM.)
The downsides of this approach is having to ship a WASM runtime such as Wasmer with the Dart Native apps, and it might be slower than just using the native library. The potential upside is that the native library does not have to be cross-compiled.)
Community contributions are welcome.
Filing an issue because we don't have one tracking this yet.