66 lines
2.0 KiB
Zig
66 lines
2.0 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn addShaderDefinition(
|
|
b: *std.Build,
|
|
comptime sdl3Path: []const u8,
|
|
optimize: std.builtin.OptimizeMode,
|
|
shaderName: []const u8,
|
|
jsonPath: std.Build.LazyPath,
|
|
) *std.Build.Module {
|
|
const reflectedZig = b.addSystemCommand(&[_][]const u8{"python"});
|
|
reflectedZig.addArg(sdl3Path ++ "/spvreflect/spvreflect.py");
|
|
reflectedZig.addFileArg(jsonPath);
|
|
reflectedZig.addArg("--output");
|
|
|
|
const reflectedZigOut = reflectedZig.addOutputFileArg(b.fmt("reflected/{s}.zig", .{shaderName}));
|
|
const module = b.createModule(.{ .root_source_file = reflectedZigOut, .optimize = optimize });
|
|
|
|
const dep = b.dependency("shaderTypes", .{
|
|
.target = b.graph.host,
|
|
.optimize = optimize,
|
|
});
|
|
module.addImport("shaderTypes", dep.module("shaderTypes"));
|
|
|
|
return module;
|
|
}
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const sdl_dep = b.dependency("sdl", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
const sdl3_lib = sdl_dep.artifact("SDL3");
|
|
|
|
const mod = b.addModule("sdl3", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.root_source_file = b.path("src/sdl3.zig"),
|
|
});
|
|
|
|
mod.addIncludePath(b.path("SDL/include"));
|
|
mod.linkLibrary(sdl3_lib);
|
|
|
|
const test_step = b.step("test", "run unit tests for sdl3");
|
|
const tests = b.addExecutable(.{
|
|
.name = "hello-triangle",
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.root_source_file = b.path("src/samples/hello-triangle.zig"),
|
|
.link_libc = true,
|
|
});
|
|
|
|
tests.root_module.addImport("sdl3", mod);
|
|
|
|
const vertexDefinitions = addShaderDefinition(b, ".", optimize, "hello-triangle.vert", b.path("content/hello-triangle.vert.json"));
|
|
tests.root_module.addImport("hello-triangle.vert", vertexDefinitions);
|
|
|
|
const runArtifact = b.addRunArtifact(tests);
|
|
test_step.dependOn(&runArtifact.step);
|
|
|
|
b.installArtifact(tests);
|
|
}
|