Introduce fp-bindgen to reduce WASM boilerplate
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 215
- Avg merge
- 2h 9m
- Merged PRs (30d)
- 27
Description
Currently, interactions between JS<->WASM have several non-critical issues:
- They are handwritten boilerplate (allocating/reading/freeing memory mostly)
- Each new export/import introduces a lot of code duplication
- The ABI is slightly inconsistent. Sometimes functions don't return anything, sometimes they take multiple raw strings and sometimes they take a single string that is meant to be read as a JSON.
Normally, projects like this would use wasm-bindgen and/or wasm-pack. Unfortunately, we cannot use those due to our reliance on the wasm32-wasi target. https://github.com/fiberplane/fp-bindgen however, should work for us. We should likely use their beta releases, because they do not do releases very frequently at the moment.
With this, we can have a much stronger contract between wingc and any JS that attempts to consume it. It also uses MessagePack to get data between runtimes, which may even be faster than the current JSON method we use in several places.
Note: Technically, an alternative would be to use https://github.com/bytecodealliance/wit-bindgen and https://github.com/bytecodealliance/jco. It's very possible these will be the defacto method of doing this in the future, but it's likely too early to go all-in on WASM components.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing wingc's existing JavaScript↔WASM interactions and the handwritten memory-management and import/export code described in the issue. Then evaluate fp-bindgen's beta releases against the wasm32-wasi target, including its MessagePack-based data exchange. Done means the duplicated boilerplate is replaced and the ABI contract is made consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, wasm
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 24/100