dart-archive / wasm

Utilities for loading and running WASM modules from Dart code
https://pub.dev/packages/wasm
BSD 3-Clause "New" or "Revised" License
312 stars 24 forks source link

Investigate generating bindings. #116

Open modulovalue opened 1 year ago

modulovalue commented 1 year ago

It would be good to have some machinery that is able to generate bindings for any given WASM module i.e. generate type-safe APIs in Dart that would allow us to use the declarations declared in a WASM module without having to use any unsafe features (i.e. casting) ourselves. There are some open questions:

liamappelbe commented 1 year ago

I'm tempted to add a mode to package:ffigen that can scan a C header and generate package:wasm bindings. But it's tricky because the encoding of higher level types like strings depends on your target (eg WASI or Emscripten).

It's probably safer to just look at the wasm module's type info and generate some low level bindings. The conversion to higher level types can happen in a wrapper.

modulovalue commented 1 year ago

Rusts solution to this issue: https://rustwasm.github.io/wasm-bindgen/