-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.zig
243 lines (225 loc) · 6.38 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
232
233
234
235
236
237
238
239
240
241
242
243
const std = @import("std");
const builtin = @import("builtin");
pub fn build(b: *std.Build) !void {
const options = .{
.zxaudio2_debug_layer = b.option(
bool,
"zxaudio2_debug_layer",
"Enable XAudio2 debug layer",
) orelse false,
.zd3d12_debug_layer = b.option(
bool,
"zd3d12_debug_layer",
"Enable DirectX 12 debug layer",
) orelse false,
.zd3d12_gbv = b.option(
bool,
"zd3d12_gbv",
"Enable DirectX 12 GPU-Based Validation (GBV)",
) orelse false,
};
const options_step = b.addOptions();
inline for (std.meta.fields(@TypeOf(options))) |field| {
options_step.addOption(field.type, field.name, @field(options, field.name));
}
const zwindows_module = b.addModule("zwindows", .{
.root_source_file = b.path("src/zwindows.zig"),
});
const options_module = options_step.createModule();
_ = b.addModule("zd3d12", .{
.root_source_file = b.path("src/zd3d12.zig"),
.imports = &.{
.{ .name = "options", .module = options_module },
.{ .name = "zwindows", .module = zwindows_module },
},
});
_ = b.addModule("zxaudio2", .{
.root_source_file = b.path("src/zxaudio2.zig"),
.imports = &.{
.{ .name = "options", .module = options_module },
.{ .name = "zwindows", .module = zwindows_module },
},
});
}
pub fn install_xaudio2(
step: *std.Build.Step,
zwindows: *std.Build.Dependency,
install_dir: std.Build.InstallDir,
) void {
const b = step.owner;
step.dependOn(
&b.addInstallFileWithDir(
.{ .dependency = .{
.dependency = zwindows,
.sub_path = "bin/x64/xaudio2_9redist.dll",
} },
install_dir,
"xaudio2_9redist.dll",
).step,
);
}
pub fn install_d3d12(
step: *std.Build.Step,
zwindows: *std.Build.Dependency,
install_dir: std.Build.InstallDir,
) void {
const b = step.owner;
step.dependOn(
&b.addInstallFileWithDir(
.{ .dependency = .{
.dependency = zwindows,
.sub_path = "bin/x64/D3D12Core.dll",
} },
install_dir,
"d3d12/D3D12Core.dll",
).step,
);
step.dependOn(
&b.addInstallFileWithDir(
.{ .dependency = .{
.dependency = zwindows,
.sub_path = "bin/x64/D3D12SDKLayers.dll",
} },
install_dir,
"d3d12/D3D12SDKLayers.dll",
).step,
);
}
pub fn install_directml(
step: *std.Build.Step,
zwindows: *std.Build.Dependency,
install_dir: std.Build.InstallDir,
) void {
const b = step.owner;
step.dependOn(
&b.addInstallFileWithDir(
.{ .dependency = .{
.dependency = zwindows,
.sub_path = "bin/x64/DirectML.dll",
} },
install_dir,
"DirectML.dll",
).step,
);
step.dependOn(
&b.addInstallFileWithDir(
.{ .dependency = .{
.dependency = zwindows,
.sub_path = "bin/x64/DirectML.Debug.dll",
} },
install_dir,
"DirectML.Debug.dll",
).step,
);
}
pub const CompileShaders = struct {
step: *std.Build.Step,
zwindows: *std.Build.Dependency,
shader_ver: []const u8,
pub fn addVsShader(
self: CompileShaders,
input_path: []const u8,
entry_point: []const u8,
output_filename: []const u8,
define: []const u8,
) void {
self.addShader(
input_path,
entry_point,
output_filename,
"vs",
define,
);
}
pub fn addPsShader(
self: CompileShaders,
input_path: []const u8,
entry_point: []const u8,
output_filename: []const u8,
define: []const u8,
) void {
self.addShader(
input_path,
entry_point,
output_filename,
"ps",
define,
);
}
pub fn addCsShader(
self: CompileShaders,
input_path: []const u8,
entry_point: []const u8,
output_filename: []const u8,
define: []const u8,
) void {
self.addShader(
input_path,
entry_point,
output_filename,
"cs",
define,
);
}
pub fn addMsShader(
self: CompileShaders,
input_path: []const u8,
entry_point: []const u8,
output_filename: []const u8,
define: []const u8,
) void {
self.addShader(
input_path,
entry_point,
output_filename,
"ms",
define,
);
}
pub fn addShader(
self: CompileShaders,
input_path: []const u8,
entry_point: []const u8,
output_filename: []const u8,
profile: []const u8,
define: []const u8,
) void {
const b = self.step.owner;
const dxc_path = switch (builtin.target.os.tag) {
.windows => self.zwindows.path("bin/x64/dxc.exe").getPath(b),
.linux => self.zwindows.path("bin/x64/dxc").getPath(b),
else => @panic("Unsupported target"),
};
const dxc_command = [9][]const u8{
dxc_path,
input_path,
b.fmt("/E {s}", .{entry_point}),
b.fmt("/Fo {s}", .{output_filename}),
b.fmt("/T {s}_{s}", .{ profile, self.shader_ver }),
if (define.len == 0) "" else b.fmt("/D {s}", .{define}),
"/WX",
"/Ges",
"/O3",
};
const cmd_step = b.addSystemCommand(&dxc_command);
if (builtin.target.os.tag == .linux) {
cmd_step.setEnvironmentVariable(
"LD_LIBRARY_PATH",
self.zwindows.path("bin/x64").getPath(b),
);
}
self.step.dependOn(&cmd_step.step);
}
};
pub fn addCompileShaders(
b: *std.Build,
comptime name: []const u8,
zwindows: *std.Build.Dependency,
options: struct { shader_ver: []const u8 },
) CompileShaders {
return .{
.step = b.step(name ++ "-dxc", "Build shaders for '" ++ name ++ "'"),
.zwindows = zwindows,
.shader_ver = options.shader_ver,
};
}