-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.zig
231 lines (211 loc) · 8.22 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
const std = @import("std");
const os = std.os;
var is_release = true;
pub fn generate_fonts(b: *std.Build) !*std.Build.Step.Run {
const full = std.builtin.OptimizeMode.ReleaseSafe;
const native_target = b.resolveTargetQuery(.{});
const native_rl = try build_raylib(b, native_target, full);
var generateFont = b.addExecutable(.{
.name = "generate_shaders",
.target = native_target,
.optimize = full,
});
generateFont.addCSourceFile(.{ .file = b.path("./tools/font_export.c") });
generateFont.addCSourceFile(.{ .file = b.path("./src/str.c") });
generateFont.addIncludePath(b.path("."));
generateFont.addIncludePath(b.path("./external/raylib-5.0/src"));
generateFont.linkLibrary(native_rl);
generateFont.linkLibC();
var ret = b.addRunArtifact(generateFont);
ret.addArg("./fonts/PlayfairDisplayRegular-ywLOY.ttf");
ret.addArg("src/misc/default_font.h");
return ret;
}
pub fn generate_shaders(b: *std.Build) !*std.Build.Step.Run {
const full = std.builtin.OptimizeMode.ReleaseSafe;
const native_target = b.resolveTargetQuery(.{});
const native_rl = try build_raylib(b, native_target, full);
var shaderGen = b.addExecutable(.{
.name = "generate_shaders",
.target = native_target,
.optimize = full,
});
shaderGen.addCSourceFile(.{ .file = b.path("./tools/shaders_bake.c") });
shaderGen.addCSourceFile(.{ .file = b.path("./src/str.c") });
shaderGen.addIncludePath(b.path("./external/raylib-5.0/src"));
shaderGen.addIncludePath(b.path("./src"));
shaderGen.addIncludePath(b.path("."));
shaderGen.linkLibC();
shaderGen.linkLibrary(native_rl);
var ret = b.addRunArtifact(shaderGen);
ret.addArg("WINDOWS");
ret.addArg(".generated/shaders.h");
return ret;
}
pub fn build_raylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step.Compile {
const raylib = b.addStaticLibrary(.{
.name = b.fmt("raylib_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(optimize) }),
.target = target,
.optimize = optimize,
});
const raylibSources = .{
"./external/raylib-5.0/src/rmodels.c",
"./external/raylib-5.0/src/rshapes.c",
"./external/raylib-5.0/src/rtext.c",
"./external/raylib-5.0/src/rtextures.c",
"./external/raylib-5.0/src/utils.c",
"./external/raylib-5.0/src/rcore.c",
};
inline for (raylibSources) |source| {
raylib.addCSourceFile(.{ .file = b.path(source) });
}
switch (target.result.os.tag) {
.windows => {
raylib.addCSourceFile(.{ .file = b.path("./external/raylib-5.0/src/rglfw.c") });
raylib.linkSystemLibrary("winmm");
raylib.linkSystemLibrary("gdi32");
raylib.linkSystemLibrary("opengl32");
raylib.defineCMacro("PLATFORM_DESKTOP", null);
},
.linux, .freebsd => {
raylib.linkSystemLibrary("glfw");
raylib.defineCMacro("PLATFORM_DESKTOP", null);
},
.macos => {
var raylib_flags_arr: std.ArrayListUnmanaged([]const u8) = .{};
raylib_flags_arr.clearRetainingCapacity();
try raylib_flags_arr.append(b.allocator, "-ObjC");
raylib.addCSourceFile(.{
.file = b.path("./external/raylib-5.0/src/rglfw.c"),
.flags = raylib_flags_arr.items,
});
raylib_flags_arr.deinit(b.allocator);
raylib.linkFramework("Foundation");
raylib.linkFramework("CoreServices");
raylib.linkFramework("CoreGraphics");
raylib.linkFramework("AppKit");
raylib.linkFramework("IOKit");
raylib.defineCMacro("PLATFORM_DESKTOP", null);
},
else => {
unreachable();
},
}
raylib.linkLibC();
raylib.addIncludePath(b.path("."));
raylib.addIncludePath(b.path("./external/glfw/include"));
return raylib;
}
pub fn build_imgui(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile {
const imgui = b.addStaticLibrary(.{
.name = b.fmt("imgui_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(optimize) }),
.target = target,
.optimize = optimize,
});
const imguiSources = .{
"./external/imgui-docking/imgui.cpp",
"./external/imgui-docking/imgui.cpp",
"./external/imgui-docking/imgui_draw.cpp",
"./external/imgui-docking/imgui_tables.cpp",
"./external/imgui-docking/imgui_widgets.cpp",
"./external/imgui-docking/backends/imgui_impl_glfw.cpp",
"./external/imgui-docking/backends/imgui_impl_opengl3.cpp",
};
inline for (imguiSources) |source| {
imgui.addCSourceFile(.{ .file = b.path(source) });
}
imgui.linkLibC();
imgui.linkLibCpp();
imgui.addIncludePath(b.path("./external/imgui-docking"));
imgui.addIncludePath(b.path("./external/glfw/include"));
return imgui;
}
const gui_kind_t = enum { imgui, raylib, headless };
pub fn build_brplot(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, kind: gui_kind_t) !*std.Build.Step.Compile {
is_release = optimize != std.builtin.OptimizeMode.Debug;
const exe = b.addExecutable(.{
.name = b.fmt("brplot_{s}_{s}_{s}", .{ @tagName(kind), @tagName(target.result.os.tag), @tagName(optimize) }),
.target = target,
.optimize = optimize,
});
const raylib = try build_raylib(b, target, optimize);
const imgui = build_imgui(b, target, optimize);
exe.addCSourceFiles(.{ .files = &.{
"./src/data.c",
"./src/data_generator.c",
"./src/filesystem++.cpp",
"./src/filesystem.c",
"./src/graph_utils.c",
"./src/gui++.cpp",
"./src/gui.c",
"./src/help.c",
"./src/keybindings.c",
"./src/main.c",
"./src/memory.cpp",
"./src/permastate.c",
"./src/plot.c",
"./src/plotter.c",
"./src/q.c",
"./src/read_input.c",
"./src/resampling2.c",
"./src/shaders.c",
"./src/smol_mesh.c",
"./src/str.c",
"./src/platform.c",
} });
exe.addIncludePath(b.path("."));
exe.addIncludePath(b.path("./src"));
exe.addIncludePath(b.path("./external/raylib-5.0/src"));
exe.addIncludePath(b.path("./external/Tracy"));
exe.linkLibC();
exe.defineCMacro("PLATFORM_DESKTOP", "1");
if (is_release) {
exe.defineCMacro("RELEASE", "1");
exe.step.dependOn(&(try generate_shaders(b)).step);
}
switch (kind) {
.raylib => {
exe.linkLibrary(raylib);
exe.defineCMacro("RAYLIB", null);
},
.imgui => {
exe.linkLibrary(raylib);
exe.linkLibrary(imgui);
exe.addIncludePath(b.path("./external/imgui-docking"));
exe.addIncludePath(b.path("./src/imgui"));
exe.defineCMacro("IMGUI", null);
},
.headless => {
exe.defineCMacro("NUMBER_OF_STEPS", "100");
exe.defineCMacro("HEADLESS", null);
},
}
exe.linkLibCpp();
exe.step.dependOn(&(try generate_fonts(b)).step);
return exe;
}
pub fn build_all(b: *std.Build, target: std.Build.ResolvedTarget) !void {
inline for (std.meta.fields(std.builtin.OptimizeMode)) |optim| {
inline for (std.meta.fields(gui_kind_t)) |kind| {
const brplot = try build_brplot(b, target, @enumFromInt(optim.value), @enumFromInt(kind.value));
b.installArtifact(brplot);
}
}
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const gui_kind = b.option(gui_kind_t, "Gui", "Gui Kind") orelse gui_kind_t.imgui;
const all = b.option(bool, "All", "Build all targets") orelse false;
if (all) {
try build_all(b, target);
} else {
const brplot = try build_brplot(b, target, optimize, gui_kind);
b.installArtifact(brplot);
}
// const run_cmd = b.addRunArtifact(brplot);
// run_cmd.step.dependOn(b.getInstallStep());
//
// const run_step = b.step("run", "Run the app");
// run_step.dependOn(&run_cmd.step);
}