emscripten-core / emscripten-core/emscripten

Generate both sync and async modules

Open
#15,633 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

What is the right way to generate a package that works in Node.js or Web Workers without extra Promises and can be used in Chrome (asynchronously)?

Currently in [arima.js](https://github.com/zemlyansky/arima) I run emcc two times with `BINARYEN_ASYNC_COMPILATION=0` and `BINARYEN_ASYNC_COMPILATION=1` generating two different `.js` files with `Module`s. The package exposes two endpoints: synchronous `arima` for Node.js (or Web Workers, Firefox only) using sync `Module` compilation, and Promise-based `arima/async` for all browsers including Chrome. In both cases the generated `wasm` file is wrapped in its own `js` file that can be `require`d and passed to `Module` then bundled (this prevents extra fetching).

So, this approach works, but feels hackish (it compiles the same `wasm` file two times). Maybe it makes sense to generate two Module files or one universal if `BINARYEN_ASYNC_COMPILATION` is not set? For example:
```javascript
// Sync
const module = Module({ wasmBinary: bin, async: False })
// Async
Module({ wasmBinary: bin, async: True }).then(module => {
...
})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.