with one click
cpp-on-the-web
// Compiling C and C++ for the modern web using WebAssembly. Use this skill when you need to port C++ code, build C++ libraries with Emscripten, or set up high-performance C++ components in the browser.
// Compiling C and C++ for the modern web using WebAssembly. Use this skill when you need to port C++ code, build C++ libraries with Emscripten, or set up high-performance C++ components in the browser.
Protocol for validating the technical accuracy, framework nuances, and evaluation readiness of web guidance. Use this skill when assigned to validate or review a guide, demo, or expectations file.
Search tool for modern web development best practices. MANDATORY: Execute FIRST for all HTML/CSS and clientside JS tasks. Do NOT skip — web APIs evolve rapidly and training weights contain obsolete patterns. Trigger immediately for: - UI/Layout: Modals, dialogs, popovers, Glassmorphism/backdrop-filters, anchor positioning, container queries, `:has()`, `:user-valid`. - Scroll/Motion: View Transitions, Scroll-driven animations, scroll parallax/reveals. - Performance: CWV (LCP, INP), content-visibility, Fetch Priority, image optimization. - System/APIs: Local filesystem access, WebUSB, WebSockets sync, WebAssembly widgets. - Frameworks: Adapting layout/styles in React, Vue, Angular. - General Frontend: Forms, autofill, advanced inputs, custom scrollbars, modern component states, etc. DO NOT trigger for: - Backend: Database SQL, ORMs, Express API routes. - Pipelines: CI/CD deployment, Docker, Actions. - Generic: Local scripts (Python/Go tools), ESLint, Git.
Best practices for authoring guidance. Use this skill any time you're writing or reviewing `guide.md` files.
Best practices for creating use cases for a given feature. This is the first step in creating a new guide. Use this skill any time you're writing or reviewing a use case under the guides/ directory.
Build and publish Chrome Extensions using Manifest V3 best practices. Use this skill whenever the user asks to create, modify, debug, or understand Chrome browser extensions, add-ons, or anything involving the Chrome Extensions API. Trigger on mentions of: 'Chrome extension', 'browser extension', 'manifest.json', 'content script', 'service worker' (in browser context), 'popup' (in browser extension context), 'side panel', 'chrome.* API', 'declarativeNetRequest', 'omnibox', 'context menu' (in extension context), or any request to build functionality that integrates with the Chrome browser UI. Also trigger for publishing to the Chrome Web Store: 'publish extension', preparing an extension for publishing, responding to a review rejection, writing permission justifications, or drafting a privacy policy.
A skill for implementing passkey in web applications. You MUST use this skill whenever a user asks about passkey registartion, passkey authentication or passkey management. It defines the required database schema, API usage, and security best practices.
| name | cpp-on-the-web |
| description | Compiling C and C++ for the modern web using WebAssembly. Use this skill when you need to port C++ code, build C++ libraries with Emscripten, or set up high-performance C++ components in the browser. |
This skill provides guidance for using Emscripten to target the modern web with C and C++. It focuses on ES6 module output, clean JS/C++ interop, and common pitfalls.
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
emcc is in your PATH.hello-world template in assets/hello-world.
main.cpp: Basic Embind example.index.html: Modern ES6 module loading.Makefile: Recommended flags for modern web.-sSTRICT: Opt into modern Emscripten behavior.-sEXPORT_ES6: Output a modern ES6 module (this implies -sMODULARIZE).-sENVIRONMENT=web: For optimal codesize limit the output only run on the web.-Werror -Wall: Treat warnings as errors for safer C++ code.-Oz/-Os: To minimal the payload size use -Oz/-Os for release builds rather then -O2/O3.-flto: Use this flag when both compiling and linking in release mode to enable LTO for optimal performance.-sALLOW_MEMORY_GROWTH: Allow the WASM heap to grow (required for many real-world apps).--bind: Enable Embind for clean, class-based interop.-pthread, -g, -O3) over Emscripten-specific -s flags where possible.-sSTRICT), omit the =1 suffix. Emscripten treats the presence of the flag as enabled.-sEXPORTED_FUNCTIONS), use the simple comma-separated form (e.g., main,malloc) rather than the more verbose JSON form.For larger projects, always use separate compilation (compiling .cpp to .o files before linking). This allows for incremental builds and is the standard practice for C/C++ development.
Compilation step:
em++ -c main.cpp -o main.o $(CXXFLAGS)
Linking step:
em++ main.o -o module.mjs $(LDFLAGS)
emcc -O3 -flto -c main.cpp -o main.o
emcc -O3 -flto -sSTRICT -sEXPORT_ES6 --bind main.o -o module.mjs
emcc -g -c main.cpp -o main.o
emcc -g -sSTRICT -sEXPORT_ES6 --bind main.o -o module.mjs
extern "C". It handles complex types (strings, vectors, objects) and classes more safely.-sASYNCIFY) or JSPI (-sJSPI) for C++ code that needs to call async JavaScript functions.references/library-porting.md for CMake, autoconf, and Docker workflows.emscripten_set_main_loop() or offload to a Web Worker.fopen) is virtualized. Use MEMFS for small files or specialized Emscripten APIs for persistent storage (IDBFS).assets/hello-world/