-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
64 lines (48 loc) · 2.02 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "kickstart_glfw_example",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const xml_path: []const u8 = b.pathFromRoot("vk.xml");
const vkzig_dep = b.dependency("vulkan", .{
.registry = xml_path,
});
const kickstart_dep = b.dependency("vk_kickstart", .{
.registry = xml_path,
.enable_validation = if (optimize == .Debug) true else false,
.verbose = true,
});
exe.root_module.addImport("vk-kickstart", kickstart_dep.module("vk-kickstart"));
exe.root_module.addImport("vulkan", vkzig_dep.module("vulkan-zig"));
const glfw = b.dependency("glfw", .{
.target = target,
.optimize = .ReleaseFast,
});
exe.linkLibrary(glfw.artifact("glfw"));
addShader(b, exe, "shaders/shader.vert", "shader_vert");
addShader(b, exe, "shaders/shader.frag", "shader_frag");
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
fn addShader(b: *std.Build, step: *std.Build.Step.Compile, path: []const u8, name: []const u8) void {
var hasher = std.hash.Wyhash.init(0);
hasher.update(path);
const hash = hasher.final();
const hex = std.fmt.allocPrint(b.allocator, "{x}", .{hash}) catch @panic("OOM");
const output_name = std.mem.join(b.allocator, "", &.{ hex, ".spv" }) catch @panic("OOM");
const shaderc = b.addSystemCommand(&.{ "glslc", "--target-env=vulkan1.2", "-o" });
const shader_spv = shaderc.addOutputFileArg(output_name);
shaderc.addFileArg(b.path(path));
step.root_module.addAnonymousImport(name, .{ .root_source_file = shader_spv });
}