From 083af6af79dae52c238ea050d8e5ca3f4a9d72d1 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 06:12:05 +0300 Subject: [PATCH] feat(config): import CMake configure presets --- CMakeLists.txt | 1 + docs/agent-workflow/STATE.md | 2 + docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 6 + docs/roadmap/22-superiority-and-gaps.md | 2 +- include/Void/Build/Config/Presets.hpp | 35 ++++ src/Config/Presets.cpp | 235 ++++++++++++++++++++++++ src/Main.cpp | 49 +++++ tests/CliContracts.cmake | 1 + tests/FullV1Tests.cpp | 56 ++++++ 10 files changed, 387 insertions(+), 1 deletion(-) create mode 100644 include/Void/Build/Config/Presets.hpp create mode 100644 src/Config/Presets.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a0ed45..7cac956 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ add_library(VoidBuild_Core STATIC src/Execution/Scheduler.cpp src/Config/BuildTree.cpp src/Config/Frontend.cpp + src/Config/Presets.cpp src/Config/Scaffold.cpp src/Daemon/Daemon.cpp src/Editor/CompDb.cpp diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 0375df1..ac54235 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -292,6 +292,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 99 (Windows Path & Case-Sensitivity Validation)**: graph lowering for Windows targets rejects case-insensitive output collisions (`Tool` vs `tool` → `Tool.exe`/`tool.exe`) and reserved device names (`CON`, `NUL`, `COM1`, …), with explicit diagnostics. The Wine regression test now also proves PE case-insensitive file semantics (`fopen("CASE_A.TXT")` finds `case_a.txt`) and asserts both validation errors. +- **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. + ## 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 f04b4a2..660cad9 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -103,4 +103,5 @@ Base HEAD: `fe0d1a6` | Wave 97 (ZIP & DEB generators) | `--archive-format zip|deb`: stored ZIP and Debian ar package with metadata; tested structurally and validated with real `dpkg-deb` | 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 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 | | 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 e31c7fb..870fb2e 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1412,6 +1412,12 @@ dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc -p wine64 -c build/pinned/bin/vbs_v1 target fails with `reserved Windows device name`. - Regression test: **passed** (14.12 s); full CTest: **8 / 8 passed** in 277.56 s. +## CMakePresets Import (GCC 16.2, pin `0002e74`) + +- `FullV1Tests.cmake_presets_import_maps_inherits_and_cache` **passed**: a child preset inheriting an array parent gets the merged `${sourceDir}` binary dir, `Release` → `release` profile, `clang++` → `clang`, and the suggested command contains `--profile 'release' --compiler 'clang' --build-dir '...'`; a bare preset defaults to `debug`/`gcc` with no build dir. +- CLI contract: `vbs presets --help` passes. +- Full CTest: **8 / 8 passed** in 276.96 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 d84136e..5678779 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, external plugins. +4. IDE ecosystem: File API shim, 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/include/Void/Build/Config/Presets.hpp b/include/Void/Build/Config/Presets.hpp new file mode 100644 index 0000000..bb1e0b7 --- /dev/null +++ b/include/Void/Build/Config/Presets.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include + +namespace Void::Build::Config { + +// One imported CMake configure preset projected onto VBS concepts. +struct ImportedPreset { + std::string name; + std::string generator; // Recorded for diagnostics; VBS has no generator. + std::optional build_dir; // binaryDir with ${sourceDir} expanded. + std::string build_type; // Raw CMAKE_BUILD_TYPE (may be empty). + std::string profile{"debug"}; // Mapped VBS profile: debug or release. + std::string compiler{"gcc"}; // Mapped VBS compiler family: gcc or clang. + std::map> cache_variables; +}; + +// Parses `CMakePresets.json`-style configure presets, resolving `inherits` +// (string or array) and projecting build type/compiler onto VBS defaults. +// The project root is used to expand `${sourceDir}`. +[[nodiscard]] Void::Result::Result, Void::Result::Error> +load_cmake_presets(const std::filesystem::path &presets_file, + const std::filesystem::path &project_root); + +// Shell-safe single-quoted argument for the suggested `vbs` command line. +[[nodiscard]] std::string suggested_build_command(const ImportedPreset &preset); + +} // namespace Void::Build::Config diff --git a/src/Config/Presets.cpp b/src/Config/Presets.cpp new file mode 100644 index 0000000..56c8c0f --- /dev/null +++ b/src/Config/Presets.cpp @@ -0,0 +1,235 @@ +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace Void::Build::Config { +namespace { + +using JsonValue = Void::Json::Strict::Value; +using JsonObject = JsonValue::Object; + +Void::Result::Error make_error(std::string message) { + return Void::System::make_system_error(Void::System::SystemErrorCode::invalid_argument, + std::move(message)); +} + +std::string lower(std::string_view text) { return Void::Str::to_lower_ascii(text); } + +std::string map_profile(std::string_view build_type) { + const std::string type = lower(build_type); + if (type == "debug") { + return "debug"; + } + if (type == "release" || type == "relwithdebinfo" || type == "minsizerel") { + return "release"; + } + return "debug"; +} + +std::string map_compiler(std::string_view compiler_path) { + const std::string path = lower(compiler_path); + if (path.find("clang") != std::string::npos) { + return "clang"; + } + return "gcc"; +} + +std::string expand_source_dir(std::string value, const std::filesystem::path &project_root) { + const std::string token{"${sourceDir}"}; + std::size_t pos = 0; + while ((pos = value.find(token, pos)) != std::string::npos) { + value.replace(pos, token.size(), project_root.string()); + pos += project_root.string().size(); + } + return value; +} + +} // namespace + +Void::Result::Result, Void::Result::Error> +load_cmake_presets(const std::filesystem::path &presets_file, + const std::filesystem::path &project_root) { + auto text = Void::FileSystem::read_file(presets_file); + if (!text) { + return std::unexpected{text.error()}; + } + auto parsed = Void::Json::Strict::parse(*text); + if (!parsed) { + return std::unexpected{ + make_error(std::format("CMakePresets '{}' is not valid JSON", presets_file.string()))}; + } + const auto *root = std::get_if(&parsed->value); + if (!root) { + return std::unexpected{make_error("CMakePresets root must be a JSON object")}; + } + const auto list_it = root->find("configurePresets"); + if (list_it == root->end()) { + return std::vector{}; + } + const auto *presets = std::get_if(&list_it->second.value); + if (!presets) { + return std::unexpected{make_error("configurePresets must be a JSON array")}; + } + + std::map> raw_by_name; + std::vector order; + for (const auto &entry : *presets) { + const auto *object = std::get_if(&entry.value); + if (!object) { + continue; + } + const auto name_it = object->find("name"); + if (name_it == object->end()) { + continue; + } + const auto *name = std::get_if(&name_it->second.value); + if (!name) { + continue; + } + if (!raw_by_name.contains(*name)) { + order.push_back(*name); + } + raw_by_name[*name] = *object; + } + + // Flattens `inherits` (string or array) depth-first with cycle detection. + std::map> merged; + std::function(const std::string &, + std::set)> + flatten = [&](const std::string &name, std::set stack) + -> Void::Result::Result { + if (const auto it = merged.find(name); it != merged.end()) { + return it->second; + } + const auto raw_it = raw_by_name.find(name); + if (raw_it == raw_by_name.end()) { + return std::unexpected{make_error( + std::format("CMakePresets preset '{}' is inherited but not defined", name))}; + } + if (!stack.insert(name).second) { + return std::unexpected{ + make_error(std::format("CMakePresets inherits cycle at '{}'", name))}; + } + JsonObject result; + const auto inherits_it = raw_it->second.find("inherits"); + std::vector parents; + if (inherits_it != raw_it->second.end()) { + if (const auto *single = std::get_if(&inherits_it->second.value)) { + parents.push_back(*single); + } else if (const auto *many = + std::get_if(&inherits_it->second.value)) { + for (const auto &parent : *many) { + if (const auto *text = std::get_if(&parent.value)) { + parents.push_back(*text); + } + } + } + } + for (const auto &parent : parents) { + auto parent_merged = flatten(parent, stack); + if (!parent_merged) { + return std::unexpected{parent_merged.error()}; + } + for (const auto &[key, value] : *parent_merged) { + result[key] = value; + } + } + for (const auto &[key, value] : raw_it->second) { + if (key == "cacheVariables") { + auto &target = result[key]; + if (target.value.index() == 0) { + target = JsonValue{JsonObject{}}; + } + auto *target_object = std::get_if(&target.value); + const auto *source_object = std::get_if(&value.value); + if (target_object != nullptr && source_object != nullptr) { + for (const auto &[cache_key, cache_value] : *source_object) { + (*target_object)[cache_key] = cache_value; + } + } + } else { + result[key] = value; + } + } + merged[name] = result; + return result; + }; + + std::vector imported; + for (const auto &name : order) { + auto flat = flatten(name, {}); + if (!flat) { + return std::unexpected{flat.error()}; + } + ImportedPreset preset; + preset.name = name; + const auto read_string = [&](std::string_view key) -> std::string { + const auto it = flat->find(std::string{key}); + if (it == flat->end()) { + return {}; + } + const auto *value = std::get_if(&it->second.value); + return value ? *value : std::string{}; + }; + preset.generator = read_string("generator"); + if (auto binary_dir = read_string("binaryDir"); !binary_dir.empty()) { + preset.build_dir = expand_source_dir(binary_dir, project_root); + } + if (const auto cache_it = flat->find("cacheVariables"); cache_it != flat->end()) { + if (const auto *cache = std::get_if(&cache_it->second.value)) { + for (const auto &[key, value] : *cache) { + std::string text; + if (const auto *as_text = std::get_if(&value.value)) { + text = *as_text; + } else if (const auto *as_bool = std::get_if(&value.value)) { + text = *as_bool ? "ON" : "OFF"; + } + preset.cache_variables[key] = text; + } + } + } + if (const auto bt = preset.cache_variables.find("CMAKE_BUILD_TYPE"); + bt != preset.cache_variables.end()) { + preset.build_type = bt->second; + } + preset.profile = map_profile(preset.build_type); + if (const auto cxx = preset.cache_variables.find("CMAKE_CXX_COMPILER"); + cxx != preset.cache_variables.end()) { + preset.compiler = map_compiler(cxx->second); + } + imported.push_back(std::move(preset)); + } + return imported; +} + +std::string suggested_build_command(const ImportedPreset &preset) { + const auto quote = [](const std::string &value) { + std::string out{"'"}; + for (const char c : value) { + if (c == '\'') { + out += "'\\''"; + } else { + out.push_back(c); + } + } + out.push_back('\''); + return out; + }; + std::string command = "vbs build"; + if (preset.build_dir) { + command += " --build-dir " + quote(*preset.build_dir); + } + command += " --profile " + quote(preset.profile); + command += " --compiler " + quote(preset.compiler); + return command; +} + +} // namespace Void::Build::Config diff --git a/src/Main.cpp b/src/Main.cpp index f2ac06c..2e901c9 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -1331,6 +1332,40 @@ int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) { return 0; } +struct PresetsCmdOptions { + std::string file_arg{"CMakePresets.json"}; + std::string project_arg; + std::optional name_arg; +}; + +int execute_presets_command(const PresetsCmdOptions &opts) { + auto presets = Config::load_cmake_presets(opts.file_arg, opts.project_arg); + if (!presets) { + std::cerr << "vbs presets: " << presets.error().message() << '\n'; + return 1; + } + if (opts.name_arg) { + const auto match = + std::ranges::find_if(*presets, [&](const Config::ImportedPreset &preset) { + return preset.name == *opts.name_arg; + }); + if (match == presets->end()) { + std::cerr << "vbs presets: unknown preset '" << *opts.name_arg << "'\n"; + return 1; + } + std::cout << Config::suggested_build_command(*match) << '\n'; + return 0; + } + for (const auto &preset : *presets) { + std::cout << "preset=" << preset.name << " profile=" << preset.profile + << " compiler=" << preset.compiler + << " build_dir=" << (preset.build_dir ? *preset.build_dir : std::string{"-"}) + << " build_type=" << (preset.build_type.empty() ? "-" : preset.build_type) + << '\n'; + } + return 0; +} + struct VerifyCmdOptions { std::optional name_arg; std::optional version_arg; @@ -2728,6 +2763,7 @@ int main(int argc, char **argv) { TokensCmdOptions tokens_opts; LockCmdOptions lock_opts; VerifyCmdOptions verify_opts; + PresetsCmdOptions presets_opts; CompdbEntriesCmdOptions compdb_entries_opts; publish_opts.project_arg = cwd; BridgeCmdOptions bridge_opts; @@ -2934,6 +2970,16 @@ int main(int argc, char **argv) { verify_opts.trusted_key_files); add_log_flags(verify_cmd, false); // `-v` is `--version` on verify. + auto &presets_cmd = root.subcommand( + "presets", "Import CMake configure presets (CMakePresets.json) as VBS equivalents"); + presets_cmd + .option_default("--file", "-f", "CMakePresets.json path", presets_opts.file_arg, + "CMakePresets.json") + .option_default("--project", "-C", "Project root for ${sourceDir}", + presets_opts.project_arg, cwd) + .option("--name", "-n", "Print the VBS command for one preset", presets_opts.name_arg); + add_log_flags(presets_cmd); + auto &lock_cmd = root.subcommand("lock", "Inspect the project's vbs.lock"); auto &lock_show_cmd = lock_cmd.subcommand("show", "Print lockfile contexts and entries"); lock_show_cmd.option_default("--project", "-C", "Project directory", lock_opts.project_arg, @@ -3404,6 +3450,9 @@ int main(int argc, char **argv) { if (cmd == "verify") { return execute_verify_command(verify_opts); } + if (cmd == "presets") { + return execute_presets_command(presets_opts); + } if (cmd == "compdb-entries") { return execute_compdb_entries_command(compdb_entries_opts); } diff --git a/tests/CliContracts.cmake b/tests/CliContracts.cmake index 9a95cf2..34742fa 100644 --- a/tests/CliContracts.cmake +++ b/tests/CliContracts.cmake @@ -55,6 +55,7 @@ check_process(0 "Usage: vbs releases yank " "" releases yank --help) check_process(2 "" "--registry, --name, and --version are required" releases yank) check_process(0 "Usage: vbs tokens list " "" tokens list --help) check_process(0 "Usage: vbs lock show " "" lock show --help) +check_process(0 "Usage: vbs presets " "" presets --help) check_process(0 "Usage: vbs verify " "" verify --help) check_process(0 "Usage: vbs compdb-entries " "" compdb-entries --help) check_process(1 "" "no compilation database is published" compdb-entries --project diff --git a/tests/FullV1Tests.cpp b/tests/FullV1Tests.cpp index 154c296..2e04a7b 100644 --- a/tests/FullV1Tests.cpp +++ b/tests/FullV1Tests.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -1061,6 +1062,61 @@ void build(Void::Build::Project &p) { } } +// === IDE/migration ecosystem: CMakePresets import === +VOID_TEST(FullV1Tests, cmake_presets_import_maps_inherits_and_cache) { + Void::FileSystem::TempDir tmp{"vbs_presets_"}; + const auto presets_file = tmp / "CMakePresets.json"; + write_file(presets_file, R"json({ + "version": 3, + "configurePresets": [ + {"name": "base", "hidden": true, "binaryDir": "${sourceDir}/out/base", + "cacheVariables": {"CMAKE_BUILD_TYPE": "Debug"}}, + {"name": "release-clang", "inherits": ["base"], + "cacheVariables": {"CMAKE_BUILD_TYPE": "Release", "CMAKE_CXX_COMPILER": "/usr/bin/clang++"}, + "generator": "Ninja"}, + {"name": "plain", "generator": "Unix Makefiles"} + ] +})json"); + + auto presets = Config::load_cmake_presets(presets_file, tmp.path()); + Void::Testing::require(presets.has_value()); + Void::Testing::expect_eq(presets->size(), std::size_t{3}); + + const auto find = [&](std::string_view name) -> const Config::ImportedPreset * { + for (const auto &preset : *presets) { + if (preset.name == name) { + return &preset; + } + } + return nullptr; + }; + const auto *base = find("base"); + Void::Testing::require(base != nullptr); + Void::Testing::expect_eq(base->profile, std::string{"debug"}); + Void::Testing::expect(base->build_dir.has_value()); + if (base->build_dir) { + Void::Testing::expect(base->build_dir->ends_with("out/base")); + Void::Testing::expect(base->build_dir->starts_with(tmp.path().string())); + } + + const auto *release = find("release-clang"); + Void::Testing::require(release != nullptr); + Void::Testing::expect_eq(release->profile, std::string{"release"}); + Void::Testing::expect_eq(release->compiler, std::string{"clang"}); + Void::Testing::expect_eq(release->generator, std::string{"Ninja"}); + Void::Testing::expect(release->cache_variables.contains("CMAKE_BUILD_TYPE")); + const auto command = Config::suggested_build_command(*release); + Void::Testing::expect(command.find("--profile 'release'") != std::string::npos); + Void::Testing::expect(command.find("--compiler 'clang'") != std::string::npos); + Void::Testing::expect(command.find("--build-dir '") != std::string::npos); + + const auto *plain = find("plain"); + Void::Testing::require(plain != nullptr); + Void::Testing::expect_eq(plain->profile, std::string{"debug"}); + Void::Testing::expect_eq(plain->compiler, std::string{"gcc"}); + Void::Testing::expect(!plain->build_dir.has_value()); +} + // === Track C (Wine-first): cross-compile to Windows with MinGW-w64 and run tests under Wine === VOID_TEST(FullV1Tests, track_c_windows_target_cross_build_and_wine_test) { const auto vbs_bin = locate_vbs_binary();