Skip to content

mohitmishra786/low-level-dev-skills / skills/runtimes/wasm-emscripten

wasm-emscripten

Verified

WebAssembly with Emscripten skill for C/C++ to WASM compilation. Use when compiling C/C++ to WebAssembly with emcc, configuring EXPORTED_FUNCTIONS, understanding the WASM memory model, using Asyncify for async C code, debugging .wasm with browser devtools or wasm-opt, or targeting WASI vs browser environments. Activates on queries about Emscripten, emcc, WebAssembly from C/C++, WASM memory model, Asyncify, EXPORTED_FUNCTIONS, WASI, or wasm-opt.

FileKindSize
SKILL.mdskill md6.5 KB
references/emscripten-linker-flags.mdmarkdown2.3 KB

references/emscripten-linker-flags.md

View on GitHub
# Emscripten Linker Flags Reference

Source: <https://emscripten.org/docs/tools_reference/settings_reference.html>

## Key Settings

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `EXPORTED_FUNCTIONS` | list | `["_main"]` | C functions exported to JS (needs leading `_`) |
| `EXPORTED_RUNTIME_METHODS` | list | `[]` | Runtime helpers: `ccall`, `cwrap`, `allocate`, etc. |
| `MODULARIZE` | bool | `0` | Wrap output in a function returning a Promise |
| `EXPORT_NAME` | string | `"Module"` | Name of the exported JS module |
| `INITIAL_MEMORY` | int | 16MB | Initial WASM heap size |
| `MAXIMUM_MEMORY` | int | 2GB | Max WASM heap with ALLOW_MEMORY_GROWTH |
| `ALLOW_MEMORY_GROWTH` | bool | `0` | Allow heap to grow dynamically |
| `STACK_SIZE` | int | 64KB | C stack size |
| `ASSERTIONS` | 0/1/2 | `1` in debug | Runtime safety assertions |
| `SAFE_HEAP` | bool | `0` | Check all heap accesses for alignment |
| `ASYNCIFY` | bool | `0` | Enable Asyncify for async C |
| `USE_PTHREADS` | bool | `0` | Enable pthreads (needs SharedArrayBuffer) |
| `SHARED_MEMORY` | bool | `0` | Enable shared memory |
| `SINGLE_FILE` | bool | `0` | Embed WASM in JS as base64 |
| `ENVIRONMENT` | string | `"web,webview,worker,node"` | Target environments |
| `FILESYSTEM` | bool | `1` | Include virtual filesystem |
| `EXIT_RUNTIME` | bool | `0` | Call exit() when main() returns |
| `INVOKE_RUN` | bool | `1` | Run main() automatically |
| `NO_EXIT_RUNTIME` | bool | `1` | Don't tear down runtime on exit |

## Common Configurations

### Minimal library (no main, no filesystem)

```bash
emcc lib.c -o lib.js \
  -s EXPORTED_FUNCTIONS='["_my_func"]' \
  -s EXPORTED_RUNTIME_METHODS='["cwrap"]' \
  -s FILESYSTEM=0 \
  -s MODULARIZE=1 \
  -s EXPORT_NAME=MyLib \
  -s ENVIRONMENT=web \
  -Os
```

### Node.js WASM module

```bash
emcc prog.c -o prog.js \
  -s ENVIRONMENT=node \
  -s MODULARIZE=1 \
  -s EXPORT_NAME=MyModule \
  -O2
# Use: const M = await require('./prog.js')()
```

### Threaded application

```bash
emcc prog.c -o prog.js \
  -s USE_PTHREADS=1 \
  -s PTHREAD_POOL_SIZE=4 \
  -s INITIAL_MEMORY=64MB \
  -O2
# Requires: Cross-Origin-Opener-Policy: same-origin
#           Cross-Origin-Embedder-Policy: require-corp
```

### Minimal WASI build

```bash
emcc prog.c -o prog.wasm \
  --target=wasi \
  -s ENVIRONMENT=node \
  -Os
```
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall