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

+28 -2
View File
@@ -1580,6 +1580,8 @@ struct DaemonCmdOptions {
std::optional<std::string> build_arg;
std::optional<std::string> socket_arg;
std::string profile_arg{"debug"};
std::vector<std::string> targets;
std::string jobs_arg{"0"};
std::string max_bytes_arg{"0"};
std::string max_requests_arg{"0"};
};
@@ -1659,6 +1661,22 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
}
request_json =
std::format(R"({{"op":"describe","profile":{}}})", Util::json_quote(opts.profile_arg));
} else if (sub == "build") {
std::size_t jobs = 0;
const auto [ptr, ec] = std::from_chars(opts.jobs_arg.data(),
opts.jobs_arg.data() + opts.jobs_arg.size(), jobs);
if (ec != std::errc{} || ptr != opts.jobs_arg.data() + opts.jobs_arg.size() || jobs > 256) {
std::cerr << "vbs daemon build: invalid --jobs value '" << opts.jobs_arg << "'\n";
return 2;
}
if (opts.profile_arg.empty()) {
std::cerr << "vbs daemon build: --profile must not be empty\n";
return 2;
}
const std::string targets_json = Util::json_array(
opts.targets, [](const std::string &target) { return Util::json_quote(target); });
request_json = std::format(R"({{"op":"build","profile":{},"targets":{},"jobs":{}}})",
Util::json_quote(opts.profile_arg), targets_json, jobs);
} else {
std::cerr << "vbs daemon: unknown command '" << sub << "'\n";
return 2;
@@ -1666,8 +1684,9 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
// Describe evaluates the whole project graph (descriptor compile, toolchain probe, lowering),
// which can exceed the 2 s default; the daemon bounds evaluation at 10 s.
const auto request_timeout =
sub == "describe" ? std::chrono::milliseconds{15000} : std::chrono::milliseconds{2000};
const auto request_timeout = sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
: sub == "describe" ? std::chrono::milliseconds{15000}
: std::chrono::milliseconds{2000};
auto response = Daemon::request(socket_path, request_json, request_timeout);
if (!response) {
std::cerr << "vbs daemon: " << response.error().message() << '\n';
@@ -2600,6 +2619,13 @@ int main(int argc, char **argv) {
configure_daemon_common(daemon_describe_cmd);
daemon_describe_cmd.option_default("--profile", "-p", "Profile to evaluate",
daemon_opts.profile_arg, "debug");
auto &daemon_build_cmd = daemon_cmd.subcommand("build", "Build a project graph via the daemon");
configure_daemon_common(daemon_build_cmd);
daemon_build_cmd
.option_default("--profile", "-p", "Profile to build", daemon_opts.profile_arg, "debug")
.option_many("--target", "-t", "Target to build", daemon_opts.targets)
.option_default("--jobs", "-j", "Maximum parallel jobs (0 = hardware concurrency)",
daemon_opts.jobs_arg, "0");
const auto parsed = root.parse_detailed(argc, argv);
if (parsed.is_help()) {