-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.zig
132 lines (115 loc) · 3.67 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
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
fn AddShaderBuildCommand(b: *std.Build, dep_sokol_shdc: *std.Build.Dependency, inputPath: []const u8, outputPath: []const u8) *std.Build.Step.Run
{
const shdcPath = switch (builtin.os.tag) {
.windows => "bin/win32/sokol-shdc.exe",
.linux => "bin/linux/sokol-shdc",
.macos => switch (builtin.cpu.arch) {
.aarch64 =>"bin/osx_arm64/sokol-shdc",
.x86_64 =>"bin/osx/sokol-shdc",
else => @compileError("Sokol-shdc doesn't support this osx cpu's arhitecture."),
},
else => @compileError("Sokol-shdc is not supported on this machine. Shaders can't be compiled."),
};
const sokolShdc = b.addSystemCommand(&.{shdcPath, "--input"});
sokolShdc.setCwd(dep_sokol_shdc.path(""));
sokolShdc.addFileArg(b.path(inputPath));
sokolShdc.addArg("--output");
sokolShdc.addFileArg(b.path(outputPath));
sokolShdc.addArgs(&.{"--slang", "glsl410:hlsl4:metal_macos", "-b"});
return sokolShdc;
}
pub fn build(b: *std.Build) !void
{
const target = b.standardTargetOptions(.{});
if (target.result.os.tag != .linux and target.result.os.tag != .windows)
{
std.debug.print("{} is not supported as a build target.\n", .{target.result.os.tag});
std.process.exit(1);
}
if (target.result.cpu.arch != .x86_64)
{
std.debug.print("Only x86_64 is supported as a build target.\n", .{});
std.process.exit(1);
}
// TODO: ABI check?
const optimise = b.standardOptimizeOption(.{});
_ = try b.default_step.addDirectoryWatchInput(.{.cwd_relative = "code/*"});
const exe = b.addExecutable(.{
.name = "goldsrctosource",
.target = target,
.optimize = optimise,
.link_libc = true,
});
if (optimise == .Debug)
{
exe.defineCMacro("GC_DEBUG", "");
const debugGraphics = true;
if (debugGraphics)
{
const imgui = b.addStaticLibrary(.{
.name = "imgui",
.target = target,
.optimize = .ReleaseFast,
.link_libc = true,
});
imgui.addCSourceFiles(.{
.root = b.path("code/imgui"),
.files = &.{
"imgui.cpp", "imgui_draw.cpp",
"imgui_tables.cpp", "imgui_widgets.cpp", "imgui_demo.cpp",
"cimgui.cpp"
},
});
imgui.addIncludePath(b.path("code/imgui/"));
imgui.addIncludePath(b.path("code/"));
imgui.linkLibCpp();
const dep_sokol_shdc = b.dependency("sokol_shdc", .{});
const worldShader = AddShaderBuildCommand(b, dep_sokol_shdc,
"code/shaders/world.glsl",
"code/shaders_compiled/world.h");
const wireShader = AddShaderBuildCommand(b, dep_sokol_shdc,
"code/shaders/wire.glsl",
"code/shaders_compiled/wire.h");
b.default_step.dependOn(&worldShader.step);
b.default_step.dependOn(&wireShader.step);
exe.linkLibrary(imgui);
// TODO: sokol-shdc!!!!!!
exe.defineCMacro("DEBUG_GRAPHICS", "");
if (target.result.os.tag == .windows)
{
exe.linkSystemLibrary("gdi32");
}
else if (target.result.os.tag == .linux)
{
exe.linkSystemLibrary("x11");
exe.linkSystemLibrary("xi");
exe.linkSystemLibrary("xcursor");
exe.linkSystemLibrary("gl");
exe.linkSystemLibrary("rt");
}
}
if (target.result.os.tag == .linux)
{
exe.linkSystemLibrary("ubsan");
}
}
exe.linkLibC();
if (target.result.os.tag == .windows)
{
exe.addCSourceFile(.{
.file = b.path("code/win32_goldsrctosource.c"),
.flags = &.{"-std=c23", "-fmacro-backtrace-limit=0"},
});
}
else if (target.result.os.tag == .linux)
{
exe.addCSourceFile(.{
.file = b.path("code/linux_goldsrctosource.c"),
.flags = &.{"-fno-sanitize-trap=undefined", "-fmacro-backtrace-limit=0", "-std=c23"}
});
}
b.installArtifact(exe);
}