asset compression

This commit is contained in:
Jorijn van der Graaf 2026-05-11 18:37:30 +02:00
commit 30a283c1b3
57 changed files with 13237 additions and 8 deletions

View file

@ -4,29 +4,76 @@ namespace fs = std::filesystem;
using namespace Crafter;
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
GitProjectSpec mathSpec{
.source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git" },
.args = std::vector<std::string>(args.begin(), args.end()),
};
Configuration* math = GitProject(mathSpec);
std::vector<std::string> depArgs(args.begin(), args.end());
bool useLocal = false;
for (std::string_view a : args) {
if (a == "--local") { useLocal = true; break; }
}
Configuration* math = useLocal
? LocalProject({
.projectFile = "../Crafter.Math/project.cpp",
.args = depArgs,
})
: GitProject({
.source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git" },
.args = depArgs,
});
Configuration cfg;
cfg.path = "./";
cfg.name = "Crafter.Asset";
// Default to library so consumers (Crafter.Graphics, examples) link against
// libCrafter.Asset.a — the Compression module's non-template entry points
// need to be in a real archive, not just PCM-inline. `--exe` (via the
// example's main.cpp) flips us to Executable to produce crafter-asset.
cfg.type = ConfigurationType::LibraryStatic;
ApplyStandardArgs(cfg, args);
bool wantExe = false;
for (std::string_view a : args) {
if (a == "--exe") { wantExe = true; break; }
}
if (wantExe) cfg.type = ConfigurationType::Executable;
cfg.outputName = (cfg.type == ConfigurationType::Executable) ? "crafter-asset" : "Crafter.Asset";
cfg.dependencies = { math };
std::array<fs::path, 3> ifaces = {
// Vendored GDeflate (Apache-2.0, Microsoft DirectStorage reference) +
// libdeflate (MIT, NVIDIA fork). The C++ wrappers live inline in the
// Compression module impl; libdeflate's .c sources are compiled here.
cfg.compileFlags.push_back("-Ilib/gdeflate/libdeflate");
const std::array<fs::path, 12> libdeflateSources = {
"lib/gdeflate/libdeflate/lib/adler32",
"lib/gdeflate/libdeflate/lib/crc32",
"lib/gdeflate/libdeflate/lib/deflate_compress",
"lib/gdeflate/libdeflate/lib/deflate_decompress",
"lib/gdeflate/libdeflate/lib/gdeflate_compress",
"lib/gdeflate/libdeflate/lib/gdeflate_decompress",
"lib/gdeflate/libdeflate/lib/gzip_compress",
"lib/gdeflate/libdeflate/lib/gzip_decompress",
"lib/gdeflate/libdeflate/lib/utils",
"lib/gdeflate/libdeflate/lib/zlib_compress",
"lib/gdeflate/libdeflate/lib/zlib_decompress",
"lib/gdeflate/libdeflate/lib/x86/cpu_features",
};
for (const fs::path& p : libdeflateSources) cfg.cFiles.push_back(p);
std::array<fs::path, 4> ifaces = {
"interfaces/Crafter.Asset",
"interfaces/Crafter.Asset-Compression",
"interfaces/Crafter.Asset-Texture",
"interfaces/Crafter.Asset-Mesh",
};
if (cfg.type == ConfigurationType::Executable) {
std::array<fs::path, 1> impls = { "implementations/main" };
std::array<fs::path, 2> impls = {
"implementations/Crafter.Asset-Compression",
"implementations/main",
};
cfg.GetInterfacesAndImplementations(ifaces, impls);
} else {
std::array<fs::path, 0> impls = {};
std::array<fs::path, 1> impls = {
"implementations/Crafter.Asset-Compression",
};
cfg.GetInterfacesAndImplementations(ifaces, impls);
}