Crafter.Build/examples/library/project.cpp
Jorijn van der Graaf 8892154b28
Some checks failed
CI / build-test-release (push) Failing after 7m15s
linting
2026-07-23 01:24:42 +02:00

40 lines
1.5 KiB
C++

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view>) {
// The library — built into mylib/bin/MyMath-<target>-<march>/libMyMath.a
// and exposed to consumers via cfg.dependencies. The static unique_ptr
// keeps the Configuration alive for the duration of the build (the
// consumer holds a raw pointer to it).
static auto lib = std::make_unique<Configuration>();
lib->path = "./mylib/";
lib->name = "MyMath";
lib->outputName = "MyMath";
lib->target = "x86_64-pc-linux-gnu";
lib->type = ConfigurationType::LibraryStatic;
{
std::array<fs::path, 1> ifaces = { "MyMath" };
std::array<fs::path, 0> impls = {};
lib->GetInterfacesAndImplementations(ifaces, impls);
}
// The consumer — main.cpp imports MyMath. The build resolves the import
// through cfg.dependencies and links libMyMath.a automatically.
Configuration cfg;
cfg.path = "./";
cfg.name = "math-app";
cfg.outputName = "math-app";
cfg.target = "x86_64-pc-linux-gnu";
cfg.type = ConfigurationType::Executable;
cfg.dependencies = { lib.get() };
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
cfg.GetInterfacesAndImplementations(ifaces, impls);
return cfg;
}