Preview of main at d0a501a, 2026-11-07

C++ for WebAssembly: Emscripten, WASI and wasmtime

webcpp's libraries are header-only C++20, built, tested and documented with b2, the way Boost's are. The same program builds for the browser, for a server as a WebAssembly component, and natively.

Getting started

Install Boost, b2 and a C++20 compiler, at the versions the README gives. Then clone the superproject with its libraries, and run every library's tests:

git clone --recursive https://github.com/webcpporg/webcpp
cd webcpp
b2 test

A b2 project uses a library through /webcpp/<name>//<name>. CMake or a plain compiler uses the headers that b2 install --prefix=<dir> copies to <dir>/include/webcpp/.

The README: prerequisites and configuration

Building for each target

Native. b2 builds with your own compiler, as for any C++ library, for programs that integrate closely with an operating system.

b2 test example

WASI, for servers. Two clang toolsets of wasi-sdk build for wasm32-wasip2 and wasm32-wasip3. wasmtime runs each test, and serves a component the way a cloud runs a WebAssembly container, lighter than Docker.

b2 toolset=clang-wasip2 testing.launcher=wasmtime test example
b2 toolset=clang-wasip3 testing.launcher=wasmtime test example

Emscripten, for the browser. The emscripten toolset builds a library that declares that target, and node runs its tests. A program for a page is linked, and runs in the browser.

b2 toolset=emscripten libs/<name>/test libs/<name>/example

b2 declared-targets -d0 lists the targets each library declares.

Registering the WebAssembly toolsets

The libraries' pages

Each library's page teaches it: its guide, its guarantees, its API reference and how it is tested.

  • asio

    Boost.Asio for native, browser and WASIp2/P3 targets, with explicit platform capabilities and shipped Wasm implementations.

  • beast

    Beast-compatible HTTP and WebSocket interfaces for WebAssembly and native applications.

  • cobalt

    Boost.Cobalt coroutine applications on native, browser and WASI targets.

  • config

    webcpp's configuration, which every webcpp library includes first: the target a program is built for, whether webcpp has exceptions, and webcpp's version.

  • document

    A JSON document for C++20 that behaves as JavaScript does, in one relocatable image.

  • idna

    IDNA2008 and UTS 46 for C++20: Punycode, ToASCII and ToUnicode, and label validity, over generated Unicode 17.0 tables.

  • lexical

    Validators and Boost.URL grammar rules for the string formats of JSON Schema, for C++20.

  • pratt

    A generic Pratt parser engine for C++20, with a decimal calculator built on it.

  • trystero

    Serverless WebRTC rooms for C++20, wire compatible with Trystero.

  • wasi

    Header-only helpers for C++ built as WebAssembly components: the HTTP handler a component exports on wasip2 and wasip3, and the macros a program writes its main between.

  • xactor

    A header-only, deterministic actor system: actors that handle one message at a time, with fuel per execution, timers and a lifecycle.

  • xstate

    A header-only port of XState's state machines and actors: machines read from XState's JSON config, stepped by XState's pure functions or run as actors on xactor.

The documentation's index