Build: qualify wasm test suite with portable libc++ fallbacks (refs #38)

This commit is contained in:
faumaray committed 2026-12-03 17:43:14 +03:00
1 parent 1ba60d5d6a
commit f0820b778f
7 files changed
+163 -12

No files matched your search

+3 -2
View File
@@ -20,8 +20,8 @@ set_property(CACHE VOID_TARGET PROPERTY STRINGS auto ${VOID_KNOWN_TARGETS})
# 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).
# install, consume and run under Node, including the test suite with
# -pthread (see docs/targets.md).
set(VOID_WASM_MODULES
Algorithms
Binary
@@ -53,6 +53,7 @@ set(VOID_WINDOWS_MODULES
Discovery
Fsm
Functional
IO
Log
LogState
Math
+26 -10
View File
@@ -147,7 +147,7 @@ cmake -S . -B build-mingw -G Ninja \
A regular MinGW-w64 installation with winpthreads does not need those extra
flags.
### Browser / Wasm subset (library qualified, test suite unqualified)
### Browser / Wasm subset (qualified)
| Item | Value |
|------|-------|
@@ -157,7 +157,7 @@ flags.
| 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` |
| Observed | configure, compile, `cmake --install`, consume (`find_package(Void)`) and run the consumer under Node (`node_exit=0`) |
| Observed | library: configure, compile, install, consume and run under Node; tests: **901 tests, 895 passed, 6 skipped, 0 failed** under Node |
The allowlist is fail-closed: native networking (`Net`, `RPC`), processes and
filesystem (`System`, `SystemAsync`), IPC, SQLite, plugins and anything that
@@ -190,15 +190,31 @@ 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 (7 translation units after the
reflection gating below). The remaining blockers are libc++ gaps, not
reflection:
The **test suite** is qualified with pthreads, exception handling and a
larger stack:
- `Core/Publication` uses `std::atomic<std::shared_ptr<...>>`, whose
specialization is not implemented by this libc++ (`__cpp_lib_atomic_shared_ptr`
absent). A portable fallback is needed.
- Several `TestingMock` tests need `std::move_only_function`, also absent
from this libc++.
```bash
emcmake cmake -S . -B build-wasm-tests -G Ninja -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_SCAN_FOR_MODULES=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_FLAGS="-fexceptions -pthread" \
-DCMAKE_EXE_LINKER_FLAGS="-fexceptions -pthread -sSTACK_SIZE=16777216 \
-sINITIAL_MEMORY=134217728 -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1073741824" \
-DVOID_ENABLE_TESTING=ON \
-DVOID_ENABLED_MODULES="Algorithms;Binary;Containers;Core;Data;Functional;LogState;Math;Memory;Testing;TestingMock;Text;Time;Unicode"
cmake --build build-wasm-tests
node build-wasm-tests/tests/VoidTests.js --no-color
```
Static linking (`BUILD_SHARED_LIBS=OFF`) is required for exception handling
across the test binary; `-fexceptions` enables catching, `-pthread` enables
the threading tests, and the stack/memory flags accommodate the deepest
recursive tests.
Portable fallbacks added for libc++ without the C++23/26 pieces:
`Core/Publication` uses a mutex-protected `shared_ptr` when
`__cpp_lib_atomic_shared_ptr` is absent, and `TestingMock` uses an internal
move-only function wrapper when `__cpp_lib_move_only_function` is absent.
Reflection-dependent test files are gated with `// @requires-reflection`
(Core/Meta, Core/FlagsReflect, Data/CsvReflect, Data/Reflect*,
+48
View File
@@ -7,6 +7,10 @@
#include <optional>
#include <utility>
#if !defined(__cpp_lib_atomic_shared_ptr)
#include <mutex>
#endif
namespace Void::Core
{
@@ -226,7 +230,51 @@ template <typename T> class Publication
private:
#if defined(__cpp_lib_atomic_shared_ptr)
std::atomic<std::shared_ptr<State>> current_;
#else
// Older libc++ (e.g. Emscripten) does not implement the
// atomic<shared_ptr> specialization. Keep the same load /
// compare-exchange surface with a mutex-protected pointer; the
// publication is still coherent for single-writer/multi-reader use.
class AtomicStatePtr
{
public:
explicit AtomicStatePtr(std::shared_ptr<State> initial)
: current_(std::move(initial))
{
}
[[nodiscard]] std::shared_ptr<State>
load(std::memory_order) const
{
std::lock_guard lock{mutex_};
return current_;
}
bool compare_exchange_weak(std::shared_ptr<State>& expected,
std::shared_ptr<State> desired,
std::memory_order,
std::memory_order)
{
std::lock_guard lock{mutex_};
if (current_ != expected) {
expected = current_;
return false;
}
current_ = std::move(desired);
return true;
}
private:
mutable std::mutex mutex_;
std::shared_ptr<State> current_;
};
AtomicStatePtr current_;
#endif
};
} // namespace Void::Core
+5
View File
@@ -1,6 +1,7 @@
#pragma once
#include <Void/TestingMock/Matcher.hpp>
#include <Void/TestingMock/MoveOnlyFunction.hpp>
#include <Void/TestingMock/Session.hpp>
#include <concepts>
@@ -30,7 +31,11 @@ namespace Void::TestingMock::Detail
std::tuple<MatcherHolder<std::decay_t<Args>>...>;
/// Move-only function — supports unique_ptr-capturing lambdas,
/// move-only arguments, and move-only return values.
#if defined(__cpp_lib_move_only_function)
using Action = std::move_only_function<R(Args...)>;
#else
using Action = MoveOnlyFunction<R(Args...)>;
#endif
Expectation(MatcherTuple matchers, std::source_location loc)
: m_matchers(std::move(matchers)), m_location(loc)
@@ -0,0 +1,73 @@
#pragma once
#include <concepts>
#include <cstddef>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
namespace Void::TestingMock::Detail
{
/// Minimal move-only type-erased callable with the subset of
/// std::move_only_function used by TestingMock. Only needed on standard
/// libraries that do not implement std::move_only_function (older libc++,
/// e.g. Emscripten).
template <typename Signature> class MoveOnlyFunction;
template <typename R, typename... Args>
class MoveOnlyFunction<R(Args...)>
{
private:
struct Base {
virtual ~Base() = default;
virtual R invoke(Args&&... args) = 0;
};
template <typename F> struct Model final : Base {
explicit Model(F callable) : fn(std::move(callable)) {}
R invoke(Args&&... args) override
{
return std::invoke(fn, std::forward<Args>(args)...);
}
F fn;
};
public:
MoveOnlyFunction() noexcept = default;
MoveOnlyFunction(std::nullptr_t) noexcept {}
template <typename F>
requires std::invocable<F&, Args...> &&
(!std::same_as<std::remove_cvref_t<F>,
MoveOnlyFunction>)
MoveOnlyFunction(F&& callable)
: impl_(std::make_unique<Model<std::remove_cvref_t<F>>>(
std::forward<F>(callable)))
{
}
MoveOnlyFunction(MoveOnlyFunction&&) noexcept = default;
MoveOnlyFunction& operator=(MoveOnlyFunction&&) noexcept = default;
MoveOnlyFunction(const MoveOnlyFunction&) = delete;
MoveOnlyFunction& operator=(const MoveOnlyFunction&) = delete;
[[nodiscard]] explicit operator bool() const noexcept
{
return impl_ != nullptr;
}
R operator()(Args... args)
{
return impl_->invoke(std::forward<Args>(args)...);
}
private:
std::unique_ptr<Base> impl_;
};
} // namespace Void::TestingMock::Detail
+4
View File
@@ -16,9 +16,13 @@ namespace
// @tag reflection
Void::Testing::Test debug_dump_reflects_struct_elements()
{
#if !VOID_HAS_CXX26_REFLECTION
Void::Testing::skip("C++26 reflection is not available");
#else
std::vector<P> v{{1, 2}, {3, 4}};
Void::Testing::expect_eq(Void::Containers::debug_dump(v),
std::string{"[P{x: 1, y: 2}, P{x: 3, y: 4}]"});
#endif
}
// @tag reflection
+4
View File
@@ -27,10 +27,14 @@ Void::Testing::Test struct_eq_passes_when_equal()
// includes the type name and field values.
Void::Testing::Test repr_renders_struct_via_reflection()
{
#if !VOID_HAS_CXX26_REFLECTION
Void::Testing::skip("C++26 reflection is not available");
#else
const auto out = Void::Testing::Detail::repr(Point{3, 4});
Void::Testing::expect(out.find("Point") != std::string::npos);
Void::Testing::expect(out.find("x: 3") != std::string::npos);
Void::Testing::expect(out.find("y: 4") != std::string::npos);
#endif
}
// repr for primitives still works.