[M4] cargoxx build invokes nix+cmake

This commit is contained in:
2026-05-10 00:04:18 +00:00
parent 807158b8cc
commit f6e8699a72
6 changed files with 121 additions and 29 deletions

View File

@@ -51,7 +51,7 @@ TEST_CASE("cmd_build generates files for a no-deps binary project",
REQUIRE(cmd_new("hello", false, parent).has_value());
auto root = parent / "hello";
auto r = cmd_build(root, true, false, overlay_path(parent));
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
REQUIRE(std::filesystem::exists(root / "flake.nix"));
@@ -73,7 +73,7 @@ TEST_CASE("cmd_build generates files for a library project", "[cli][build]") {
REQUIRE(cmd_new("widget", true, parent).has_value());
auto root = parent / "widget";
auto r = cmd_build(root, true, false, overlay_path(parent));
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
auto cmake_text = read_file(root / "build" / "CMakeLists.txt");
@@ -89,7 +89,7 @@ TEST_CASE("cmd_build resolves a curated dep into find_package + targets",
auto root = parent / "app";
add_dep(root, "fmt", "10.2.0");
auto r = cmd_build(root, true, false, overlay_path(parent));
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
auto cmake_text = read_file(root / "build" / "CMakeLists.txt");
@@ -106,7 +106,7 @@ TEST_CASE("cmd_build resolves a componentized dep", "[cli][build]") {
auto root = parent / "app";
add_dep(root, "boost", "1.84.0", {"filesystem", "system"});
auto r = cmd_build(root, true, false, overlay_path(parent));
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
auto cmake_text = read_file(root / "build" / "CMakeLists.txt");
@@ -123,7 +123,7 @@ TEST_CASE("cmd_build synthesizes a lockfile entry per dep", "[cli][build]") {
add_dep(root, "fmt", "10.2.0");
add_dep(root, "spdlog", "1.13.0");
auto r = cmd_build(root, true, false, overlay_path(parent));
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
auto lock = lockfile::parse(root / "Cargoxx.lock");
@@ -139,22 +139,31 @@ TEST_CASE("cmd_build fails for an unknown dep", "[cli][build]") {
auto root = parent / "app";
add_dep(root, "obscurelib", "0.0.1");
auto r = cmd_build(root, true, false, overlay_path(parent));
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE_FALSE(r.has_value());
REQUIRE(r.error().code == ErrorCode::LinkdbUnknownPackage);
}
TEST_CASE("cmd_build without --no-build returns NotImplemented", "[cli][build]") {
TEST_CASE("cmd_build --release writes a release-typed build/CMakeLists",
"[cli][build]") {
// The CMAKE_BUILD_TYPE flag itself is set on the cmake command line, not in
// the generated CMakeLists.txt — but the same generation runs for both
// profiles, so just verify the --release path with --no-build doesn't error.
auto parent = fresh_dir();
REQUIRE(cmd_new("app", false, parent).has_value());
auto root = parent / "app";
auto r = cmd_build(root, true, true, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
}
auto r = cmd_build(root, false, false, overlay_path(parent));
REQUIRE_FALSE(r.has_value());
REQUIRE(r.error().code == ErrorCode::NotImplemented);
// Files are still generated before the build step would run
REQUIRE(std::filesystem::exists(root / "flake.nix"));
REQUIRE(std::filesystem::exists(root / "build" / "CMakeLists.txt"));
TEST_CASE("cmd_build accepts a --target argument under --no-build",
"[cli][build]") {
auto parent = fresh_dir();
REQUIRE(cmd_new("app", false, parent).has_value());
auto root = parent / "app";
auto r = cmd_build(root, true, false, std::string{"app_bin"},
overlay_path(parent));
REQUIRE(r.has_value());
}
TEST_CASE("cmd_build is idempotent — second run produces identical files",
@@ -164,12 +173,12 @@ TEST_CASE("cmd_build is idempotent — second run produces identical files",
auto root = parent / "app";
add_dep(root, "fmt", "10.2.0");
REQUIRE(cmd_build(root, true, false, overlay_path(parent)).has_value());
REQUIRE(cmd_build(root, true, false, std::nullopt, overlay_path(parent)).has_value());
auto first_cmake = read_file(root / "build" / "CMakeLists.txt");
auto first_flake = read_file(root / "flake.nix");
auto first_lock = read_file(root / "Cargoxx.lock");
REQUIRE(cmd_build(root, true, false, overlay_path(parent)).has_value());
REQUIRE(cmd_build(root, true, false, std::nullopt, overlay_path(parent)).has_value());
REQUIRE(read_file(root / "build" / "CMakeLists.txt") == first_cmake);
REQUIRE(read_file(root / "flake.nix") == first_flake);
REQUIRE(read_file(root / "Cargoxx.lock") == first_lock);