feat(workspace): add multi-package workspace builds with shared lock and CAS
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s

- SDK: Workspace/workspace() declaration plus Project::workspace_dependency()
- Frontend: workspace.cpp discovery/evaluation alongside build.cpp
- Main: per-member builds sharing the root vbs.lock and build/.vbs CAS, --member and --changed-since selection
- Cross-member native linking; member builds do not steal the root compile_commands.json alias
- Path-dependency snapshots exclude generated editor metadata
- Verified in Docker GCC 16: 8/8 CTest suites; 3-member workspace fixture with unified lockfile
This commit is contained in:
faumaray committed 2026-12-03 13:07:09 +03:00
1 parent 09c0a91d1d
commit 2970fbe25c
12 files changed
+515 -19

No files matched your search

+130 -5
View File
@@ -32,7 +32,8 @@ bool is_cpp_file(const std::filesystem::path &p) {
return ext == ".cpp" || ext == ".cc" || ext == ".cxx";
}
std::string generate_driver_source(bool has_profiles_file) {
std::string generate_driver_source(bool has_profiles_file, bool has_build_file,
bool has_workspace_file) {
std::string code = R"cpp(#include <Void/Build.hpp>
#include <Void/Build/Util/Json.hpp>
@@ -49,6 +50,18 @@ std::string generate_driver_source(bool has_profiles_file) {
code += R"cpp(void profiles(Void::Build::Profiles &descriptions) {
descriptions = Void::Build::default_profiles();
}
)cpp";
}
if (!has_build_file) {
code += R"cpp(void build(Void::Build::Project &) {
throw std::runtime_error{"this descriptor declares no build() entry point"};
}
)cpp";
}
if (!has_workspace_file) {
code += R"cpp(void workspace(Void::Build::Workspace &) {
throw std::runtime_error{"this descriptor declares no workspace() entry point"};
}
)cpp";
}
code += R"cpp(
@@ -166,6 +179,16 @@ int main(int argc, char **argv) {
write_text(output_path, payload);
return 0;
}
if (mode == "workspace") {
Void::Build::Workspace ws;
workspace(ws);
const std::string payload =
"{\"protocol_version\":1,\"request_id\":" +
Void::Build::Util::json_quote(request_id) +
",\"payload\":" + ws.to_json() + "}\n";
write_text(output_path, payload);
return 0;
}
std::cerr << "vbs-config-driver: unknown mode '" << mode << "'\n";
return 2;
} catch (const std::exception &err) {
@@ -257,9 +280,13 @@ discover_config_sources(const std::filesystem::path &project_root,
}
const auto root_build = canonical_root / "build.cpp";
if (!std::filesystem::is_regular_file(root_build, ec)) {
const auto root_workspace = canonical_root / "workspace.cpp";
const bool has_build = std::filesystem::is_regular_file(root_build, ec);
const bool has_workspace = std::filesystem::is_regular_file(root_workspace, ec);
if (!has_build && !has_workspace) {
return std::unexpected{
make_error(std::format("missing required root description '{}'", root_build.string()))};
make_error(std::format("missing required root description '{}' or '{}'",
root_build.string(), root_workspace.string()))};
}
std::vector<std::filesystem::path> sources;
@@ -271,7 +298,12 @@ discover_config_sources(const std::filesystem::path &project_root,
}
};
push(root_build);
if (has_build) {
push(root_build);
}
if (has_workspace) {
push(root_workspace);
}
const auto profiles_cpp = canonical_root / "build.profiles.cpp";
if (std::filesystem::is_regular_file(profiles_cpp, ec)) {
@@ -349,7 +381,10 @@ compile_descriptor(const FrontendOptions &options) {
const bool has_profiles =
std::filesystem::is_regular_file(canonical_root / "build.profiles.cpp", ec);
const std::string driver_src = generate_driver_source(has_profiles);
const bool has_build = std::filesystem::is_regular_file(canonical_root / "build.cpp", ec);
const bool has_workspace =
std::filesystem::is_regular_file(canonical_root / "workspace.cpp", ec);
const std::string driver_src = generate_driver_source(has_profiles, has_build, has_workspace);
const auto driver_cpp = config_dir / "Driver.cpp";
if (auto wrote = Platform::atomic_write_file(driver_cpp, driver_src, false); !wrote) {
return std::unexpected{wrote.error()};
@@ -552,6 +587,11 @@ compile_descriptor(const FrontendOptions &options) {
return desc;
}
bool is_workspace_root(const std::filesystem::path &project_root) {
std::error_code ec;
return std::filesystem::is_regular_file(project_root / "workspace.cpp", ec);
}
Void::Result::Result<Profiles, Void::Result::Error>
discover_profiles(const CompiledDescriptor &descriptor, const FrontendOptions &options) {
std::error_code ec;
@@ -763,4 +803,89 @@ evaluate_project(const CompiledDescriptor &descriptor, const ProfileContext &con
return desc;
}
Void::Result::Result<WorkspaceDescription, Void::Result::Error>
evaluate_workspace(const CompiledDescriptor &descriptor, const FrontendOptions &options) {
std::error_code ec;
const auto run_dir =
std::filesystem::weakly_canonical(options.build_root, ec) / ".vbs" / "config" / "eval";
std::filesystem::create_directories(run_dir, ec);
const std::string req_id = std::format("ws_{}_{}", static_cast<long long>(::getpid()),
g_req_seq.fetch_add(1, std::memory_order_relaxed));
const auto out_file = run_dir / (req_id + ".json");
Platform::ProcessRequest req;
req.executable = descriptor.executable_path;
req.arguments = {"--mode", "workspace", "--output", out_file.string(), "--request-id", req_id};
req.working_directory = options.project_root;
req.timeout = options.eval_timeout;
auto proc = Platform::run_supervised(req);
auto cleanup = [&] { std::filesystem::remove(out_file, ec); };
if (!proc) {
cleanup();
return std::unexpected{proc.error()};
}
if (!proc->succeeded()) {
cleanup();
return std::unexpected{
make_error(std::format("workspace evaluation failed (exit={}, signal={}): {}",
proc->exit_code, proc->term_signal, proc->stderr_data))};
}
auto text = Void::FileSystem::read_file_bounded(out_file, {16ULL * 1024ULL * 1024ULL});
cleanup();
if (!text) {
return std::unexpected{make_error("workspace evaluation did not produce a result file")};
}
if (!Util::is_valid_utf8(*text)) {
return std::unexpected{make_error("workspace evaluation result contains invalid UTF-8")};
}
auto parsed = Void::Json::Strict::parse(*text);
if (!parsed) {
return std::unexpected{make_error("workspace evaluation emitted malformed JSON")};
}
const auto *root = std::get_if<JsonVal::Object>(&parsed->value);
if (!root) {
return std::unexpected{make_error("workspace evaluation envelope must be a JSON object")};
}
if (get_i64(*root, "protocol_version").value_or(0) != kFrontendProtocolVersion) {
return std::unexpected{make_error("workspace evaluation protocol version mismatch")};
}
if (get_str(*root, "request_id").value_or("") != req_id) {
return std::unexpected{make_error("workspace evaluation request_id mismatch")};
}
const auto *payload_v = find_key(*root, "payload");
const auto *payload = payload_v ? std::get_if<JsonVal::Object>(&payload_v->value) : nullptr;
if (!payload) {
return std::unexpected{make_error("workspace evaluation missing payload")};
}
const auto *members_v = find_key(*payload, "members");
const auto *arr = members_v ? std::get_if<JsonVal::Array>(&members_v->value) : nullptr;
if (!arr) {
return std::unexpected{make_error("workspace evaluation payload missing members array")};
}
WorkspaceDescription result;
std::set<std::string> seen;
for (const auto &mv : *arr) {
const auto *mobj = std::get_if<JsonVal::Object>(&mv.value);
if (!mobj) {
continue;
}
WorkspaceMember member;
member.name = get_str(*mobj, "name").value_or("");
member.path = get_str(*mobj, "path").value_or("");
if (member.name.empty() || member.path.empty()) {
return std::unexpected{make_error("workspace member requires nonempty name and path")};
}
if (!seen.insert(member.name).second) {
return std::unexpected{make_error("duplicate workspace member '" + member.name + "'")};
}
result.members.push_back(std::move(member));
}
return result;
}
} // namespace Void::Build::Config