From 6cf8c53a02ed8029b995448969298c1913460e59 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 06:41:50 +0300 Subject: [PATCH] feat(ide): emit a CMake File API codemodel reply --- docs/agent-workflow/STATE.md | 2 + docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 10 + docs/roadmap/22-superiority-and-gaps.md | 2 +- src/Editor/CompDb.cpp | 239 ++++++++++++++++++++++-- tests/FullV1Tests.cpp | 99 ++++++++++ 6 files changed, 334 insertions(+), 19 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index ac54235..c26149c 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -294,6 +294,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 100 (CMakePresets Import)**: `Config::load_cmake_presets` parses `CMakePresets.json`-style configure presets (resolving `inherits` as a string or array with cycle detection), expands `${sourceDir}`, merges `cacheVariables`, and maps `CMAKE_BUILD_TYPE`/`CMAKE_CXX_COMPILER` onto VBS profile/compiler. The `vbs presets` CLI lists the mapping or prints the equivalent `vbs build` command for one preset; covered by `FullV1Tests.cmake_presets_import_maps_inherits_and_cache` and a CLI contract. +- **Wave 101 (CMake File API Shim)**: `vbs ide generate` now regenerates a CMake File API `codemodel-v2` reply tree (`build/.cmake/api/v1/reply/{index,codemodel-v2,directory,target-*}.json`) from the lowered graph, including per-target type, artifacts, `nameOnDisk`, sources, and compile groups (language, command fragments, defines, includes). Covered by `FullV1Tests.ide_integration_compdb_build_cpp_and_editor_configs_end_to_end`, which walks index → codemodel → target JSON. + ## Remaining future scope - **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index 660cad9..796ba97 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -104,4 +104,5 @@ Base HEAD: `fe0d1a6` | Wave 98 (Signed installer archives) | `--signing-key` writes `.sha256`/`.sig`/`.pub` for the installer archive and fails closed without a backend | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; install test passes, full CTest 8/8) | `include/Void/Build/Install/Installer.hpp`, `src/Install/Installer.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 99 (Windows path semantics) | Case-insensitive output collision + reserved device name validation for Windows targets; Wine case-insensitivity assertion | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Windows regression test passes, full CTest 8/8) | `src/Graph/Graph.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 100 (CMakePresets import) | `Config::load_cmake_presets` (inherits, `${sourceDir}`, cache merge, profile/compiler mapping) + `vbs presets` CLI | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; presets test passes, full CTest 8/8) | `include/Void/Build/Config/Presets.hpp`, `src/Config/Presets.cpp`, `src/Main.cpp`, `tests/{FullV1Tests,CliContracts}.cpp/cmake`, docs | +| Wave 101 (CMake File API shim) | `vbs ide generate` emits `.cmake/api/v1/reply` codemodel-v2 + directory + per-target JSON from the lowered graph | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; IDE integration test passes, full CTest 8/8) | `src/Editor/CompDb.cpp`, `tests/FullV1Tests.cpp`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 870fb2e..d45913f 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1418,6 +1418,16 @@ dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc -p wine64 -c build/pinned/bin/vbs_v1 - CLI contract: `vbs presets --help` passes. - Full CTest: **8 / 8 passed** in 276.96 s. +## CMake File API Shim (GCC 16.2, pin `0002e74`) + +- `vbs ide generate` writes `build/.cmake/api/v1/reply/` with an `index-*.json` listing + `codemodel-v2`, a `codemodel-v2-*.json` referencing a directory file and all target files, and + `target-*.json` per target (kind/type/artifacts/`nameOnDisk`/sources/compileGroups). +- All emitted JSON files validate as strict JSON (checked with a JSON parser during development). +- `ide_integration_compdb_build_cpp_and_editor_configs_end_to_end` walks index → codemodel → + target and asserts the executable target has artifacts and compile groups: **passed** (3.14 s). +- Full CTest: **8 / 8 passed** in 276.69 s. + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/docs/roadmap/22-superiority-and-gaps.md b/docs/roadmap/22-superiority-and-gaps.md index 5678779..f851286 100644 --- a/docs/roadmap/22-superiority-and-gaps.md +++ b/docs/roadmap/22-superiority-and-gaps.md @@ -78,7 +78,7 @@ Concrete work this implies: 1. Documentation drift: status tables must match verified reality (this plan updates them). 2. Wine-first Windows target support (§2). 3. Packaging parity: ZIP (stored), DEB, RPM, metadata, signing (`--archive-format` extensions). -4. IDE ecosystem: File API shim, presets import (**done**: `vbs presets`), external plugins. +4. IDE ecosystem: File API shim (**done**: `vbs ide generate` emits codemodel-v2), presets import (**done**: `vbs presets`), external plugins. 5. Migration tooling (`vbs migrate`) and migrating VoidLibrary onto VBS. 6. Test-runner parity. 7. Benchmarks against CMake/Meson/build2 on documented fixtures (including 10k-target scaling). diff --git a/src/Editor/CompDb.cpp b/src/Editor/CompDb.cpp index 4a3ab99..0a41bd2 100644 --- a/src/Editor/CompDb.cpp +++ b/src/Editor/CompDb.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -9,6 +10,7 @@ #include #include +#include namespace Void::Build::Editor { namespace { @@ -752,6 +754,12 @@ std::string_view ide_kind_name(IdeKind kind) { return "all"; } +namespace { +Void::Result::Result +emit_cmake_file_api(const Graph::BuildGraph &graph, const std::filesystem::path &project_root, + const std::filesystem::path &build_root); +} // namespace + Void::Result::Result generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &options) { using Util::json_array; @@ -797,6 +805,11 @@ generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &opt return {}; }; + // CMake File API metadata is always regenerated: it is IDE/build metadata owned by VBS. + if (auto emitted = emit_cmake_file_api(graph, proj_root, build_root); !emitted) { + return std::unexpected{emitted.error()}; + } + const bool want_all = (options.editor == IdeKind::All); // 1. .clangd configuration (GCC-16 flag sanitization + CompilationDatabase pointer). @@ -874,20 +887,17 @@ generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &opt vs_tasks.push_back(make_vs_task("vbs: refresh compile_commands.json", {"compdb", "export", "--profile", graph.profile.name}, "", false)); - vs_tasks.push_back(make_vs_task( - "vbs: install", - {"install", "--profile", graph.profile.name, "--prefix", - (options.build_root / "install").string(), - "--bundle-dependencies", - "--archive", (options.build_root / "install" / "installer.tar").string()}, - "", false)); + vs_tasks.push_back( + make_vs_task("vbs: install", + {"install", "--profile", graph.profile.name, "--prefix", + (options.build_root / "install").string(), "--bundle-dependencies", + "--archive", (options.build_root / "install" / "installer.tar").string()}, + "", false)); vs_tasks.push_back(make_vs_task( "vbs: package installer", {"install", "--profile", graph.profile.name, "--prefix", - (options.build_root / "install").string(), - "--bundle-dependencies", - "--archive", (options.build_root / "install" / "installer.sh").string(), - "--archive-format", "sh"}, + (options.build_root / "install").string(), "--bundle-dependencies", "--archive", + (options.build_root / "install" / "installer.sh").string(), "--archive-format", "sh"}, "", false)); for (const auto &tname : buildable_targets) { vs_tasks.push_back(make_vs_task( @@ -980,9 +990,8 @@ generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &opt ztasks.push_back(make_zed_task("vbs: test", {"test", "--profile", graph.profile.name})); ztasks.push_back(make_zed_task("vbs: clean", {"clean"})); ztasks.push_back(make_zed_task( - "vbs: install", - {"install", "--profile", graph.profile.name, "--prefix", - (options.build_root / "install").string(), "--bundle-dependencies"})); + "vbs: install", {"install", "--profile", graph.profile.name, "--prefix", + (options.build_root / "install").string(), "--bundle-dependencies"})); for (const auto &rt : runnables) { ztasks.push_back( make_zed_task("vbs: build " + rt.name, @@ -1080,8 +1089,7 @@ query_compdb_entries(const std::filesystem::path &compdb_path, const CompdbQuery const auto *entries = std::get_if(&parsed->value); if (!entries) { return std::unexpected{Void::System::make_system_error( - Void::System::SystemErrorCode::io_error, - "compilation database must be a JSON array")}; + Void::System::SystemErrorCode::io_error, "compilation database must be a JSON array")}; } CompdbQueryResult result; @@ -1099,8 +1107,7 @@ query_compdb_entries(const std::filesystem::path &compdb_path, const CompdbQuery if (file == nullptr) { continue; } - if (!query.file_filter.empty() && - !std::string_view{*file}.ends_with(query.file_filter)) { + if (!query.file_filter.empty() && !std::string_view{*file}.ends_with(query.file_filter)) { continue; } ++result.total; @@ -1141,6 +1148,202 @@ query_compdb_entries(const std::filesystem::path &compdb_path, const CompdbQuery return result; } +namespace { + +std::string file_api_target_type(TargetKind kind) { + switch (kind) { + case TargetKind::Executable: + case TargetKind::Test: + return "EXECUTABLE"; + case TargetKind::StaticLibrary: + return "STATIC_LIBRARY"; + case TargetKind::SharedLibrary: + return "SHARED_LIBRARY"; + case TargetKind::HeaderOnly: + return "INTERFACE_LIBRARY"; + case TargetKind::ObjectLibrary: + return "OBJECT_LIBRARY"; + case TargetKind::CustomAction: + return "UTILITY"; + } + return "UTILITY"; +} + +std::string safe_file_token(std::string_view text) { + std::string out; + for (const char c : text) { + out.push_back( + (std::isalnum(static_cast(c)) != 0 || c == '.' || c == '_' || c == '-') + ? c + : '_'); + } + return out.empty() ? std::string{"project"} : out; +} + +// Emits a CMake File API (codemodel-v2) reply tree so CMake-aware IDEs can consume VBS +// projects. The reply directory is entirely VBS-owned and regenerated on every run. +Void::Result::Result +emit_cmake_file_api(const Graph::BuildGraph &graph, const std::filesystem::path &project_root, + const std::filesystem::path &build_root) { + using Util::json_array; + using Util::json_quote; + + const auto reply_dir = build_root / ".cmake" / "api" / "v1" / "reply"; + std::error_code ec; + std::filesystem::remove_all(reply_dir, ec); + std::filesystem::create_directories(reply_dir, ec); + if (ec) { + return std::unexpected{Void::System::make_system_error( + Void::System::SystemErrorCode::io_error, + std::format("cannot create CMake File API reply directory '{}': {}", reply_dir.string(), + ec.message()))}; + } + + auto write_reply = + [&](const std::string &file_name, + std::string_view content) -> Void::Result::Result { + if (auto written = Platform::atomic_write_file(reply_dir / file_name, content, false); + !written) { + return std::unexpected{written.error()}; + } + return {}; + }; + + const std::string version_block = "{\"major\":2,\"minor\":0}"; + std::vector target_json_files; + std::vector target_ids; + + for (const auto &target : graph.targets) { + std::string compile_groups = "["; + bool first_group = true; + for (const auto &action : graph.actions) { + if (action.target_name != target.name) { + continue; + } + if (action.kind != Graph::ActionKind::Compile && + action.kind != Graph::ActionKind::PrecompiledHeader && + action.kind != Graph::ActionKind::HeaderUnit) { + continue; + } + std::vector source_indexes; + const auto source_it = + std::ranges::find(target.expanded_sources, action.logical_source_file); + if (source_it != target.expanded_sources.end()) { + source_indexes.push_back(static_cast( + std::distance(target.expanded_sources.begin(), source_it))); + } + if (!first_group) { + compile_groups += ','; + } + first_group = false; + compile_groups += "{\"sourceIndexes\":" + json_array(source_indexes, [](std::size_t i) { + return std::to_string(i); + }); + compile_groups += ",\"language\":" + json_quote(action.is_c_source ? "C" : "CXX"); + compile_groups += ",\"compileCommandFragments\":" + + json_array(action.arguments, [](const std::string &argument) { + return "{\"fragment\":" + Util::json_quote(argument) + '}'; + }); + compile_groups += + ",\"defines\":" + json_array(action.defines, [](const std::string &d) { + return "{\"define\":" + Util::json_quote(d) + '}'; + }); + compile_groups += + ",\"includes\":" + + json_array(action.physical_include_dirs, [](const auto &include) { + return "{\"path\":" + Util::json_quote(include.first.string()) + '}'; + }); + compile_groups += '}'; + } + compile_groups += ']'; + + std::string target_json = + "{\"kind\":\"target\",\"version\":" + version_block + + ",\"name\":" + json_quote(target.name) + + ",\"type\":" + json_quote(file_api_target_type(target.kind)) + ",\"artifacts\":" + + json_array(target.primary_outputs, + [](const std::filesystem::path &p) { + return "{\"path\":" + Util::json_quote(p.string()) + '}'; + }) + + ",\"nameOnDisk\":" + + json_quote(target.primary_outputs.empty() + ? std::string{} + : target.primary_outputs.front().filename().string()) + + ",\"paths\":{\"source\":" + json_quote(graph.project_root.string()) + + ",\"build\":" + json_quote(graph.profile_build_dir.string()) + "},\"sources\":" + + json_array(target.expanded_sources, + [](const std::filesystem::path &p) { + return "{\"path\":" + Util::json_quote(p.string()) + '}'; + }) + + ",\"compileGroups\":" + compile_groups + '}'; + + const std::string file_name = "target-" + safe_file_token(target.name) + "-" + + Util::sha256_hex(target_json).substr(0, 16) + ".json"; + if (auto written = write_reply(file_name, target_json); !written) { + return written; + } + target_json_files.push_back(file_name); + target_ids.push_back(target.name); + } + + std::string target_refs; + for (std::size_t i = 0; i < target_json_files.size(); ++i) { + if (i > 0) { + target_refs += ','; + } + target_refs += "{\"directoryIndex\":0,\"id\":" + json_quote(":" + target_ids[i]) + + ",\"jsonFile\":" + json_quote(target_json_files[i]) + + ",\"name\":" + json_quote(target_ids[i]) + + ",\"projectIndex\":0,\"targetIndex\":" + std::to_string(i) + '}'; + } + const std::string directory_json = + "{\"kind\":\"directory\",\"version\":" + version_block + + ",\"paths\":{\"build\":" + json_quote(build_root.string()) + + ",\"source\":" + json_quote(project_root.string()) + + "},\"projectIndexes\":[0],\"targetIndexes\":" + + json_array(std::views::iota(std::size_t{0}, target_json_files.size()), + [](std::size_t i) { return std::to_string(i); }) + + '}'; + const std::string directory_file = + "directory-.-" + Util::sha256_hex(directory_json).substr(0, 16) + ".json"; + if (auto written = write_reply(directory_file, directory_json); !written) { + return written; + } + + const std::string codemodel_json = + "{\"kind\":\"codemodel\",\"version\":" + version_block + + ",\"paths\":{\"source\":" + json_quote(project_root.string()) + + ",\"build\":" + json_quote(build_root.string()) + + "},\"configurations\":[{\"name\":" + json_quote(graph.profile.name) + + ",\"projects\":[{\"name\":" + json_quote(project_root.filename().string()) + + ",\"targetIndexes\":" + + json_array(std::views::iota(std::size_t{0}, target_json_files.size()), + [](std::size_t i) { return std::to_string(i); }) + + "}],\"directories\":[{\"source\":" + json_quote(project_root.string()) + + ",\"build\":" + json_quote(build_root.string()) + + ",\"jsonFile\":" + json_quote(directory_file) + + ",\"projectIndexes\":[0],\"targetIndexes\":" + + json_array(std::views::iota(std::size_t{0}, target_json_files.size()), + [](std::size_t i) { return std::to_string(i); }) + + "}],\"targets\":[" + target_refs + "]}]}"; + const std::string codemodel_file = + "codemodel-v2-" + Util::sha256_hex(codemodel_json).substr(0, 16) + ".json"; + if (auto written = write_reply(codemodel_file, codemodel_json); !written) { + return written; + } + + const std::string index_json = + "{\"cmake\":{\"generator\":{\"multiConfig\":false},\"version\":{\"major\":0," + "\"minor\":1,\"patch\":0,\"string\":\"" + + std::string{Bootstrap::version} + + "\"}},\"reply\":{\"codemodel-v2\":{\"jsonFile\":" + json_quote(codemodel_file) + + ",\"kind\":\"codemodel\",\"version\":" + version_block + "}}}"; + const std::string index_file = "index-" + Util::sha256_hex(index_json).substr(0, 16) + ".json"; + return write_reply(index_file, index_json); +} + +} // namespace + std::string format_ide_query_json(const Graph::BuildGraph &graph, const std::filesystem::path &compdb_path, const std::filesystem::path &sdk_include_dir) { diff --git a/tests/FullV1Tests.cpp b/tests/FullV1Tests.cpp index 2e04a7b..c7ed724 100644 --- a/tests/FullV1Tests.cpp +++ b/tests/FullV1Tests.cpp @@ -2593,6 +2593,105 @@ VOID_TEST(FullV1Tests, ide_integration_compdb_build_cpp_and_editor_configs_end_t Void::Testing::expect(parsed.has_value()); } } + // The CMake File API shim emits a codemodel-v2 reply tree from the lowered graph. + { + const auto reply_dir = bdir / ".cmake" / "api" / "v1" / "reply"; + Void::Testing::expect(std::filesystem::exists(reply_dir)); + std::filesystem::path index_file; + if (std::filesystem::exists(reply_dir)) { + for (const auto &entry : std::filesystem::directory_iterator(reply_dir)) { + if (entry.path().filename().string().starts_with("index-")) { + index_file = entry.path(); + } + } + } + Void::Testing::require(!index_file.empty()); + const auto read_json = + [](const std::filesystem::path &path) -> std::optional { + auto text = Void::FileSystem::read_file(path); + if (!text) { + return std::nullopt; + } + auto parsed = Void::Json::Strict::parse(*text); + if (!parsed) { + return std::nullopt; + } + return std::move(*parsed); + }; + using JsonObject = Void::Json::Strict::Value::Object; + const auto get_object = [](const JsonObject &object, + std::string_view key) -> const JsonObject * { + const auto it = object.find(key); + return it == object.end() ? nullptr : std::get_if(&it->second.value); + }; + const auto get_string = [](const JsonObject &object, std::string_view key) -> std::string { + const auto it = object.find(key); + if (it == object.end()) { + return {}; + } + const auto *text = std::get_if(&it->second.value); + return text ? *text : std::string{}; + }; + + const auto index_json = read_json(index_file); + Void::Testing::require(index_json.has_value()); + const auto *index_object = std::get_if(&index_json->value); + Void::Testing::require(index_object != nullptr); + const auto *reply = get_object(*index_object, "reply"); + Void::Testing::require(reply != nullptr); + const auto *codemodel_entry = get_object(*reply, "codemodel-v2"); + Void::Testing::require(codemodel_entry != nullptr); + const auto codemodel_file = get_string(*codemodel_entry, "jsonFile"); + Void::Testing::require(!codemodel_file.empty()); + + const auto codemodel_json = read_json(reply_dir / codemodel_file); + Void::Testing::require(codemodel_json.has_value()); + const auto *codemodel_object = std::get_if(&codemodel_json->value); + Void::Testing::require(codemodel_object != nullptr); + const auto configs_it = codemodel_object->find("configurations"); + Void::Testing::require(configs_it != codemodel_object->end()); + const auto *configs = + std::get_if(&configs_it->second.value); + Void::Testing::require(configs != nullptr && !configs->empty()); + const auto *configuration = std::get_if(&configs->front().value); + Void::Testing::require(configuration != nullptr); + const auto targets_it = configuration->find("targets"); + Void::Testing::require(targets_it != configuration->end()); + const auto *targets = + std::get_if(&targets_it->second.value); + Void::Testing::require(targets != nullptr && !targets->empty()); + const auto *first_target = std::get_if(&targets->front().value); + Void::Testing::require(first_target != nullptr); + const auto target_file = get_string(*first_target, "jsonFile"); + Void::Testing::require(!target_file.empty()); + + const auto target_json = read_json(reply_dir / target_file); + Void::Testing::require(target_json.has_value()); + const auto *target_object = std::get_if(&target_json->value); + Void::Testing::require(target_object != nullptr); + Void::Testing::expect_eq(get_string(*target_object, "kind"), std::string{"target"}); + Void::Testing::expect(!get_string(*target_object, "type").empty()); + Void::Testing::expect(!get_string(*target_object, "name").empty()); + auto target_text = Void::FileSystem::read_file(reply_dir / target_file); + Void::Testing::require(target_text.has_value()); + + // At least one emitted target is the executable, with artifacts and compile groups. + bool saw_executable = false; + for (const auto &entry : std::filesystem::directory_iterator(reply_dir)) { + const auto name = entry.path().filename().string(); + if (!name.starts_with("target-")) { + continue; + } + auto text = Void::FileSystem::read_file(entry.path()); + if (text && text->find("\"type\":\"EXECUTABLE\"") != std::string::npos) { + saw_executable = true; + Void::Testing::expect(text->find("\"artifacts\":[{") != std::string::npos); + Void::Testing::expect(text->find("\"compileGroups\":[{") != std::string::npos); + } + } + Void::Testing::expect(saw_executable); + } + // The generated IDE tasks include install/package entries. if (auto tasks = Void::FileSystem::read_file(proj / ".vscode" / "tasks.json"); tasks) { Void::Testing::expect(tasks->find("vbs: install") != std::string::npos);