feat(provenance,daemon): add Ed25519 signing primitives and bounded daemon describe op
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 9s

This commit is contained in:
faumaray committed 2026-12-03 17:30:12 +03:00
1 parent 0bde74f739
commit 21babb8c31
16 files changed
+1232 -20

No files matched your search

+154
View File
@@ -1,10 +1,16 @@
#include <Void/Build/Daemon/Daemon.hpp>
#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Build/Watch/Watcher.hpp>
#include <Void/Data/StrictJson.hpp>
#include <Void/Functional/Error.hpp>
#include <algorithm>
#include <cerrno>
#include <chrono>
#include <cstddef>
@@ -13,6 +19,7 @@
#include <fcntl.h>
#include <format>
#include <limits>
#include <optional>
#include <poll.h>
#include <string>
#include <string_view>
@@ -23,6 +30,7 @@
#include <unistd.h>
#include <utility>
#include <variant>
#include <vector>
namespace Void::Build::Daemon {
namespace {
@@ -35,6 +43,10 @@ constexpr std::size_t kMaxJsonDepth = 16U;
constexpr int kListenBacklog = 8;
constexpr auto kClientIoTimeout = std::chrono::milliseconds{2000};
constexpr auto kProbeTimeout = std::chrono::milliseconds{1000};
constexpr auto kDescribeEvalTimeout = std::chrono::seconds{10};
constexpr std::size_t kMaxDescribeProfileBytes = 128U;
constexpr std::size_t kMaxDescribeTargetNames = 128U;
constexpr std::size_t kMaxDescribeTargetNameBytes = 200U;
Void::Result::Error make_error(Void::Result::ErrorKind kind, std::string message,
int system_errno = 0) {
@@ -279,6 +291,119 @@ std::string ok_response(std::string_view op) {
return serialize_response(JsonValue{std::move(object)});
}
// Mirrors the executable's frontend option construction: SDK include/source roots come from the
// generated BootstrapConfig, and the prebuilt SDK archive is discovered from the running binary
// or the configured binary directory.
Config::FrontendOptions make_frontend_options(const DaemonOptions &options) {
Config::FrontendOptions frontend;
frontend.project_root = options.project_root;
frontend.build_root = options.build_root;
frontend.sdk_include_dir = std::filesystem::path{Bootstrap::sdk_include_dir};
frontend.sdk_source_dir = std::filesystem::path{Bootstrap::sdk_source_dir};
frontend.eval_timeout = kDescribeEvalTimeout;
std::error_code ec;
std::vector<std::filesystem::path> sdk_candidates;
if (const auto self_exe = std::filesystem::read_symlink("/proc/self/exe", ec);
!ec && !self_exe.empty()) {
const auto self_root = self_exe.parent_path().parent_path();
sdk_candidates.push_back(self_root / "libVoidBuildSdk.a");
sdk_candidates.push_back(self_root / "libVoidBuild_Sdk.a");
sdk_candidates.push_back(self_root / "lib" / "libVoidBuildSdk.a");
}
if (!Bootstrap::binary_dir.empty()) {
const auto bin_dir = std::filesystem::path{Bootstrap::binary_dir};
sdk_candidates.push_back(bin_dir / "libVoidBuild_Sdk.a");
sdk_candidates.push_back(bin_dir / "out" / "libVoidBuildSdk.a");
sdk_candidates.push_back(bin_dir / "profiles" / "debug" / "out" / "libVoidBuildSdk.a");
}
for (const auto &candidate : sdk_candidates) {
if (std::filesystem::is_regular_file(candidate, ec)) {
frontend.sdk_library_path = candidate;
break;
}
}
return frontend;
}
// Evaluates the project description in-process and lowers it to a bounded graph summary.
// Workspace roots are rejected explicitly: member selection belongs to the CLI.
std::string describe_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
if (Config::is_workspace_root(options.project_root)) {
return error_response("describe: workspace roots are not supported by the daemon yet");
}
const auto frontend = make_frontend_options(options);
auto compiled = Config::compile_descriptor(frontend);
if (!compiled) {
return error_response(std::format("describe: {}", compiled.error().format()));
}
auto profiles = Config::discover_profiles(*compiled, frontend);
if (!profiles) {
return error_response(std::format("describe: {}", profiles.error().format()));
}
ProfileContext context;
try {
context = profiles->resolve(profile_name, compiler_override, Toolchain::host_os_name(),
Toolchain::host_architecture_name());
} catch (const std::exception &ex) {
return error_response(std::format("describe: {}", ex.what()));
}
auto description = Config::evaluate_project(*compiled, context, frontend);
if (!description) {
return error_response(std::format("describe: {}", description.error().format()));
}
auto toolchain = Toolchain::discover_and_probe(context, options.build_root / ".vbs" / "probes");
if (!toolchain) {
return error_response(std::format("describe: {}", toolchain.error().format()));
}
Graph::GraphLowerOptions lower_options;
lower_options.project_root = options.project_root;
lower_options.build_root = options.build_root;
auto graph = Graph::lower_project_graph(*description, *toolchain, lower_options);
if (!graph) {
return error_response(std::format("describe: {}", graph.error().format()));
}
std::vector<std::string> target_names;
target_names.reserve(graph->targets.size());
for (const auto &target : graph->targets) {
target_names.push_back(target.name);
}
std::ranges::sort(target_names);
bool truncated = false;
if (target_names.size() > kMaxDescribeTargetNames) {
target_names.resize(kMaxDescribeTargetNames);
truncated = true;
}
JsonValue::Array names_json;
names_json.reserve(target_names.size());
for (auto &name : target_names) {
if (name.size() > kMaxDescribeTargetNameBytes) {
name.resize(kMaxDescribeTargetNameBytes);
truncated = true;
}
names_json.emplace_back(std::move(name));
}
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"describe"}});
object.emplace("profile", JsonValue{context.name});
object.emplace("targets", JsonValue{static_cast<std::int64_t>(graph->targets.size())});
object.emplace("actions", JsonValue{static_cast<std::int64_t>(graph->actions.size())});
object.emplace("target_names", JsonValue{std::move(names_json)});
if (truncated) {
object.emplace("target_names_truncated", JsonValue{true});
}
return serialize_response(JsonValue{std::move(object)});
}
} // namespace
struct DaemonServer::Impl {
@@ -386,6 +511,35 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "status") {
return {status_response(), false};
}
if (*name == "describe") {
std::string profile_name{"debug"};
if (const auto entry = object->find("profile"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr) {
return {error_response("\"profile\" must be a string"), false};
}
if (value->empty()) {
return {error_response("\"profile\" must not be empty"), false};
}
if (value->size() > kMaxDescribeProfileBytes) {
return {error_response("\"profile\" is too long"), false};
}
profile_name = *value;
}
std::optional<CompilerFamily> compiler_override;
if (const auto entry = object->find("compiler"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr) {
return {error_response("\"compiler\" must be a string"), false};
}
try {
compiler_override = parse_compiler(*value);
} catch (const std::exception &ex) {
return {error_response(ex.what()), false};
}
}
return {describe_project(options, profile_name, compiler_override), false};
}
if (*name == "shutdown") {
return {ok_response("shutdown"), true};
}