-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
70 lines (61 loc) · 2.56 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
65
66
67
68
69
70
const std = @import("std");
const build_lib = std.build;
const Builder = build_lib.Builder;
const builtin = std.builtin;
const path = std.fs.path;
const GLFWDependencies = [_][]const u8{
"c",
"user32",
"gdi32",
"shell32",
};
const vulkan_library = "E:/Libraries/VulkanSDK/1.2.148.1/Lib/vulkan-1.lib";
const glfw_library = "E:/Libraries/glfw/build/src/Release/glfw3.lib";
fn linkVulkanGLFWAndDependencies(step: *build_lib.LibExeObjStep) void {
step.addObjectFile(vulkan_library);
step.addObjectFile(glfw_library);
for (GLFWDependencies) |dep| {
step.linkSystemLibrary(dep);
}
}
fn doCommonStuff(lib_or_tests: anytype, build_mode: builtin.Mode) void {
lib_or_tests.addIncludeDir(".");
lib_or_tests.addPackagePath("ZigZag", "../ZigZag/main.zig");
lib_or_tests.setBuildMode(build_mode);
linkVulkanGLFWAndDependencies(lib_or_tests);
}
fn addShader(b: *Builder, in_file: []const u8, out_file: []const u8) !*build_lib.RunStep {
const dirname = "Shaders";
const full_in = try path.join(b.allocator, &[_][]const u8{ dirname, in_file });
defer b.allocator.free(full_in);
const full_out = try path.join(b.allocator, &[_][]const u8{ dirname, out_file });
defer b.allocator.free(full_out);
return b.addSystemCommand(&[_][]const u8{
"glslangValidator",
"-V100",
"-e",
"main",
// "--vn",
// "shader_data",
"-o",
full_out,
full_in,
});
}
pub fn build(b: *Builder) !void {
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("ZigVulkan", "main.zig");
doCommonStuff(lib, mode);
lib.install();
var main_tests = b.addTest("main.zig");
doCommonStuff(main_tests, mode);
main_tests.step.dependOn(&(try addShader(b, "fixed_rectangle.vert.hlsl", "fixed_rectangle.vert.spr")).step);
main_tests.step.dependOn(&(try addShader(b, "white.frag.hlsl", "white.frag.spr")).step);
main_tests.step.dependOn(&(try addShader(b, "fixed_uv_rectangle.vert.hlsl", "fixed_uv_rectangle.vert.spr")).step);
main_tests.step.dependOn(&(try addShader(b, "textured.frag.hlsl", "textured.frag.spr")).step);
main_tests.step.dependOn(&(try addShader(b, "plain_rectangle.vert.hlsl", "plain_rectangle.vert.spr")).step);
main_tests.step.dependOn(&(try addShader(b, "textured_rectangle.vert.hlsl", "textured_rectangle.vert.spr")).step);
main_tests.step.dependOn(&(try addShader(b, "plain_colour.frag.hlsl", "plain_colour.frag.spr")).step);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
}