Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit 9ff7cd0

Browse files
author
Stephen Gutekanst
committed
glfw: system_sdk: add Windows system SDK with updated DirectX headers
This effectively provides all you need to develop & cross compile DirectX 11/12 applications with `mach/glfw` (or just Zig in general, by copying `system_sdk.zig` into your own project.) Helps hexops/mach#86 Helps hexops/mach#59 Signed-off-by: Stephen Gutekanst <[email protected]>
1 parent d8079d6 commit 9ff7cd0

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

system_sdk.zig

+26-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ pub const Options = struct {
4848
linux_x86_64: []const u8 = "sdk-linux-x86_64",
4949
linux_x86_64_revision: []const u8 = "ab7fa8f3a05b06e0b06f4277b484e27004bfb20f",
5050

51+
/// The Windows x86-64 SDK repository name.
52+
windows_x86_64: []const u8 = "sdk-windows-x86_64",
53+
windows_x86_64_revision: []const u8 = "5acba990efd112ea0ced364f0428e6ef6e7a5541",
54+
5155
/// If true, the Builder.sysroot will set to the SDK path. This has the drawback of preventing
5256
/// you from including headers, libraries, etc. from outside the SDK generally. However, it can
5357
/// be useful in order to identify which libraries, headers, frameworks, etc. may be missing in
@@ -58,7 +62,7 @@ pub const Options = struct {
5862
pub fn include(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
5963
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
6064
switch (target.os.tag) {
61-
.windows => {},
65+
.windows => includeSdkWindowsX8664(b, step, options),
6266
.macos => includeSdkMacOS(b, step, options),
6367
else => includeSdkLinuxX8664(b, step, options), // Assume Linux-like for now
6468
}
@@ -113,6 +117,27 @@ fn includeSdkLinuxX8664(b: *Builder, step: *std.build.LibExeObjStep, options: Op
113117
step.addLibPath(sdk_root_libs);
114118
}
115119

120+
fn includeSdkWindowsX8664(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
121+
const sdk_root_dir = getSdkRoot(b.allocator, options.github_org, options.windows_x86_64, options.windows_x86_64_revision) catch unreachable;
122+
123+
if (options.set_sysroot) {
124+
// We have no sysroot for Windows, but we still set one to prevent inclusion of other system
125+
// libs (if set_sysroot is set, don't want to accidentally depend on system libs.)
126+
var sdk_sysroot = std.fs.path.join(b.allocator, &.{sdk_root_dir}) catch unreachable;
127+
b.sysroot = sdk_sysroot;
128+
}
129+
130+
var sdk_includes = std.fs.path.join(b.allocator, &.{ sdk_root_dir, "include" }) catch unreachable;
131+
var sdk_libs = std.fs.path.join(b.allocator, &.{ sdk_root_dir, "lib" }) catch unreachable;
132+
defer {
133+
b.allocator.free(sdk_includes);
134+
b.allocator.free(sdk_libs);
135+
}
136+
137+
step.addIncludeDir(sdk_includes);
138+
step.addLibPath(sdk_libs);
139+
}
140+
116141
var cached_sdk_root: ?[]const u8 = null;
117142

118143
/// returns the SDK root path, determining it iff necessary. In a real application, this may be

0 commit comments

Comments
 (0)