[M7] generated flake.nix moves to build/flake.nix
This commit is contained in:
12
flake.nix
12
flake.nix
@@ -10,7 +10,19 @@
|
|||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
cargoxx = pkgs.gcc15Stdenv.mkDerivation {
|
||||||
|
# Fill rules here
|
||||||
|
};
|
||||||
|
buildCppPackage = attrs: pkgs.gcc15Stdenv.mkDerivation {
|
||||||
|
pname = attrs.pname;
|
||||||
|
version = attrs.version;
|
||||||
|
buildPhase = ''
|
||||||
|
cargoxx build
|
||||||
|
'';
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
|
lib.buildCppPackage = buildCppPackage;
|
||||||
|
package = cargoxx;
|
||||||
devShell = pkgs.gcc15Stdenv.mkDerivation {
|
devShell = pkgs.gcc15Stdenv.mkDerivation {
|
||||||
name = "shell";
|
name = "shell";
|
||||||
version = "1.0";
|
version = "1.0";
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ namespace {
|
|||||||
|
|
||||||
auto run_nix_cmake(const fs::path& project_root, const std::vector<std::string>& cmake_args,
|
auto run_nix_cmake(const fs::path& project_root, const std::vector<std::string>& cmake_args,
|
||||||
std::string_view phase) -> util::Result<void> {
|
std::string_view phase) -> util::Result<void> {
|
||||||
std::vector<std::string> args{"develop", "--command", "cmake"};
|
std::vector<std::string> args{"develop", "path:./build", "--command", "cmake"};
|
||||||
args.insert(args.end(), cmake_args.begin(), cmake_args.end());
|
args.insert(args.end(), cmake_args.begin(), cmake_args.end());
|
||||||
|
|
||||||
auto r = exec::run("nix", args, exec::ExecOptions{
|
auto r = exec::run("nix", args, exec::ExecOptions{
|
||||||
@@ -233,7 +233,7 @@ auto cmd_build(const fs::path& project_root, bool no_build, bool release,
|
|||||||
project_root / "build"));
|
project_root / "build"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto r = write_text(project_root / "flake.nix", flake_text); !r) {
|
if (auto r = write_text(project_root / "build" / "flake.nix", flake_text); !r) {
|
||||||
return std::unexpected(r.error());
|
return std::unexpected(r.error());
|
||||||
}
|
}
|
||||||
if (auto r = write_text(project_root / "build" / "CMakeLists.txt", cmake_text); !r) {
|
if (auto r = write_text(project_root / "build" / "CMakeLists.txt", cmake_text); !r) {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ auto cmd_test(const fs::path& project_root, bool release,
|
|||||||
const auto build_dir = std::format("build/{}", profile);
|
const auto build_dir = std::format("build/{}", profile);
|
||||||
|
|
||||||
auto r = exec::run("nix",
|
auto r = exec::run("nix",
|
||||||
{"develop", "--command", "ctest", "--test-dir", build_dir,
|
{"develop", "path:./build", "--command", "ctest",
|
||||||
"--output-on-failure"},
|
"--test-dir", build_dir, "--output-on-failure"},
|
||||||
exec::ExecOptions{
|
exec::ExecOptions{
|
||||||
.cwd = project_root,
|
.cwd = project_root,
|
||||||
.env_overrides = {},
|
.env_overrides = {},
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ auto run(int argc, char** argv) -> int {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (build_no_build) {
|
if (build_no_build) {
|
||||||
std::cout << " Generated flake.nix, build/CMakeLists.txt, Cargoxx.lock\n";
|
std::cout << " Generated build/flake.nix, build/CMakeLists.txt, Cargoxx.lock\n";
|
||||||
} else {
|
} else {
|
||||||
std::cout << " Built\n";
|
std::cout << " Built\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ TEST_CASE("cmd_build generates files for a no-deps binary project",
|
|||||||
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
|
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
|
||||||
REQUIRE(r.has_value());
|
REQUIRE(r.has_value());
|
||||||
|
|
||||||
REQUIRE(std::filesystem::exists(root / "flake.nix"));
|
REQUIRE(std::filesystem::exists(root / "build" / "flake.nix"));
|
||||||
REQUIRE(std::filesystem::exists(root / "build" / "CMakeLists.txt"));
|
REQUIRE(std::filesystem::exists(root / "build" / "CMakeLists.txt"));
|
||||||
REQUIRE(std::filesystem::exists(root / "Cargoxx.lock"));
|
REQUIRE(std::filesystem::exists(root / "Cargoxx.lock"));
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ TEST_CASE("cmd_build generates files for a no-deps binary project",
|
|||||||
REQUIRE(cmake_text.find("add_executable(hello_bin ../src/main.cpp)") !=
|
REQUIRE(cmake_text.find("add_executable(hello_bin ../src/main.cpp)") !=
|
||||||
std::string::npos);
|
std::string::npos);
|
||||||
|
|
||||||
auto flake_text = read_file(root / "flake.nix");
|
auto flake_text = read_file(root / "build" / "flake.nix");
|
||||||
REQUIRE(flake_text.find("description = \"hello\";") != std::string::npos);
|
REQUIRE(flake_text.find("description = \"hello\";") != std::string::npos);
|
||||||
REQUIRE(flake_text.find("github:NixOS/nixpkgs/nixos-unstable") != std::string::npos);
|
REQUIRE(flake_text.find("github:NixOS/nixpkgs/nixos-unstable") != std::string::npos);
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ TEST_CASE("cmd_build resolves a manually-seeded dep into find_package + targets"
|
|||||||
REQUIRE(cmake_text.find("find_package(fmt CONFIG REQUIRED)") != std::string::npos);
|
REQUIRE(cmake_text.find("find_package(fmt CONFIG REQUIRED)") != std::string::npos);
|
||||||
REQUIRE(cmake_text.find("fmt::fmt") != std::string::npos);
|
REQUIRE(cmake_text.find("fmt::fmt") != std::string::npos);
|
||||||
|
|
||||||
auto flake_text = read_file(root / "flake.nix");
|
auto flake_text = read_file(root / "build" / "flake.nix");
|
||||||
REQUIRE(flake_text.find("pkgs.fmt_10") != std::string::npos);
|
REQUIRE(flake_text.find("pkgs.fmt_10") != std::string::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,11 +197,11 @@ TEST_CASE("cmd_build is idempotent — second run produces identical files",
|
|||||||
|
|
||||||
REQUIRE(cmd_build(root, true, false, std::nullopt, 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_cmake = read_file(root / "build" / "CMakeLists.txt");
|
||||||
auto first_flake = read_file(root / "flake.nix");
|
auto first_flake = read_file(root / "build" / "flake.nix");
|
||||||
auto first_lock = read_file(root / "Cargoxx.lock");
|
auto first_lock = read_file(root / "Cargoxx.lock");
|
||||||
|
|
||||||
REQUIRE(cmd_build(root, true, false, std::nullopt, 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 / "build" / "CMakeLists.txt") == first_cmake);
|
||||||
REQUIRE(read_file(root / "flake.nix") == first_flake);
|
REQUIRE(read_file(root / "build" / "flake.nix") == first_flake);
|
||||||
REQUIRE(read_file(root / "Cargoxx.lock") == first_lock);
|
REQUIRE(read_file(root / "Cargoxx.lock") == first_lock);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user