Crafter.Graphics/project.cpp

148 lines
7.1 KiB
C++
Raw Normal View History

2026-04-30 01:29:17 +02:00
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
std::vector<std::string> depArgs(args.begin(), args.end());
2026-05-12 00:24:48 +02:00
// --local resolves Crafter.* deps from sibling working trees instead of
// fetching them from forgejo. Use during cross-repo development so edits
// in ../Crafter.Asset are picked up without commit-and-pull. Add to
// depArgs too so transitive deps inherit the same mode.
bool useLocal = false;
for (std::string_view a : args) {
if (a == "--local") { useLocal = true; break; }
}
if (useLocal && std::find(depArgs.begin(), depArgs.end(), std::string("--local")) == depArgs.end()) {
depArgs.push_back("--local");
}
auto resolveDep = [&](std::string_view name, std::string_view gitUrl) -> Configuration* {
if (useLocal) {
return LocalProject({
.projectFile = fs::path("../") / name / "project.cpp",
.args = depArgs,
});
}
return GitProject({
.source = { .url = std::string(gitUrl) },
.args = depArgs,
});
};
Configuration* event = resolveDep("Crafter.Event", "https://forgejo.catcrafts.net/Catcrafts/Crafter.Event.git");
Configuration* math = resolveDep("Crafter.Math", "https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git");
Configuration* asset = resolveDep("Crafter.Asset", "https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git");
2026-04-30 01:29:17 +02:00
Configuration cfg;
cfg.path = "./";
cfg.name = "Crafter.Graphics";
cfg.outputName = "Crafter.Graphics";
cfg.type = ConfigurationType::LibraryStatic;
auto opts = ApplyStandardArgs(cfg, args);
cfg.dependencies = { event, math, asset };
// Window backend follows the target triple. V1 had separate lib-wayland /
// lib-win32 configurations; V2 picks the right one automatically based on
// where the build is going. Cross-compile (`--target=...`) flips the
// backend along with everything else.
bool windows = cfg.target.find("windows") != std::string::npos
|| cfg.target.find("mingw") != std::string::npos;
if (windows) {
cfg.defines.push_back({"CRAFTER_GRAPHICS_WINDOW_WIN32", ""});
cfg.linkFlags.push_back("-lkernel32");
cfg.linkFlags.push_back("-luser32");
cfg.linkFlags.push_back("-lgdi32");
2026-05-12 00:24:48 +02:00
// Windows.Gaming.Input (WGI) needs the WinRT activation runtime
// and combase for HSTRING / RoGetActivationFactory.
cfg.linkFlags.push_back("-lruntimeobject");
cfg.linkFlags.push_back("-lcombase");
2026-04-30 01:29:17 +02:00
} else {
cfg.defines.push_back({"CRAFTER_GRAPHICS_WINDOW_WAYLAND", ""});
cfg.linkFlags.push_back("-lwayland-client");
cfg.linkFlags.push_back("-lxkbcommon");
2026-05-12 00:24:48 +02:00
// Gamepad: libudev for hot-plug + device enumeration; libevdev
// for event parsing + axis calibration. libevdev ships its headers
// under a versioned dir (libevdev-1.0/) so the -I is mandatory.
cfg.linkFlags.push_back("-ludev");
cfg.linkFlags.push_back("-levdev");
cfg.compileFlags.push_back("-I/usr/include/libevdev-1.0");
2026-04-30 01:29:17 +02:00
cfg.cFiles.push_back("lib/xdg-shell-protocol");
cfg.cFiles.push_back("lib/wayland-xdg-decoration-unstable-v1-client-protocol");
cfg.cFiles.push_back("lib/fractional-scale-v1");
cfg.cFiles.push_back("lib/viewporter");
}
2026-05-01 23:35:37 +02:00
// Vulkan is the only renderer. Software fallback is provided externally
// via the Vulkan loader (e.g. llvmpipe / lavapipe) — no separate code path.
ExternalDependency& vkHeaders = cfg.externalDependencies.emplace_back();
vkHeaders.name = "Vulkan-Headers";
vkHeaders.source.url = "https://github.com/KhronosGroup/Vulkan-Headers.git";
vkHeaders.builder = ExternalBuilder::None;
vkHeaders.includeDirs = { "include" };
ExternalDependency& vkUtility = cfg.externalDependencies.emplace_back();
vkUtility.name = "Vulkan-Utility-Libraries";
vkUtility.source.url = "https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git";
vkUtility.builder = ExternalBuilder::None;
vkUtility.includeDirs = { "include" };
cfg.linkFlags.push_back(windows ? "-lvulkan-1" : "-lvulkan");
2026-04-30 01:29:17 +02:00
if (opts.Has("--timing")) cfg.defines.push_back({"CRAFTER_TIMING", ""});
2026-05-12 00:24:48 +02:00
std::array<fs::path, 29> ifaces = {
2026-04-30 01:29:17 +02:00
"interfaces/Crafter.Graphics",
"interfaces/Crafter.Graphics-Animation",
2026-05-12 00:24:48 +02:00
"interfaces/Crafter.Graphics-Clipboard",
2026-05-02 21:08:20 +02:00
"interfaces/Crafter.Graphics-ComputeShader",
2026-05-12 00:24:48 +02:00
"interfaces/Crafter.Graphics-Decompress",
2026-04-30 01:29:17 +02:00
"interfaces/Crafter.Graphics-DescriptorHeapVulkan",
"interfaces/Crafter.Graphics-Device",
"interfaces/Crafter.Graphics-Font",
2026-05-02 21:08:20 +02:00
"interfaces/Crafter.Graphics-FontAtlas",
2026-04-30 01:29:17 +02:00
"interfaces/Crafter.Graphics-ForwardDeclarations",
2026-05-12 00:24:48 +02:00
"interfaces/Crafter.Graphics-Gamepad",
2026-04-30 01:29:17 +02:00
"interfaces/Crafter.Graphics-ImageVulkan",
2026-05-12 00:24:48 +02:00
"interfaces/Crafter.Graphics-Input",
2026-05-03 02:45:38 +02:00
"interfaces/Crafter.Graphics-InputField",
2026-05-12 00:24:48 +02:00
"interfaces/Crafter.Graphics-Keys",
2026-04-30 01:29:17 +02:00
"interfaces/Crafter.Graphics-Mesh",
"interfaces/Crafter.Graphics-PipelineRTVulkan",
"interfaces/Crafter.Graphics-RenderingElement3D",
2026-05-01 23:35:37 +02:00
"interfaces/Crafter.Graphics-RenderPass",
"interfaces/Crafter.Graphics-RTPass",
2026-04-30 01:29:17 +02:00
"interfaces/Crafter.Graphics-SamplerVulkan",
"interfaces/Crafter.Graphics-ShaderBindingTableVulkan",
"interfaces/Crafter.Graphics-ShaderVulkan",
"interfaces/Crafter.Graphics-Types",
2026-05-01 23:35:37 +02:00
"interfaces/Crafter.Graphics-UI",
2026-05-02 21:08:20 +02:00
"interfaces/Crafter.Graphics-UIComponents",
2026-04-30 01:29:17 +02:00
"interfaces/Crafter.Graphics-VulkanBuffer",
"interfaces/Crafter.Graphics-VulkanTransition",
"interfaces/Crafter.Graphics-Window",
};
2026-05-12 00:24:48 +02:00
std::array<fs::path, 13> impls = {
"implementations/Crafter.Graphics-Clipboard",
2026-05-02 21:08:20 +02:00
"implementations/Crafter.Graphics-ComputeShader",
2026-04-30 01:29:17 +02:00
"implementations/Crafter.Graphics-Device",
"implementations/Crafter.Graphics-Font",
2026-05-02 21:08:20 +02:00
"implementations/Crafter.Graphics-FontAtlas",
2026-05-12 00:24:48 +02:00
"implementations/Crafter.Graphics-Gamepad",
"implementations/Crafter.Graphics-Input",
2026-05-03 02:45:38 +02:00
"implementations/Crafter.Graphics-InputField",
2026-04-30 01:29:17 +02:00
"implementations/Crafter.Graphics-Mesh",
"implementations/Crafter.Graphics-RenderingElement3D",
2026-05-02 21:08:20 +02:00
"implementations/Crafter.Graphics-UI",
"implementations/Crafter.Graphics-UIComponents",
2026-04-30 01:29:17 +02:00
"implementations/Crafter.Graphics-Window",
};
cfg.GetInterfacesAndImplementations(ifaces, impls);
2026-05-02 21:08:20 +02:00
cfg.shaders.emplace_back(fs::path("shaders/ui-quads.comp.glsl"), std::string("main"), ShaderType::Compute);
cfg.shaders.emplace_back(fs::path("shaders/ui-circles.comp.glsl"), std::string("main"), ShaderType::Compute);
cfg.shaders.emplace_back(fs::path("shaders/ui-images.comp.glsl"), std::string("main"), ShaderType::Compute);
cfg.shaders.emplace_back(fs::path("shaders/ui-text.comp.glsl"), std::string("main"), ShaderType::Compute);
cfg.buildFiles.emplace_back(fs::path("shaders/ui-shared.glsl"));
2026-05-01 23:35:37 +02:00
2026-04-30 01:29:17 +02:00
return cfg;
}