feat(daemon): serve IDE workspace and compdb metadata over the Unix socket
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 1m2s

This commit is contained in:
faumaray committed 2026-12-03 20:08:20 +03:00
1 parent e97f3905e5
commit 118c0dc860
9 files changed
+152 -8

No files matched your search

+47 -1
View File
@@ -3,6 +3,7 @@
#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Editor/CompDb.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Package/Lockfile.hpp>
@@ -12,6 +13,7 @@
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Build/Util/Json.hpp>
#include <Void/Build/Watch/Watcher.hpp>
#include <Void/Configuration/Env.hpp>
#include <Void/Data/StrictJson.hpp>
@@ -557,6 +559,47 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
return serialize_response(JsonValue{std::move(object)});
}
// Publishes the profile compilation database and returns the IDE query metadata JSON.
std::string ide_query_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "ide_query");
if (!evaluated) {
return error_response(evaluated.error());
}
auto graph = lower_graph(options, *evaluated, {}, "ide_query");
if (!graph) {
return error_response(graph.error());
}
const auto frontend = make_frontend_options(options);
const auto existing_selection =
Editor::read_selection_state(options.project_root).value_or(std::nullopt);
Editor::PublishOptions publish;
publish.project_root = options.project_root;
publish.build_root = options.build_root;
publish.update_selection = !existing_selection.has_value();
publish.sdk_include_dir = frontend.sdk_include_dir;
auto published = Editor::publish_profile_compdb(*graph, publish);
if (!published) {
return error_response(std::format("ide_query: {}", published.error().format()));
}
std::error_code ec;
const auto root_compdb = options.build_root / "compile_commands.json";
const auto compdb_path =
std::filesystem::exists(root_compdb, ec) ? root_compdb : published->compdb_path;
std::string query =
Editor::format_ide_query_json(*graph, compdb_path, frontend.sdk_include_dir);
// The socket protocol is one JSON object per line: the embedded query must not contain
// newlines before the final response terminator.
while (!query.empty() && (query.back() == '\n' || query.back() == '\r')) {
query.pop_back();
}
return "{\"ok\":true,\"op\":\"ide_query\",\"compdb\":" +
Util::json_quote(compdb_path.string()) + ",\"query\":" + query + '}';
}
// 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) {
@@ -713,7 +756,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "status") {
return {status_response(), false};
}
if (*name == "describe" || *name == "build") {
if (*name == "describe" || *name == "build" || *name == "ide_query") {
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);
@@ -743,6 +786,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "describe") {
return {describe_project(options, profile_name, compiler_override), false};
}
if (*name == "ide_query") {
return {ide_query_project(options, profile_name, compiler_override), false};
}
std::vector<std::string> selected_targets;
if (const auto entry = object->find("targets"); entry != object->end()) {
+23 -3
View File
@@ -1443,6 +1443,13 @@ 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 == "ide_query") {
if (opts.profile_arg.empty()) {
std::cerr << "vbs daemon ide query: --profile must not be empty\n";
return 2;
}
request_json =
std::format(R"({{"op":"ide_query","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(),
@@ -1467,8 +1474,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 == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
: sub == "describe" ? std::chrono::milliseconds{15000}
: std::chrono::milliseconds{2000};
: sub == "describe" ? std::chrono::milliseconds{15000}
: sub == "ide_query" ? std::chrono::milliseconds{30000}
: std::chrono::milliseconds{2000};
auto response = Daemon::request(socket_path, request_json, request_timeout);
if (!response) {
std::cerr << "vbs daemon: " << response.error().message() << '\n';
@@ -2411,6 +2419,13 @@ int main(int argc, char **argv) {
.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");
auto &daemon_ide_cmd = daemon_cmd.subcommand("ide", "Editor/IDE metadata served by the daemon");
configure_daemon_common(daemon_ide_cmd);
auto &daemon_ide_query_cmd =
daemon_ide_cmd.subcommand("query", "Emit IDE workspace/target/compdb metadata JSON");
configure_daemon_common(daemon_ide_query_cmd);
daemon_ide_query_cmd.option_default("--profile", "-p", "Profile to query",
daemon_opts.profile_arg, "debug");
const auto parsed = root.parse_detailed(argc, argv);
if (parsed.is_help()) {
@@ -2503,7 +2518,12 @@ int main(int argc, char **argv) {
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::string daemon_sub = parsed.matched_command_path.at(1);
if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
parsed.matched_command_path[2] == "query") {
daemon_sub = "ide_query";
}
return execute_daemon_command(daemon_sub, daemon_opts);
}
std::cerr << "vbs: unhandled subcommand '" << cmd << "'\n";