60 lines
2.1 KiB
C++
60 lines
2.1 KiB
C++
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
import std;
|
||
|
|
import Crafter.Build;
|
||
|
|
namespace fs = std::filesystem;
|
||
|
|
using namespace Crafter;
|
||
|
|
|
||
|
|
// The project other projects load: a library, a program built on it, and a
|
||
|
|
// tool that shares nothing with either and declares a test and a script.
|
||
|
|
// Its `path` is relative, as a project file writes it, so a consumer only
|
||
|
|
// builds it into this directory once the loader has rebased it.
|
||
|
|
namespace {
|
||
|
|
// One new set per call, at addresses that never change: whoever loads
|
||
|
|
// this file keeps the pointers it returns.
|
||
|
|
std::deque<Configuration> Owned;
|
||
|
|
}
|
||
|
|
|
||
|
|
extern "C" std::vector<Configuration*> CrafterBuildConfigurations(std::span<const std::string_view>) {
|
||
|
|
Configuration& greeter = Owned.emplace_back();
|
||
|
|
greeter.path = "./";
|
||
|
|
greeter.name = "greeter";
|
||
|
|
greeter.outputName = "greeter";
|
||
|
|
greeter.type = ConfigurationType::LibraryStatic;
|
||
|
|
{
|
||
|
|
std::array<fs::path, 1> interfaces = { "greeter/Greeter" };
|
||
|
|
std::array<fs::path, 0> implementations = {};
|
||
|
|
greeter.GetInterfacesAndImplementations(interfaces, implementations);
|
||
|
|
}
|
||
|
|
|
||
|
|
Configuration& hello = Owned.emplace_back();
|
||
|
|
hello.path = "./";
|
||
|
|
hello.name = "hello";
|
||
|
|
hello.outputName = "hello";
|
||
|
|
hello.type = ConfigurationType::Executable;
|
||
|
|
hello.dependencies = { &greeter };
|
||
|
|
{
|
||
|
|
std::array<fs::path, 0> interfaces = {};
|
||
|
|
std::array<fs::path, 1> implementations = { "hello/main" };
|
||
|
|
hello.GetInterfacesAndImplementations(interfaces, implementations);
|
||
|
|
}
|
||
|
|
|
||
|
|
Configuration& tool = Owned.emplace_back();
|
||
|
|
tool.path = "./";
|
||
|
|
tool.name = "tool";
|
||
|
|
tool.outputName = "tool";
|
||
|
|
tool.type = ConfigurationType::Executable;
|
||
|
|
{
|
||
|
|
std::array<fs::path, 0> interfaces = {};
|
||
|
|
std::array<fs::path, 1> implementations = { "tool/main" };
|
||
|
|
tool.GetInterfacesAndImplementations(interfaces, implementations);
|
||
|
|
}
|
||
|
|
tool.AddTest("ToolTest");
|
||
|
|
tool.scripts.push_back({"stamp", [](ScriptContext& ctx) {
|
||
|
|
std::ofstream(ctx.projectDir / "stamp.ran") << ctx.project.name;
|
||
|
|
return 0;
|
||
|
|
}});
|
||
|
|
|
||
|
|
return { &greeter, &hello, &tool };
|
||
|
|
}
|