Skip to content

Support wasm32-unknown-emscripten#951

Draft
logan-gatlin wants to merge 3 commits intomainfrom
emscripten
Draft

Support wasm32-unknown-emscripten#951
logan-gatlin wants to merge 3 commits intomainfrom
emscripten

Conversation

@logan-gatlin
Copy link
Collaborator

@logan-gatlin logan-gatlin commented Mar 16, 2026

Wasm-bindgen will soon support emscripten outputs. This PR allows workers-rs to take that output, run it through emcc, and get a final product that can run on the workers runtime.

Strategy

  1. [HACK] Compile C VFS overrides file. Emscripten only provides weak stubs for filesystem calls for some reason. Linking with this C file provides strong definitions, which later forces Emscripten to actually provide a JS implementation. I am not sure yet why this works or why this is necessary.
  2. Compile the project and link with the C VFS .o file
  3. Run the wasm-bindgen CLI, producing library_bindgen.js and index_bg.wasm.
  4. Generate output.js and output.wasm using the emscripten toolchain:
emcc --post-link index_bg.wasm --js-library library_bindgen.js -o output.js \
  -sMODULARIZE=1 -sEXPORT_ES6=1 -sENVIRONMENT=web -sASSERTIONS=0 \
  -sSTACK_OVERFLOW_CHECK=0 -sERROR_ON_UNDEFINED_SYMBOLS=0 -Wno-experimental
  • note that the sERROR_ON_UNDEFINED_SYMBOLS=0 is a workaround for what I'm pretty sure is a bug in wasm-bindgen's emscripten implementation
  1. Generate small shim.js that handles Emscriptens startup process and exports worker compatible handles for fetch, schedule, queue.

The new example is deployed here, showing that basic programs can run on the real workers runtime

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 16, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 2 untouched benchmarks


Comparing emscripten (d66e698) with main (2d022ab)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant