# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Build Requires CMake 4.0+ and a C++26 compiler. GCC 16+ is the default — it ships the experimental `-freflection` flag and the `` header that several modules use. Clang is supported but currently lacks P2996 reflection, so modules that use it stay reflection-free behind `__has_include()`. ```bash # Configure (g++, Ninja, Debug) cmake -B build -S . -G Ninja -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Debug # Build cmake --build build # Run all tests ctest --test-dir build # Or run the single test binary directly (supports --filter, --parallel, ...) ./build/tests/VoidTests --filter "Json*" ``` Format code with: ```bash clang-format -i ``` ## Architecture VoidLibrary is a C++26 modular shared library organized as **umbrella modules** — one CMake target each, grouping related functionality. The C++ namespaces of absorbed components are unchanged (e.g. `Void::Ring` lives in `include/Void/Containers/Ring.hpp`, linked via `Void::Containers`). | Module | Type | Contents | |---|---|---| | `Core` | INTERFACE | Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant | | `Functional` | INTERFACE | Pipeline (+Curry, +Memo), Either (+Opt), Result, Retry | | `Containers` | INTERFACE | Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval | | `Math` | INTERFACE | Vec/Mat, Matrix, Numeric, Random, Histogram | | `Text` | INTERFACE | Str, Format, Tokenizer, Diff, Encoding, Semver | | `Data` | INTERFACE | Json, Csv, Ini | | `Async` | INTERFACE | Coro (Task, Generator), Concurrency (ThreadPool, Channel, ParallelFor), EventBus, Observable | | `Time` | INTERFACE | Stopwatch, Format (durations/ISO-8601), Bench | | `Log` | SHARED | `Void::Log` header-only facade + `Void::Logging` framework | | `System` | SHARED | FileSystem (Path, Query, TempDir) + Process | | `Configuration` | SHARED | Config, Env + Argparse | | `Stacktrace` | SHARED | Boost.Stacktrace capture, color helpers (kept separate to isolate the Boost dep) | | `Plugin` | SHARED | dlopen loader, C ABI, hot reload | | `StateMachine` | INTERFACE | compile-time variant-based FSM | | `Testing` / `TestingMock` | STATIC / INTERFACE | test + mock frameworks | `include/Void/Detail/` (e.g. `Enum.hpp` — P2996 enum reflection) is not a module; it is header-only and reachable from every module via the shared include root. ### Module system `cmake/Module.cmake` defines `void_add_module(NAME ...)`. The root `CMakeLists.txt` auto-discovers every subdirectory under `src/` and calls it (or includes the dir's `module.cmake` if present), then calls `void_finalize_modules()`. A module with only headers becomes an `INTERFACE` library; one with `.cpp` sources becomes `SHARED` — except `Testing`, which is special-cased to `STATIC`. Module layout: - Headers: `include/Void//*.hpp` - Sources: `src//*.cpp` - CMake target: `Void_` with alias `Void::` Every header-only module **must** have at least a one-line `src//module.cmake` (`void_add_module()`) — git does not track empty directories, and discovery iterates `src/*`. `void_add_module` accepts three dependency lists: - `INTERNAL_DEPS` — other `Void::*` modules (linked unconditionally). - `EXTERNAL_DEPS` — third-party targets fetched via `cmake/Dependencies.cmake` (`FetchContent`); add new ones there before referencing. - `OPTIONAL_DEPS` — `Void::*` modules linked only if they exist; each present dep additionally defines `VOID_HAS_` for conditional code. Resolution is deferred to `void_finalize_modules()`, so it does not depend on discovery order. ### Tests All tests compile into **one binary**, `build/tests/VoidTests` (registered as the single ctest entry): | Category | Location | Suite label | |---|---|---| | Standalone | `tests/standalone//.cpp` | `` (file stem) | | Internal (cross-module) | `tests/internal/*.cpp` | `internal_` | **The `tests/standalone/` directory name must exactly match a module name** — the scanner iterates registered modules and silently skips unknown directories. After moving/renaming tests, compare the runner's total test count. #### Writing a test Tests are free functions (or methods on a `Void::Testing::Fixture` subclass) returning `Void::Testing::Test` or `Void::Testing::DisabledTest` (both aliases for `void`). **Never write the registration code yourself** — `cmake/VoidTestScanner.cmake` parses each `.cpp` at configure time, generates `*.void_tests.cpp` shims with `Void::Testing::Detail::test_registrar` calls, and rewrites the original source to `HEADER_FILE_ONLY`. ```cpp #include #include Void::Testing::Test addition() { Void::Testing::expect_eq(1 + 1, 2); } // @tag integration, database Void::Testing::Test db_query() { Void::Testing::expect(true); } // @skip "Feature #42 not implemented" Void::Testing::DisabledTest broken() { Void::Testing::fail("not ready"); } ``` Fixture-based tests work the same way — declare a class derived from `Void::Testing::Fixture`, override `setup()`/`teardown()`, and write methods returning `Test`/`DisabledTest`. Comment metadata (immediately preceding the function): - `// @tag a, b, c` — attaches tags. - `// @skip ` — marks the test skipped with a reason; quoted or unquoted strings both work. `DisabledTest` implies `@skip "disabled"` if no explicit reason is given. - Any non-comment, non-empty line resets the accumulated tags/skip — keep the comment block adjacent to the function. The sweep in `cmake/VoidTesting.cmake` auto-applies the scan to every executable that transitively links `Void::Testing`. To opt a target out, set the `VOID_TESTING_NO_AUTO_SCAN` property; to opt in explicitly (e.g. for a target that doesn't link `Void::Testing` directly), call `void_add_tests()`. ### Logging module `Void::Logging::Logger` is an abstract base class. Derive from it to create a sink: 1. **Override `write(const Entry&)`** — called per-entry in Immediate mode and by the default `on_flush` fallback. 2. **Optionally override `on_flush(std::span)`** — for batch/vectored I/O (e.g. file sinks). 3. **Call `flush()` in your derived destructor** — the base destructor does not flush because calling a pure virtual from `~Logger` is UB. Any unflushed entries remaining after your destructor are silently dropped. Key design points: - Virtual extension points (`write`, `on_flush`) are called **outside** the internal mutex, so derived classes can do blocking I/O or acquire their own locks freely. - `Level::Disabled` suppresses all output. Levels are ordered: `Trace < Debug < Info < Warning < Error < Fatal`. - `push_scope(name)` returns a `[[nodiscard]]` RAII `ScopedContext` that emits `ScopeEnter`/`ScopeExit` entries and annotates all entries logged in that thread with a breadcrumb. `scope(name)` emits the boundary pair immediately without touching the scope stack. - `make_preset(level, prefix)` returns a `Preset` — a non-owning callable that bakes in a level and optional prefix. Presets must not outlive their logger. ## Code style Enforced by `.clang-format` (LLVM-based): 4-space indent (tabs), 80-column limit, Linux brace wrapping style, pointer alignment right.