Files
Library/README.md
T
faumarayandClaude Sonnet 4.6 a09e000f0f Add Hash, Random, Uuid, Encoding, Bits, Math modules + make Testing deps optional
New header-only modules:
- Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals
- Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string
- Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces
- Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode
- Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks
- Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation)

Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added
Detail/Color.hpp shim that delegates to Stacktrace::Color when present or
provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler,
ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE.

Fix Repr.hpp reflect_struct to handle template specializations that lack
std::meta::identifier_of (now guarded by has_identifier check).

33/33 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 21:52:22 +03:00

88 lines
4.6 KiB
Markdown

# VoidLibrary
A modular C++26 shared library. Each module is an independently installable
CMake target under the `Void::` namespace; the build system auto-discovers
modules under `src/` and links them together.
## Build
Requires CMake 4.0+ and a C++26 compiler. GCC 16+ is the default — it ships
experimental P2996 reflection (`-freflection`, `<meta>` header) that several
modules opt into.
```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
# Run a single standalone test binary directly
./build/tests/test_standalone_Logging_FileLogger
```
### Optional build flags
| Flag | Default | Effect |
|----------------------------|---------|------------------------------------------------------------------------|
| `VOID_ENABLE_TESTING` | `ON` | Build the test suite under `tests/`. |
| `VOID_WARNINGS_AS_ERRORS` | `OFF` | Adds `-Wall -Wextra -Wpedantic -Werror` (GCC/Clang) or `/W4 /WX` (MSVC). |
| `VOID_ENABLE_ASAN` | `OFF` | Adds `-fsanitize=address` to compile and link. |
| `VOID_ENABLE_UBSAN` | `OFF` | Adds `-fsanitize=undefined` to compile and link. |
| `VOID_ENABLE_COVERAGE` | `OFF` | Adds `--coverage` (GCC) or `-fprofile-instr-generate -fcoverage-mapping` (Clang). After `ctest`, run `gcovr -r . build` for a report. |
```bash
cmake -B build-asan -S . -G Ninja -DCMAKE_CXX_COMPILER=g++ \
-DVOID_ENABLE_ASAN=ON -DVOID_ENABLE_UBSAN=ON \
-DVOID_WARNINGS_AS_ERRORS=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build build-asan
ctest --test-dir build-asan
```
Format code with `clang-format -i <file>`.
## Modules
| Module | Namespace | Description |
|---------------|-----------------------|-----------------------------------------------------------------------------|
| `Logging` | `Void::Logging` | Thread-safe `Logger` ABC with buffering, scopes, presets; ships `FileLogger` and `ConsoleLogger` sinks. |
| `Testing` | `Void::Testing` | Self-registering test framework with fixtures, tags, JUnit/console reporters, signal-handler crash capture. |
| `TestingMock` | `Void::TestingMock` | Header-only mock framework: `MockFunction`, `Mock<Derived>` CRTP base, matchers (`Eq`/`_`/`Lt`/`Le`/`Gt`/`Ge`/`Range`/`Pred`/`StartsWith`/`Contains`), move-only actions. |
| `Stacktrace` | `Void::Stacktrace` | Stack capture + source-snippet rendering via Boost.Stacktrace; ANSI color helpers. |
| `Result` | `Void::Result` | Header-only `Result<T,E> = std::expected<T,E>` plus `Error` with cause-chain context, `with_context()` helper, reflection-based struct `repr` (C++26 `<meta>`). |
| `FileSystem` | `Void::FileSystem` | Header-only path utilities returning `Result<T,E>`: `read_file`, `write_file`, `atomic_write`, `ensure_directory`, `remove_path`, RAII `TempDir`. |
| `Concurrency` | `Void::Concurrency` | Header-only `ThreadPool`, bounded MPMC `Channel<T>`, and `parallel_for` built on the pool. Testing runner uses the pool for `--parallel <n>` mode. |
| `Log` | `Void::Log` | Thin global log-sink layer used internally by all modules. Install any callable via `set_sink(fn)`; include `LoggingAdapter.hpp` to bridge to `Void::Logging`. |
## Adding a module
Create `src/<ModuleName>/` and populate it with sources/headers — the build
picks it up automatically. Public headers go in
`include/Void/<ModuleName>/*.hpp`. For special dependency wiring drop a
`module.cmake` in the source directory; see `cmake/module.cmake.template`
for the shape and `cmake/Module.cmake` for the full `void_add_module`
contract (`INTERNAL_DEPS`, `EXTERNAL_DEPS`, `OPTIONAL_DEPS`,
`DEPS_WIN32`/`DEPS_UNIX`, `OPTIONS_WIN32`/`OPTIONS_UNIX`).
## Using as a dependency
```cmake
find_package(Void REQUIRED)
target_link_libraries(myapp PRIVATE Void::Logging Void::Stacktrace)
```
`find_package(Void)` exposes every installed module under the `Void::`
namespace and auto-loads the test scanner so downstream projects can use
`void_add_tests()` for free.
## Writing tests
Tests are free functions or methods on a `Void::Testing::Fixture` subclass
returning `Void::Testing::Test` (or `Void::Testing::DisabledTest`).
Registration is automatic — the CMake test scanner parses each `.cpp` at
configure time and generates the registration shim. See `CLAUDE.md` for the
comment-metadata syntax (`// @tag`, `// @skip`).