-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.zig
More file actions
61 lines (48 loc) · 1.97 KB
/
Copy pathbuild.zig
File metadata and controls
61 lines (48 loc) · 1.97 KB
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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const vk_kickstart = b.dependency("vk_kickstart", .{
.verbose = true,
.target = target,
.optimize = optimize,
});
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("src/c.h"),
.target = target,
.optimize = optimize,
});
translate_c.linkSystemLibrary("glfw", .{});
const exe = b.addExecutable(.{
.name = "kickstart_glfw_example",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "vk-kickstart", .module = vk_kickstart.module("vk-kickstart") },
.{ .name = "vulkan", .module = vk_kickstart.module("vulkan") },
.{ .name = "c", .module = translate_c.createModule() },
},
}),
});
exe.root_module.linkSystemLibrary("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 {
const output_name = std.mem.concat(b.allocator, u8, &.{ path, ".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 });
}