feat(core): Value, reflection, codecs and results, shared by app and client
Crafter.Debug.Core is what the app side and the crafter-debug client both need, without the session: - Value: a JSON value with its own parser and printer, so no consumer interface sees a JSON library. Integers stay integers and whole doubles stay doubles; NaN and the infinities, which JSON cannot spell, are written as strings rather than hidden, because a debugger must not lose a NaN; invalid UTF-8 is replaced so output always parses. Objects keep insertion order, the order an agent reads. - Reflect: aggregate members and names through structured-binding packs and source_location, taken from Crafter.DB, plus scoped-enum names by probing a range of values. Self-tested with static_asserts so a compiler that changes function_name()'s shape fails the build. - Codec<T>: encode, decode and describe for bool, integers, floating point, strings, enums, optional, vector, array, string-keyed maps, Value, Required<T> and every aggregate. Decode reports every problem in a call with its path and, for a typo, the likely intended name, and never throws: a bad call cannot take an app down, which a wrongly typed parameter could in 3DForts' hand-written from_json. - Result, Error and Async: handler results, including ones that take frames to arrive, so callers need no ready:false polling. project.cpp now builds Crafter.Debug.Core as its own library, used by both the app library and the client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb2c06c32e
commit
89a12bcd61
13 changed files with 1951 additions and 11 deletions
59
project.cpp
59
project.cpp
|
|
@ -1,6 +1,14 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// Three configurations:
|
||||
// Crafter.Debug.Core what the app and the client share (values, codecs)
|
||||
// crafter.debug-cli the client, crafter-debug
|
||||
// Crafter.Debug what an app links (returned), depending on both
|
||||
// The client is one of the library's dependencies only so that a consumer's
|
||||
// debug build compiles it in the same pass as the app; an executable adds no
|
||||
// link flags to what depends on it. Consumers load this file through
|
||||
// Debug::Use (tooling/), which also writes their launcher.
|
||||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
|
@ -18,6 +26,13 @@ namespace {
|
|||
fs::path Root() {
|
||||
return fs::path(std::source_location::current().file_name()).parent_path();
|
||||
}
|
||||
|
||||
constexpr std::array<std::string_view, 4> tests = {
|
||||
"ShouldRoundTripJson",
|
||||
"ShouldRoundTripAggregates",
|
||||
"ShouldReportDecodeErrorsWithPaths",
|
||||
"ShouldDescribeDefaultsAndRequired",
|
||||
};
|
||||
}
|
||||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
||||
|
|
@ -27,17 +42,30 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
cfg.outputName = "Crafter.Debug";
|
||||
cfg.type = ConfigurationType::LibraryStatic;
|
||||
ApplyStandardArgs(cfg, args);
|
||||
|
||||
Configuration& core = owned.emplace_back();
|
||||
core.path = Root();
|
||||
core.name = "Crafter.Debug.Core";
|
||||
core.outputName = "Crafter.Debug.Core";
|
||||
core.type = ConfigurationType::LibraryStatic;
|
||||
ApplyStandardArgs(core, args);
|
||||
{
|
||||
std::array<fs::path, 1> interfaces = { "interfaces/Crafter.Debug" };
|
||||
std::array<fs::path, 0> implementations = {};
|
||||
cfg.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
std::array<fs::path, 5> interfaces = {
|
||||
"interfaces/Crafter.Debug.Core-Value",
|
||||
"interfaces/Crafter.Debug.Core-Reflect",
|
||||
"interfaces/Crafter.Debug.Core-Codec",
|
||||
"interfaces/Crafter.Debug.Core-Result",
|
||||
"interfaces/Crafter.Debug.Core",
|
||||
};
|
||||
std::array<fs::path, 2> implementations = {
|
||||
"implementations/Crafter.Debug.Core-Value",
|
||||
"implementations/Crafter.Debug.Core-Codec",
|
||||
};
|
||||
core.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
}
|
||||
|
||||
// The client, crafter-debug. One of the library's dependencies, so a
|
||||
// consumer's debug build compiles it in the same pass as the app; an
|
||||
// executable adds no link flags to what depends on it. Built for the same
|
||||
// target as the library, and not through ApplyStandardArgs, which would
|
||||
// turn it into a library when a consumer passes --lib.
|
||||
// The client, built for the library's target. Not through
|
||||
// ApplyStandardArgs: a consumer's --lib would make it a library.
|
||||
Configuration& client = owned.emplace_back();
|
||||
client.path = Root();
|
||||
client.name = "crafter.debug-cli";
|
||||
|
|
@ -48,11 +76,24 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
client.mtune = cfg.mtune;
|
||||
client.sysroot = cfg.sysroot;
|
||||
client.debug = cfg.debug;
|
||||
client.dependencies = { &core };
|
||||
{
|
||||
std::array<fs::path, 0> interfaces = {};
|
||||
std::array<fs::path, 1> implementations = { "implementations/main" };
|
||||
client.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
}
|
||||
cfg.dependencies.push_back(&client);
|
||||
|
||||
cfg.dependencies = { &core, &client };
|
||||
{
|
||||
std::array<fs::path, 1> interfaces = { "interfaces/Crafter.Debug" };
|
||||
std::array<fs::path, 0> implementations = {};
|
||||
cfg.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
}
|
||||
|
||||
// Tests only when this is the project being built: a consumer's load of
|
||||
// this file has no use for them.
|
||||
if (IsTopLevelProject()) {
|
||||
for (const std::string_view test : tests) cfg.AddTest(test).Dependencies({ &core });
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue