feat(daemon): serve bounded in-process build requests over the Unix socket
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 10s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 16s

This commit is contained in:
faumaray committed 2026-12-03 18:07:10 +03:00
1 parent 85f2ae274f
commit 55272d3e6b
8 files changed
+238 -28

No files matched your search

+125 -22
View File
@@ -3,6 +3,7 @@
#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
@@ -47,6 +48,7 @@ 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;
constexpr std::size_t kMaxBuildTargets = 64U;
Void::Result::Error make_error(Void::Result::ErrorKind kind, std::string message,
int system_errno = 0) {
@@ -326,39 +328,48 @@ Config::FrontendOptions make_frontend_options(const DaemonOptions &options) {
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) {
struct EvaluatedProject {
ProfileContext context;
Graph::BuildGraph graph;
};
// Evaluates the project description in-process and lowers its graph. Workspace roots are
// rejected explicitly: member selection belongs to the CLI.
Void::Result::Result<EvaluatedProject, std::string>
evaluate_project_graph(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override, std::string_view op) {
if (Config::is_workspace_root(options.project_root)) {
return error_response("describe: workspace roots are not supported by the daemon yet");
return std::unexpected{
std::format("{}: workspace roots are not supported by the daemon yet", op)};
}
const auto frontend = make_frontend_options(options);
auto compiled = Config::compile_descriptor(frontend);
if (!compiled) {
return error_response(std::format("describe: {}", compiled.error().format()));
return std::unexpected{std::format("{}: {}", op, compiled.error().format())};
}
auto profiles = Config::discover_profiles(*compiled, frontend);
if (!profiles) {
return error_response(std::format("describe: {}", profiles.error().format()));
return std::unexpected{std::format("{}: {}", op, profiles.error().format())};
}
ProfileContext context;
EvaluatedProject evaluated;
try {
context = profiles->resolve(profile_name, compiler_override, Toolchain::host_os_name(),
Toolchain::host_architecture_name());
evaluated.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()));
return std::unexpected{std::format("{}: {}", op, ex.what())};
}
auto description = Config::evaluate_project(*compiled, context, frontend);
auto description = Config::evaluate_project(*compiled, evaluated.context, frontend);
if (!description) {
return error_response(std::format("describe: {}", description.error().format()));
return std::unexpected{std::format("{}: {}", op, description.error().format())};
}
auto toolchain = Toolchain::discover_and_probe(context, options.build_root / ".vbs" / "probes");
auto toolchain =
Toolchain::discover_and_probe(evaluated.context, options.build_root / ".vbs" / "probes");
if (!toolchain) {
return error_response(std::format("describe: {}", toolchain.error().format()));
return std::unexpected{std::format("{}: {}", op, toolchain.error().format())};
}
Graph::GraphLowerOptions lower_options;
@@ -366,12 +377,71 @@ std::string describe_project(const DaemonOptions &options, std::string_view prof
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()));
return std::unexpected{std::format("{}: {}", op, graph.error().format())};
}
evaluated.graph = std::move(*graph);
return evaluated;
}
// Bounded build-serving request: lowers the project graph and executes it in-process against the
// daemon's warm StateStore. Dependency materialization belongs to `vbs build`/`vbs deps`.
std::string build_project(const DaemonOptions &options, State::StateStore &state,
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "build");
if (!evaluated) {
return error_response(evaluated.error());
}
Execution::ExecutionOptions exec_options;
exec_options.jobs = jobs;
exec_options.selected_targets = selected_targets;
auto report = Execution::execute_graph(evaluated->graph, state, exec_options);
if (!report) {
return error_response(std::format("build: {}", report.error().format()));
}
JsonValue::Array failed_actions;
for (const auto &result : report->results) {
if (!result.succeeded) {
JsonValue::Object failure;
failure.emplace("action", JsonValue{result.action_id});
failure.emplace("target", JsonValue{result.target_name});
failure.emplace("error", JsonValue{result.error_message});
failed_actions.emplace_back(std::move(failure));
}
}
JsonValue::Object object;
object.emplace("ok", JsonValue{report->succeeded});
object.emplace("op", JsonValue{std::string{"build"}});
object.emplace("profile", JsonValue{evaluated->context.name});
object.emplace("targets",
JsonValue{static_cast<std::int64_t>(evaluated->graph.targets.size())});
object.emplace("actions",
JsonValue{static_cast<std::int64_t>(evaluated->graph.actions.size())});
object.emplace("executed", JsonValue{static_cast<std::int64_t>(report->executed_count)});
object.emplace("cached", JsonValue{static_cast<std::int64_t>(report->cached_count)});
object.emplace("failed", JsonValue{static_cast<std::int64_t>(report->failed_count)});
object.emplace("diagnostic", JsonValue{report->diagnostic});
object.emplace("failed_actions", JsonValue{std::move(failed_actions)});
return serialize_response(JsonValue{std::move(object)});
}
// Lowers the project graph to a bounded summary without executing it.
std::string describe_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "describe");
if (!evaluated) {
return error_response(evaluated.error());
}
const auto &graph = evaluated->graph;
const auto &context = evaluated->context;
std::vector<std::string> target_names;
target_names.reserve(graph->targets.size());
for (const auto &target : graph->targets) {
target_names.reserve(graph.targets.size());
for (const auto &target : graph.targets) {
target_names.push_back(target.name);
}
std::ranges::sort(target_names);
@@ -395,8 +465,8 @@ std::string describe_project(const DaemonOptions &options, std::string_view prof
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("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});
@@ -511,7 +581,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "status") {
return {status_response(), false};
}
if (*name == "describe") {
if (*name == "describe" || *name == "build") {
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);
@@ -538,7 +608,40 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
return {error_response(ex.what()), false};
}
}
return {describe_project(options, profile_name, compiler_override), false};
if (*name == "describe") {
return {describe_project(options, profile_name, compiler_override), false};
}
std::vector<std::string> selected_targets;
if (const auto entry = object->find("targets"); entry != object->end()) {
const auto *array = std::get_if<JsonValue::Array>(&entry->second.value);
if (array == nullptr) {
return {error_response("\"targets\" must be an array of strings"), false};
}
if (array->size() > kMaxBuildTargets) {
return {error_response("\"targets\" has too many entries"), false};
}
for (const auto &item : *array) {
const auto *text = std::get_if<std::string>(&item.value);
if (text == nullptr || text->empty() ||
text->size() > kMaxDescribeTargetNameBytes) {
return {error_response("\"targets\" entries must be non-empty bounded strings"),
false};
}
selected_targets.push_back(*text);
}
}
std::size_t jobs = 0;
if (const auto entry = object->find("jobs"); entry != object->end()) {
const auto *value = std::get_if<std::int64_t>(&entry->second.value);
if (value == nullptr || *value < 0 || *value > 256) {
return {error_response("\"jobs\" must be an integer in [0, 256]"), false};
}
jobs = static_cast<std::size_t>(*value);
}
return {build_project(options, state_store, profile_name, compiler_override,
selected_targets, jobs),
false};
}
if (*name == "shutdown") {
return {ok_response("shutdown"), true};