-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
78 lines (61 loc) · 2.64 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
71
72
73
74
75
76
77
78
const std = @import("std");
const path = std.fs.path;
const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
const ig_build = @import("zig-imgui/imgui_build.zig");
const glslc_command = if (std.builtin.os.tag == .windows) "tools/win/glslc.exe" else "glslc";
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
ig_build.addTestStep(b, "imgui:test", "zig-imgui/imgui", mode, target);
const exe = b.addExecutable("zig-gltf", "src/main.zig");
setDependencies(exe, mode, target);
exe.install();
const run_step = b.step("run", "Run the project");
const run_cmd = exe.run();
run_step.dependOn(&run_cmd.step);
const tests = b.addTest("src/all_tests.zig");
setDependencies(tests, mode, target);
const vscode_exe = b.addExecutable("vscode", "src/main.zig");
setDependencies(vscode_exe, mode, target);
const vscode_install = b.addInstallArtifact(vscode_exe);
const vscode_step = b.step("vscode", "Build for VSCode");
vscode_step.dependOn(&vscode_install.step);
const run_tests = b.step("test", "Run all tests");
run_tests.dependOn(&tests.step);
}
fn setDependencies(step: *LibExeObjStep, mode: std.builtin.Mode, target: std.zig.CrossTarget) void {
step.setBuildMode(mode);
step.linkLibCpp();
ig_build.link(step, "zig-imgui/imgui");
step.addPackagePath("vk", "include/vk.zig");
step.addPackagePath("glfw", "include/glfw.zig");
step.addPackagePath("cgltf", "include/cgltf.zig");
if (target.getOs().tag == .windows) {
step.addObjectFile(if (target.getAbi() == .msvc) "lib/win/glfw3.lib" else "lib/win/libglfw3.a");
step.addObjectFile("lib/win/vulkan-1.lib");
step.linkSystemLibrary("gdi32");
step.linkSystemLibrary("shell32");
if (step.kind == .exe) {
step.subsystem = .Windows;
}
} else {
step.linkSystemLibrary("glfw");
step.linkSystemLibrary("vulkan");
}
step.addCSourceFile("c_src/cgltf.c", &[_][]const u8{ "-std=c99", "-DCGLTF_IMPLEMENTATION", "-D_CRT_SECURE_NO_WARNINGS" });
}
fn addShader(b: *Builder, exe: anytype, in_file: []const u8, out_file: []const u8) !void {
// example:
// glslc -o shaders/vert.spv shaders/shader.vert
const dirname = "shaders";
const full_in = try path.join(b.allocator, &[_][]const u8{ dirname, in_file });
const full_out = try path.join(b.allocator, &[_][]const u8{ dirname, out_file });
const run_cmd = b.addSystemCommand(&[_][]const u8{
glslc_command,
"-o",
full_out,
full_in,
});
exe.step.dependOn(&run_cmd.step);
}