-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
40 lines (31 loc) · 1.16 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const std = @import("std");
const path = std.fs.path;
const Builder = std.build.Builder;
pub fn build(b: *Builder) !void {
const exe = b.addExecutable("triangle", "src/main.zig");
exe.setBuildMode(b.standardReleaseOptions());
exe.linkSystemLibrary("c");
exe.linkSystemLibrary("glfw");
exe.linkSystemLibrary("vulkan");
exe.install();
// Shaders
try b.makePath(try path.join(b.allocator, &[_][]const u8{ b.cache_root, "s" }));
const opt = switch (exe.build_mode) {
.Debug => "-O0",
.ReleaseSafe, .ReleaseFast => "-O",
.ReleaseSmall => "-Os",
};
try buildShader(b, opt, "triangle.vert");
try buildShader(b, opt, "triangle.frag");
}
fn buildShader(b: *Builder, optim_lvl: []const u8, comptime shader: []const u8) !void {
const output = try path.join(b.allocator, &[_][]const u8{
b.cache_root, "s", shader ++ ".spv",
});
// TODO Recompile on modification only
const cmd = b.addSystemCommand(&[_][]const u8{
"glslc", optim_lvl, "-o", output, "shaders/" ++ shader,
});
b.default_step.dependOn(&cmd.step);
b.installBinFile(output, "shaders/" ++ shader ++ ".spv");
}