fluffos/CMakePresets.json
Yucong Sun e6f0c377f8
wasm: run the full driver in the browser (Emscripten port) (#1231)
The driver cross-compiles to WebAssembly and runs a complete mudlib
inside a webpage: compiler, VM, all portable efun packages, and the
real telnet protocol layer -- the page is the telnet client, JavaScript
is the wire. The LPC testsuite passes inside the wasm driver (browser
and node).

Architecture (src/wasm/README.md):
- Transport interface (src/net/transport.h): each interactive_t owns an
  abstract byte pipe (write/flush/schedule_command/close). comm.cc and
  telnet.cc are transport-agnostic and compile unchanged on every
  target. Implementations select at link time: SocketTransport +
  WebsocketTransport (net/transport_libevent.cc, native) vs
  WasmConsoleTransport (src/wasm/comm_wasm.cc).
- Inverted event loop: the shared gametick/event core stays in
  backend.cc; backend_libevent.cc (blocking loop) vs
  src/wasm/backend_wasm.cc (page-driven fluffos_tick(now_ms), walltime
  priority queue, capped catch-up). Other per-target singletons (TLS,
  DNS resolver, crash handler) follow the same link-time pattern -- no
  #ifdef __EMSCRIPTEN__ in shared logic files.
- Mudlib rides in Emscripten's MEMFS via file_packager; driver file I/O
  needed zero changes.

jsbridge package (WASM only): js_eval() (sync), js_call() (async page
handlers with LPC callbacks), js_export() (page calls LPC via
Module.fluffos.callLPC, Promise-resolved on a later tick) -- fetch,
canvas/WebGL, storage, page UIs driving the game. Demo in
testsuite/command/jsdemo.lpc + the bundled web terminal.

Build/tooling: native-tools + wasm CMake presets (host codegen tools,
then cross build); tools/wasm/build-deps.sh (ICU + zlib cross-builds,
including the ICU genccode data quirk); tools/wasm/pack-mudlib.sh
(any mudlib + driver -> static web bundle, also works standalone from
the release zip); src/www/wasm/index.html (self-contained web terminal
with a minimal telnet client). On emsdk >= 3.1.57 the build uses native
wasm exceptions (-fwasm-exceptions); older toolchains fall back to
-sDISABLE_EXCEPTION_CATCHING=0.

CI/release: a wasm CI job (latest emsdk, deps cache keyed on resolved
emcc version) gates PRs on the LPC testsuite running inside the wasm
driver under node; release.yml ships fluffos-<version>-wasm.zip
(driver + web terminal + pack-mudlib.sh). Fixed a stale-predefine bug:
options.autogen.h now depends on packages.autogen.h + config.h.

Docs: docs/build-wasm.md (end-to-end workflow), docs/driver/wasm.md
(packer + jsbridge cookbook), docs/efun/jsbridge/*, README + AGENTS
updated. Testsuite files for optional packages guard themselves with
#ifdef __PACKAGE_*__.


Claude-Session: https://claude.ai/code/session_01VVpphH3cgXyziRDCbjUVkb

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-10 23:33:51 -04:00

172 lines
4.9 KiB
JSON

{
"version": 3,
"configurePresets": [
{
"name": "linux-debug",
"displayName": "Linux Debug (Clang + ASan/UBSan)",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"MARCH_NATIVE": "OFF",
"ENABLE_SANITIZER": "ON",
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "linux-relwithdebinfo",
"displayName": "Linux RelWithDebInfo (Clang)",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"MARCH_NATIVE": "OFF",
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"MARCH_NATIVE": "OFF"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "macos-relwithdebinfo",
"displayName": "macOS RelWithDebInfo",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"MARCH_NATIVE": "OFF"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "windows-debug",
"displayName": "Windows Debug (MSYS2/MinGW64)",
"generator": "MSYS Makefiles",
"binaryDir": "${sourceDir}/build",
"environment": {
"PATH": "$env{MSYS2_ROOT}/mingw64/bin;$env{MSYS2_ROOT}/usr/bin;$penv{PATH}",
"MSYSTEM": "MINGW64"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"MARCH_NATIVE": "OFF"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "windows-relwithdebinfo",
"displayName": "Windows RelWithDebInfo (MSYS2/MinGW64)",
"generator": "MSYS Makefiles",
"binaryDir": "${sourceDir}/build",
"environment": {
"PATH": "$env{MSYS2_ROOT}/mingw64/bin;$env{MSYS2_ROOT}/usr/bin;$penv{PATH}",
"MSYSTEM": "MINGW64"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"MARCH_NATIVE": "OFF"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "native-tools",
"displayName": "Native codegen tools (stage 1 of a cross build)",
"description": "Minimal native configuration whose only purpose is building make_func/build_applies/make_options_defs for a cross build.",
"binaryDir": "${sourceDir}/build-native-tools",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"MARCH_NATIVE": "OFF",
"USE_JEMALLOC": "OFF",
"PACKAGE_DB": "OFF",
"PACKAGE_PCRE": "OFF",
"PACKAGE_FFI": "OFF",
"PACKAGE_EXTERNAL": "OFF"
}
},
{
"name": "wasm",
"displayName": "WebAssembly (Emscripten)",
"description": "Cross build of the web driver. Configure through the emscripten wrapper: `emcmake cmake --preset wasm` (after building the native-tools preset). Wasm-built ICU/zlib are expected under /opt/wasm-deps; override with -DFLUFFOS_WASM_DEPS=<prefix>.",
"binaryDir": "${sourceDir}/build-wasm",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"FLUFFOS_HOST_TOOLS_DIR": "${sourceDir}/build-native-tools/src/tools"
}
}
],
"buildPresets": [
{
"name": "linux-debug",
"configurePreset": "linux-debug"
},
{
"name": "linux-relwithdebinfo",
"configurePreset": "linux-relwithdebinfo"
},
{
"name": "macos-debug",
"configurePreset": "macos-debug"
},
{
"name": "macos-relwithdebinfo",
"configurePreset": "macos-relwithdebinfo"
},
{
"name": "windows-debug",
"configurePreset": "windows-debug"
},
{
"name": "windows-relwithdebinfo",
"configurePreset": "windows-relwithdebinfo"
},
{
"name": "native-tools",
"configurePreset": "native-tools",
"targets": ["make_func", "build_applies", "make_options_defs"]
},
{
"name": "wasm",
"configurePreset": "wasm",
"targets": ["driver-web"]
}
]
}