web-wasm
web-wasm
Purpose
This skill enables the AI to compile and integrate code from Rust, Go, or C into WebAssembly (WASM) for high-performance web applications, using tools like wasm-bindgen, Emscripten, and the WASM Component Model.
When to Use
Use this skill for browser-based tasks requiring speed, such as running simulations, processing large datasets, or porting legacy C/C++ code to the web. Apply it when JavaScript performance is insufficient, or when working with languages like Rust for safe, concurrent code in the browser.
Key Capabilities
- Compile Rust to WASM with wasm-pack, including generating JavaScript bindings via wasm-bindgen.
- Convert C/C++ to WASM using Emscripten, with options for HTML output and memory management.
- Support Go to WASM via TinyGo, enabling lightweight modules.
- Handle WASM Component Model for composing modules, using tools like wasm-tools for interface definitions.
- Optimize for performance with flags like Emscripten's
-s ALLOW_MEMORY_GROWTH=1for dynamic memory.
Usage Patterns
To compile Rust to WASM, first ensure dependencies: install Rust via rustup and wasm-pack via cargo install wasm-pack. In your project directory, add wasm-bindgen to Cargo.toml, write annotated code, then run wasm-pack build --target web --release. For C/C++, install Emscripten SDK, set up with emsdk install latest && emsdk activate latest, then compile files with emcc. Always verify outputs in a browser by loading the generated JS and WASM files.