-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
118 lines (101 loc) · 4.48 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const std = @import("std");
const glfw = @import("mach_glfw");
pub fn linkTracy(b: *std.Build, step: *std.Build.Step.Compile, opt_path: ?[]const u8) void {
const step_options = b.addOptions();
step_options.addOption(bool, "tracy_enabled", opt_path != null);
step.root_module.addOptions("build_options", step_options);
if (opt_path) |path| {
step.addIncludePath(b.path(path));
const tracy_client_source_path = std.fs.path.join(step.step.owner.allocator, &.{ path, "TracyClient.cpp" }) catch unreachable;
step.addCSourceFile(.{
.file = b.path(tracy_client_source_path),
.flags = &[_][]const u8{
"-DTRACY_ENABLE",
"-DTRACY_FIBERS",
// MinGW doesn't have all the newfangled windows features,
// so we need to pretend to have an older windows version.
"-D_WIN32_WINNT=0x601",
"-fno-sanitize=undefined",
},
});
step.linkLibC();
step.linkSystemLibrary("c++");
if (step.rootModuleTarget().os.tag == .windows) {
step.linkSystemLibrary("Advapi32");
step.linkSystemLibrary("User32");
step.linkSystemLibrary("Ws2_32");
step.linkSystemLibrary("DbgHelp");
}
}
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const use_tracy = b.option(bool, "tracy", "Build the game with Tracy support") orelse (optimize == .Debug);
const exe = b.addExecutable(.{
.name = "stella-dei",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.strip = optimize == .ReleaseFast or optimize == .ReleaseSmall;
exe.linkLibC();
if (optimize != .Debug) exe.subsystem = .Windows;
linkTracy(b, exe, if (use_tracy) "deps/tracy-0.8.2/" else null);
// Modules
const gl = b.createModule(.{
.root_source_file = b.path("deps/gl3v3.zig"),
});
exe.root_module.addImport("gl", gl);
const nanovg = b.createModule(.{
.root_source_file = b.path("deps/nanovg/src/nanovg.zig"),
});
exe.root_module.addImport("nanovg", nanovg);
const nanovg_c_flags = &.{ "-DFONS_NO_STDIO", "-DSTBI_NO_STDIO", "-fno-stack-protector", "-fno-sanitize=undefined" };
nanovg.addIncludePath(b.path("deps/nanovg/src"));
nanovg.addCSourceFiles(.{
.files = &.{
"deps/nanovg/src/fontstash.c",
"deps/nanovg/src/stb_image.c",
},
.flags = nanovg_c_flags,
});
const zalgebra_dep = b.dependency("zalgebra", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("zalgebra", zalgebra_dep.module("zalgebra"));
const zigimg_dep = b.dependency("zigimg", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("zigimg", zigimg_dep.module("zigimg"));
const glfw_dep = b.dependency("mach_glfw", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("glfw", glfw_dep.module("mach-glfw"));
exe.addIncludePath(b.path("deps"));
exe.addCSourceFile(.{
.file = b.path("deps/miniaudio.c"),
.flags = &.{
"-fno-sanitize=undefined", // disable UBSAN (due to false positives)
},
});
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);
var exe_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_tests.linkLibC();
exe_tests.root_module.addImport("nanovg", nanovg);
exe_tests.root_module.addImport("glfw", glfw_dep.module("mach-glfw"));
exe_tests.root_module.addImport("gl", gl);
exe_tests.root_module.addImport("zigimg", zigimg_dep.module("zigimg"));
exe_tests.root_module.addImport("zalgebra", zalgebra_dep.module("zalgebra"));
exe_tests.addIncludePath(b.path("deps/nanovg/src"));
exe_tests.addCSourceFile(.{ .file = b.path("deps/nanovg/src/fontstash.c"), .flags = nanovg_c_flags });
exe_tests.addCSourceFile(.{ .file = b.path("deps/nanovg/src/stb_image.c"), .flags = nanovg_c_flags });
exe_tests.addIncludePath(b.path("deps"));
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
}