Skip to content

Commit c29e0fe

Browse files
committed
Add activateSdk to build.zig, update README
1 parent bd3ed2a commit c29e0fe

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,29 @@ pub fn build(b: *std.Build) !void {
2727
2828
...
2929
30-
const zwindows_dependency = b.dependency("zwindows", .{
30+
const zwindows = b.dependency("zwindows", .{
3131
.zxaudio2_debug_layer = (builtin.mode == .Debug),
3232
.zd3d12_debug_layer = (builtin.mode == .Debug),
3333
.zd3d12_gbv = b.option("zd3d12_gbv", "Enable GPU-Based Validation") orelse false,
3434
});
35+
36+
// Activate the sdk. This does things like ensure executables are executable by the system user.
37+
const activate_zwindows = @import("zwindows").activateSdk(b, zwindows);
38+
exe.step.dependOn(activate_zwindows);
3539
3640
// Import the Windows API bindings
37-
exe.root_module.addImport("zwindows", zwindows_dependency.module("zwindows"));
41+
exe.root_module.addImport("zwindows", zwindows.module("zwindows"));
3842
3943
// Import the optional zd3d12 helper library
40-
exe.root_module.addImport("zd3d12", zwindows_dependency.module("zd3d12"));
44+
exe.root_module.addImport("zd3d12", zwindows.module("zd3d12"));
4145
4246
// Import the optional zxaudio2 helper library
43-
exe.root_module.addImport("zxaudio2", zwindows_dependency.module("zxaudio2"));
47+
exe.root_module.addImport("zxaudio2", zwindows.module("zxaudio2"));
4448
4549
// Install vendored binaries
46-
const zwindows = @import("zwindows");
47-
try zwindows.install_xaudio2(&exe.step, zwindows_dependency, .bin);
48-
try zwindows.install_d3d12(&exe.step, zwindows_dependency, .bin);
49-
try zwindows.install_directml(&exe.step, zwindows_dependency, .bin);
50+
try @import("zwindows").install_xaudio2(&exe.step, zwindows, .bin);
51+
try @import("zwindows").install_d3d12(&exe.step, zwindows, .bin);
52+
try @import("zwindows").install_directml(&exe.step, zwindows, .bin);
5053
}
5154
```
5255

build.zig

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ pub fn build(b: *std.Build) !void {
4848
});
4949
}
5050

51+
pub fn activateSdk(b: *std.Build, zwindows: *std.Build.Dependency) *std.Build.Step {
52+
const step = b.allocator.create(std.Build.Step) catch unreachable;
53+
step.* = std.Build.Step.init(.{
54+
.id = .custom,
55+
.name = "Activate zwindows",
56+
.owner = b,
57+
.makeFn = &struct {
58+
fn make(_: *std.Build.Step, _: std.Build.Step.MakeOptions) anyerror!void {}
59+
}.make,
60+
});
61+
switch (builtin.target.os.tag) {
62+
.windows => {
63+
const dxc_path = zwindows.path("bin/x64/dxc.exe").getPath(b);
64+
step.dependOn(&b.addSystemCommand(&.{ "takeown", "/f", dxc_path }).step);
65+
},
66+
.linux => {
67+
const dxc_path = zwindows.path("bin/x64/dxc").getPath(b);
68+
step.dependOn(&b.addSystemCommand(&.{ "chmod", "+x", dxc_path }).step);
69+
},
70+
else => @panic("Unsupported host OS."),
71+
}
72+
return step;
73+
}
74+
5175
pub fn install_xaudio2(
5276
step: *std.Build.Step,
5377
zwindows: *std.Build.Dependency,
@@ -203,7 +227,7 @@ pub const CompileShaders = struct {
203227
const dxc_path = switch (builtin.target.os.tag) {
204228
.windows => self.zwindows.path("bin/x64/dxc.exe").getPath(b),
205229
.linux => self.zwindows.path("bin/x64/dxc").getPath(b),
206-
else => @panic("Unsupported target"),
230+
else => @panic("Unsupported host OS."),
207231
};
208232

209233
const dxc_command = [9][]const u8{
@@ -236,26 +260,8 @@ pub fn addCompileShaders(
236260
zwindows: *std.Build.Dependency,
237261
options: struct { shader_ver: []const u8 },
238262
) CompileShaders {
239-
const build_shaders = b.step(name ++ "-dxc", "Build shaders for '" ++ name ++ "'");
240-
241-
const dxc_path = switch (builtin.target.os.tag) {
242-
.windows => zwindows.path("bin/x64/dxc.exe").getPath(b),
243-
.linux => zwindows.path("bin/x64/dxc").getPath(b),
244-
else => @panic("Unsupported target"),
245-
};
246-
switch (builtin.target.os.tag) {
247-
.windows => {
248-
const takeown = b.addSystemCommand(&.{ "takeown", "/f", dxc_path });
249-
build_shaders.dependOn(&takeown.step);
250-
},
251-
else => {
252-
const chmod = b.addSystemCommand(&.{ "chmod", "+x", dxc_path });
253-
build_shaders.dependOn(&chmod.step);
254-
},
255-
}
256-
257263
return .{
258-
.step = build_shaders,
264+
.step = b.step(name ++ "-dxc", "Build shaders for '" ++ name ++ "'"),
259265
.zwindows = zwindows,
260266
.shader_ver = options.shader_ver,
261267
};

0 commit comments

Comments
 (0)