[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

@@ -7,6 +7,7 @@ import cargoxx.layout;
import cargoxx.linkdb;
import cargoxx.lockfile;
import cargoxx.codegen;
import cargoxx.exec;
namespace cargoxx::cli {
@@ -72,7 +73,36 @@ auto synthesize_lockfile(const manifest::Manifest& m,
} // namespace
auto cmd_build(const fs::path& project_root, bool no_build, bool /*release*/,
namespace {
auto run_nix_cmake(const fs::path& project_root, const std::vector<std::string>& cmake_args,
std::string_view phase) -> util::Result<void> {
std::vector<std::string> args{"develop", "--command", "cmake"};
args.insert(args.end(), cmake_args.begin(), cmake_args.end());
auto r = exec::run("nix", args, exec::ExecOptions{
.cwd = project_root,
.env_overrides = {},
.timeout = std::nullopt,
.inherit_stdio = true,
});
if (!r) {
return std::unexpected(r.error());
}
if (r->exit_code != 0) {
return std::unexpected(util::Error{
util::ErrorCode::BuildCmakeFailed,
std::format("cmake {} failed (exit {})", phase, r->exit_code),
"", std::nullopt, std::nullopt,
});
}
return {};
}
} // namespace
auto cmd_build(const fs::path& project_root, bool no_build, bool release,
std::optional<std::string> target,
std::optional<fs::path> overlay_path) -> util::Result<void> {
auto manifest_path = project_root / "Cargoxx.toml";
auto m = manifest::parse(manifest_path);
@@ -124,13 +154,31 @@ auto cmd_build(const fs::path& project_root, bool no_build, bool /*release*/,
return std::unexpected(r.error());
}
if (!no_build) {
return std::unexpected(util::Error{
util::ErrorCode::NotImplemented,
"cargoxx build invocation is not implemented in this milestone",
"rerun with --no-build to generate files only (full build lands at M4)",
std::nullopt, std::nullopt,
});
if (no_build) {
return {};
}
const std::string profile = release ? "release" : "debug";
const std::string profile_cap = release ? "Release" : "Debug";
const auto build_dir = std::format("build/{}", profile);
std::vector<std::string> configure_args{
"-B", build_dir,
"-S", "build",
"-G", "Ninja",
std::format("-DCMAKE_BUILD_TYPE={}", profile_cap),
};
if (auto r = run_nix_cmake(project_root, configure_args, "configure"); !r) {
return std::unexpected(r.error());
}
std::vector<std::string> build_args{"--build", build_dir};
if (target) {
build_args.push_back("--target");
build_args.push_back(*target);
}
if (auto r = run_nix_cmake(project_root, build_args, "build"); !r) {
return std::unexpected(r.error());
}
return {};