webgpu support

This commit is contained in:
Jorijn van der Graaf 2026-05-18 04:58:52 +02:00
commit dedf6b0467
22 changed files with 1656 additions and 324 deletions

View file

@ -4,6 +4,14 @@ namespace fs = std::filesystem;
using namespace Crafter;
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
bool isWasm = false;
for (std::string_view a : args) {
if (a.starts_with("--target=") && a.find("wasm") != std::string_view::npos) {
isWasm = true;
break;
}
}
Configuration* graphics = LocalProject({
.projectFile = "../../project.cpp",
.args = std::vector<std::string>(args.begin(), args.end()),
@ -13,6 +21,11 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
cfg.path = "./";
cfg.name = "HelloUI";
cfg.outputName = "HelloUI";
cfg.type = ConfigurationType::Executable;
if (isWasm) {
cfg.target = "wasm32-wasip1";
cfg.defines.push_back({"CRAFTER_GRAPHICS_WINDOW_DOM", ""});
}
ApplyStandardArgs(cfg, args);
cfg.dependencies = { graphics };
@ -21,5 +34,9 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
cfg.GetInterfacesAndImplementations(ifaces, impls);
cfg.files.push_back("font.ttf");
if (isWasm) {
EnableWasiBrowserRuntime(cfg);
}
return cfg;
}