feat: add Emscripten support to the WASM generator#26
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
emscriptenflag to the WASM generator config. When set,loadWeaveffiWasmaccepts a pre-initialized EmscriptenModule(or the promise returned by itsMODULARIZEfactory) instead of a.wasmURL. The loader prologue binds the module's underscore-prefixed exports to the symbol names the glue calls (quoted bracket access for Closure Compiler safety), with a liveget memory()getter overHEAPU8so memory growth is handled. Everything after the prologue is byte-identical to the standard loader; no standard-mode.jssnapshot changed.cabi.rsvisibility change from the fork:{PREFIX}_APInow expands to__attribute__((used, visibility("default")))under__EMSCRIPTEN__(theEMSCRIPTEN_KEEPALIVEexpansion), so exports survive dead-code elimination without an-sEXPORTED_FUNCTIONSlist._malloc/_free: the generated C header now declares{prefix}_alloc/{prefix}_deallocalongside the other runtime helpers, and the{prefix}.cscaffold provides malloc/free-backed defaults..d.tsbyte type from the Node-onlyBuffertoUint8Array..d.ts(the same treatment listeners get); documented in the generated README and the book.Credit
Based on the design validation by @ariankordi, who proved out Emscripten support end to end in the
emscripten-supportfork and reported it in #22. This PR implements the loader through a config flag plus a load-time export adapter rather than per-call-site branching, but thecabi.rsvisibility fix and the overall validation come from that work.Closes #22.
Test plan
weaveffi-gen-wasm: adapter loader shape, prefixed runtime bindings, byte-identical shared helpers between modes, async stubs,.d.tsloader signature and async omission,Uint8Arraymappinggenerators.wasm.emscripten: truecargo test --workspacepasses; the 32 changed snapshots (C/C++ headers,weaveffi.c, two.d.ts) reviewed and acceptedcargo fmt --checkandcargo clippy --workspace --all-targets -- -D warningscleanweaveffi.ccompiles with-Wall -Wextra -Werror