feat(daemon,platform): add Unix-socket daemon core, split Linux platform backends, and fix CMake feature-carrier translation
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
This commit is contained in:
1 parent
55ea305528
commit
0bde74f739
20 files changed
+1194
-21
No files matched your search
+132
@@ -2,6 +2,7 @@
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Bridge/CMakeBridge.hpp>
|
||||
#include <Void/Build/Config/Frontend.hpp>
|
||||
#include <Void/Build/Daemon/Daemon.hpp>
|
||||
#include <Void/Build/Editor/CompDb.hpp>
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
#include <Void/Build/Graph/Graph.hpp>
|
||||
@@ -26,6 +27,7 @@
|
||||
#include <Void/Build/Watch/Watcher.hpp>
|
||||
#include <Void/Configuration/Argparse.hpp>
|
||||
#include <Void/Configuration/Env.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <Void/System/SignalWatcher.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
@@ -1529,6 +1531,109 @@ int execute_gc_command(const GcCmdOptions &opts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct DaemonCmdOptions {
|
||||
std::string project_arg;
|
||||
std::optional<std::string> build_arg;
|
||||
std::optional<std::string> socket_arg;
|
||||
std::string max_bytes_arg{"0"};
|
||||
std::string max_requests_arg{"0"};
|
||||
};
|
||||
|
||||
std::filesystem::path resolve_daemon_socket(const DaemonCmdOptions &opts,
|
||||
const std::filesystem::path &build_root) {
|
||||
return opts.socket_arg ? std::filesystem::path{*opts.socket_arg}
|
||||
: build_root / ".vbs" / "vbs-daemon.sock";
|
||||
}
|
||||
|
||||
int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
const std::filesystem::path project_root{opts.project_arg};
|
||||
const std::filesystem::path build_root =
|
||||
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
||||
const auto socket_path = resolve_daemon_socket(opts, build_root);
|
||||
|
||||
if (sub == "run") {
|
||||
std::size_t max_requests = 0;
|
||||
const auto [ptr, ec] = std::from_chars(
|
||||
opts.max_requests_arg.data(),
|
||||
opts.max_requests_arg.data() + opts.max_requests_arg.size(), max_requests);
|
||||
if (ec != std::errc{} ||
|
||||
ptr != opts.max_requests_arg.data() + opts.max_requests_arg.size()) {
|
||||
std::cerr << "vbs daemon run: invalid --max-requests value '" << opts.max_requests_arg
|
||||
<< "'\n";
|
||||
return 2;
|
||||
}
|
||||
Daemon::DaemonOptions daemon_opts;
|
||||
daemon_opts.project_root = project_root;
|
||||
daemon_opts.build_root = build_root;
|
||||
daemon_opts.socket_path = socket_path;
|
||||
daemon_opts.max_requests = max_requests;
|
||||
auto server = Daemon::DaemonServer::create(std::move(daemon_opts));
|
||||
if (!server) {
|
||||
std::cerr << "vbs daemon: " << server.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
Void::Log::info("Daemon", "Serving '{}' (Ctrl+C to stop)...", socket_path.string());
|
||||
std::stop_source stop_src;
|
||||
auto sig = Void::Process::SignalWatcher::create();
|
||||
std::jthread sig_thread([&] {
|
||||
if (sig) {
|
||||
(void)sig->wait();
|
||||
stop_src.request_stop();
|
||||
}
|
||||
});
|
||||
auto result = server->run(stop_src.get_token());
|
||||
if (!result) {
|
||||
std::cerr << "vbs daemon: " << result.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string request_json;
|
||||
if (sub == "status") {
|
||||
request_json = R"({"op":"status"})";
|
||||
} else if (sub == "stop") {
|
||||
request_json = R"({"op":"shutdown"})";
|
||||
} else if (sub == "recover") {
|
||||
request_json = R"({"op":"recover"})";
|
||||
} else if (sub == "gc") {
|
||||
std::uint64_t max_bytes = 0;
|
||||
const auto [ptr, ec] =
|
||||
std::from_chars(opts.max_bytes_arg.data(),
|
||||
opts.max_bytes_arg.data() + opts.max_bytes_arg.size(), max_bytes);
|
||||
if (ec != std::errc{} || ptr != opts.max_bytes_arg.data() + opts.max_bytes_arg.size()) {
|
||||
std::cerr << "vbs daemon gc: invalid --max-bytes value '" << opts.max_bytes_arg
|
||||
<< "'\n";
|
||||
return 2;
|
||||
}
|
||||
request_json = std::format(R"({{"op":"gc","max_bytes":{}}})", max_bytes);
|
||||
} else {
|
||||
std::cerr << "vbs daemon: unknown command '" << sub << "'\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
auto response = Daemon::request(socket_path, request_json);
|
||||
if (!response) {
|
||||
std::cerr << "vbs daemon: " << response.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << *response << '\n';
|
||||
const auto parsed = Void::Json::Strict::parse(*response);
|
||||
if (!parsed) {
|
||||
return 1;
|
||||
}
|
||||
const auto *object = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
|
||||
if (object == nullptr) {
|
||||
return 1;
|
||||
}
|
||||
const auto ok = object->find("ok");
|
||||
if (ok == object->end()) {
|
||||
return 1;
|
||||
}
|
||||
const auto *flag = std::get_if<bool>(&ok->second.value);
|
||||
return (flag != nullptr && *flag) ? 0 : 1;
|
||||
}
|
||||
|
||||
struct GenTestsCmdOptions {
|
||||
std::optional<std::string> input_arg;
|
||||
std::optional<std::string> out_arg;
|
||||
@@ -2185,6 +2290,8 @@ int main(int argc, char **argv) {
|
||||
graph_opts.project_arg = cwd;
|
||||
IdeCmdOptions ide_opts;
|
||||
ide_opts.project_arg = cwd;
|
||||
DaemonCmdOptions daemon_opts;
|
||||
daemon_opts.project_arg = cwd;
|
||||
|
||||
auto add_log_flags = [&](Void::Argparse::Parser &p, bool allow_short_v = true) {
|
||||
p.flag("--verbose", allow_short_v ? "-v" : "", "Enable verbose debug logs", verbose)
|
||||
@@ -2406,6 +2513,28 @@ int main(int argc, char **argv) {
|
||||
configure_ide_common(
|
||||
ide_cmd.subcommand("query", "Emit versioned JSON workspace, target, and compdb metadata"));
|
||||
|
||||
auto &daemon_cmd = root.subcommand("daemon", "Run or control the persistent build daemon");
|
||||
auto configure_daemon_common = [&](Void::Argparse::Parser &p) {
|
||||
p.option_default("--project", "-C", "Project directory", daemon_opts.project_arg, cwd)
|
||||
.option("--build-dir", "-B", "Build output directory", daemon_opts.build_arg)
|
||||
.option("--socket", "", "Unix socket path (default: <build>/.vbs/vbs-daemon.sock)",
|
||||
daemon_opts.socket_arg);
|
||||
add_log_flags(p);
|
||||
};
|
||||
auto &daemon_run_cmd = daemon_cmd.subcommand("run", "Run the daemon in the foreground");
|
||||
configure_daemon_common(daemon_run_cmd);
|
||||
daemon_run_cmd.option_default("--max-requests", "", "Stop after N requests (0 = unlimited)",
|
||||
daemon_opts.max_requests_arg, "0");
|
||||
configure_daemon_common(daemon_cmd.subcommand("status", "Query the running daemon's status"));
|
||||
configure_daemon_common(daemon_cmd.subcommand("stop", "Ask the running daemon to shut down"));
|
||||
configure_daemon_common(
|
||||
daemon_cmd.subcommand("recover", "Run interrupted-state recovery in the daemon"));
|
||||
auto &daemon_gc_cmd = daemon_cmd.subcommand("gc", "Run CAS garbage collection in the daemon");
|
||||
configure_daemon_common(daemon_gc_cmd);
|
||||
daemon_gc_cmd.option_default("--max-bytes", "",
|
||||
"Target maximum retained CAS bytes (0=unreferenced only)",
|
||||
daemon_opts.max_bytes_arg, "0");
|
||||
|
||||
const auto parsed = root.parse_detailed(argc, argv);
|
||||
if (parsed.is_help()) {
|
||||
std::cout << parsed.message;
|
||||
@@ -2496,6 +2625,9 @@ int main(int argc, char **argv) {
|
||||
if (cmd == "ide") {
|
||||
return execute_ide_command(parsed.matched_command_path.at(1), ide_opts);
|
||||
}
|
||||
if (cmd == "daemon") {
|
||||
return execute_daemon_command(parsed.matched_command_path.at(1), daemon_opts);
|
||||
}
|
||||
|
||||
std::cerr << "vbs: unhandled subcommand '" << cmd << "'\n";
|
||||
return 2;
|
||||
|
||||
Reference in new issue
Block a user