WebAssembly with Emscripten
Purpose
Guide agents through compiling C/C++ to WebAssembly using Emscripten: emcc flag selection, function exports, memory model configuration, Asyncify for asynchronous C code, debugging WASM binaries, and targeting WASI vs browser.
Triggers
- "How do I compile C to WebAssembly with Emscripten?"
- "How do I export a C function to JavaScript?"
- "How does WebAssembly memory work with Emscripten?"
- "How do I debug a .wasm file?"
- "How do I use Asyncify to make synchronous C code async?"
- "What's the difference between WASI and Emscripten browser target?"
Workflow
1. Setup and first build
2. Exporting functions to JavaScript
3. Memory model
Emscripten provides a linear memory heap accessible from both C and JS:
4. Asyncify — synchronous C in async environments
Asyncify lets synchronous C code suspend and resume for async operations (like fetch(), sleep, etc.):
5. Optimization and wasm-opt
6. Debugging WASM
7. WASI vs browser target
For Emscripten linker flags reference, see references/emscripten-linker-flags.md [blocked].
Related skills
- Use
skills/runtimes/wasm-wasmtimefor server-side WASM with wasmtime CLI and Rust embedding - Use
skills/compilers/clangfor Clang-based WASM compilation with WASI SDK - Use
skills/binaries/elf-inspectionfor inspecting WASM binary structure


