From b1933d9906547a692dde257e59bdf6f6f9c9d9bb Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Thu, 3 Dec 2026 17:18:29 +0300 Subject: [PATCH] Build: qualify wasm library subset with Emscripten (refs #38) --- cmake/Targets.cmake | 3 +++ docs/targets.md | 53 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/cmake/Targets.cmake b/cmake/Targets.cmake index 1129159..94078da 100644 --- a/cmake/Targets.cmake +++ b/cmake/Targets.cmake @@ -19,6 +19,9 @@ set_property(CACHE VOID_TARGET PROPERTY STRINGS auto ${VOID_KNOWN_TARGETS}) # native I/O, spawns processes, loads shared libraries, uses SQLite, or needs # C++26 reflection. Keep this list fail-closed: a module is added only after # it has been configured and compiled for wasm32-unknown-emscripten. +# Qualified with Emscripten 6.0.9 (Clang 22, libc++) for configure, build, +# install, consume and run under Node; the wasm test suite is not qualified +# yet (see docs/targets.md). set(VOID_WASM_MODULES Algorithms Binary diff --git a/docs/targets.md b/docs/targets.md index 2b38e84..a42fbb3 100644 --- a/docs/targets.md +++ b/docs/targets.md @@ -144,23 +144,62 @@ cmake -S . -B build-mingw -G Ninja \ A regular MinGW-w64 installation with winpthreads does not need those extra flags. -### Browser / Wasm subset (unqualified) +### Browser / Wasm subset (library qualified, test suite unqualified) | Item | Value | |------|-------| | Triple | `wasm32-unknown-emscripten` | -| Compiler | Emscripten Clang (4.x) | +| Compiler | Emscripten 6.0.9 (Clang 22.1.8) | | Standard library | libc++ + Emscripten libc | -| CMake / generator | CMake 4.0+ via `emcmake`, Ninja | +| CMake / generator | CMake 4.5 via `emcmake`, Ninja, Node 24.22.3 as the test emulator | | Language | C++26 without reflection (`VOID_HAS_CXX26_REFLECTION=no`) | | Modules | `Algorithms Binary Containers Core Data Functional LogState Math Memory Testing TestingMock Text Time Unicode` | -| Status | **not qualified**: no Emscripten toolchain in the qualification environment | +| Observed | configure, compile, `cmake --install`, consume (`find_package(Void)`) and run the consumer under Node (`node_exit=0`) | The allowlist is fail-closed: native networking (`Net`, `RPC`), processes and filesystem (`System`, `SystemAsync`), IPC, SQLite, plugins and anything that -needs threads or reflection stay out. ThreadSanitizer is rejected for -`wasm`. Do not add a module until it has been configured and compiled with -`emcmake`. +needs threads or reflection stay out. Do not add a module until it has been +configured and compiled with `emcmake`. + +Verified commands: + +```bash +# Library subset +emcmake cmake -S . -B build-wasm -G Ninja -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_SCAN_FOR_MODULES=OFF \ + -DVOID_ENABLE_TESTING=OFF \ + -DVOID_ENABLED_MODULES="Algorithms;Binary;Containers;Core;Data;Functional;LogState;Math;Memory;Testing;TestingMock;Text;Time;Unicode" +cmake --build build-wasm +cmake --install build-wasm --prefix "$PWD/build-wasm-install" + +# Consumer (the install lives outside the Emscripten sysroot) +emcmake cmake -S tests/package/TargetProfile -B build-wasm-consumer -G Ninja \ + -DCMAKE_PREFIX_PATH="$PWD/build-wasm-install" \ + -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \ + -DCMAKE_CXX_SCAN_FOR_MODULES=OFF \ + -DVOID_EXPECTED_TARGET=wasm +cmake --build build-wasm-consumer +node build-wasm-consumer/void_target_profile_consumer.js +``` + +`CMAKE_CXX_SCAN_FOR_MODULES=OFF` avoids CMake's C++20 module dependency +scanner calling Emscripten's `emscan-deps`, which is not shipped by every +Emscripten package. `CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH` is needed +because the Emscripten toolchain restricts package lookup to its sysroot. + +The **test suite** does not build yet on wasm (16 translation units). The +blockers are test-side, not library-side: + +- Reflection tests (`Core/Meta`, `Core/FlagsReflect`, `Data/CsvReflect`, + `Data/Reflect*`, `Functional/ResultReflectionFormat`, + `TestingMock/Reflect`) are not guarded when reflection is unavailable. +- `Core/Publication` uses `std::atomic>`, whose + specialization is not implemented by this libc++ (`__cpp_lib_atomic_shared_ptr` + absent). A portable fallback is needed. +- `Testing/ContainerFixture` and several `TestingMock` tests need the same + treatment. + +Runtime observations use Node; a browser runner should confirm them. ## Sanitizers