Skip to content

Commit e5c78e8

Browse files
author
Stephen Gutekanst
committed
gpu-dawn: utilize binary releases for x86_64-windows-gnu
Closes hexops/mach#86 Signed-off-by: Stephen Gutekanst <[email protected]>
1 parent b10a160 commit e5c78e8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

build.zig

+15-6
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn ensureSubmodules(allocator: std.mem.Allocator) !void {
190190
pub fn linkFromBinary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
191191
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
192192
const binaries_available = switch (target.os.tag) {
193-
.windows => false, // TODO(build-system): add Windows binaries
193+
.windows => target.abi.isGnu(),
194194
.linux => target.cpu.arch.isX86() and (target.abi.isGnu() or target.abi.isMusl()),
195195
.macos => blk: {
196196
if (!target.cpu.arch.isX86() and !target.cpu.arch.isAARCH64()) break :blk false;
@@ -220,7 +220,7 @@ pub fn linkFromBinary(b: *Builder, step: *std.build.LibExeObjStep, options: Opti
220220
binary_target.os_version_max = .{ .none = .{} };
221221
binary_target.glibc_version = null;
222222
const zig_triple = binary_target.zigTriple(b.allocator) catch unreachable;
223-
ensureBinaryDownloaded(b.allocator, zig_triple, b.is_release, options.binary_version);
223+
ensureBinaryDownloaded(b.allocator, zig_triple, b.is_release, target.os.tag == .windows, options.binary_version);
224224

225225
const current_git_commit = getCurrentGitCommit(b.allocator) catch unreachable;
226226
const base_cache_dir_rel = std.fs.path.join(b.allocator, &.{ "zig-cache", "mach", "gpu-dawn" }) catch unreachable;
@@ -249,9 +249,13 @@ pub fn linkFromBinary(b: *Builder, step: *std.build.LibExeObjStep, options: Opti
249249
step.linkFramework("IOSurface");
250250
step.linkFramework("QuartzCore");
251251
}
252+
if (options.d3d12.?) {
253+
step.linkSystemLibrary("ole32");
254+
step.linkSystemLibrary("dxguid");
255+
}
252256
}
253257

254-
pub fn ensureBinaryDownloaded(allocator: std.mem.Allocator, zig_triple: []const u8, is_release: bool, version: []const u8) void {
258+
pub fn ensureBinaryDownloaded(allocator: std.mem.Allocator, zig_triple: []const u8, is_release: bool, is_windows: bool, version: []const u8) void {
255259
// If zig-cache/mach/gpu-dawn/<git revision> does not exist:
256260
// If on a commit in the main branch => rm -r zig-cache/mach/gpu-dawn/
257261
// else => noop
@@ -293,20 +297,25 @@ pub fn ensureBinaryDownloaded(allocator: std.mem.Allocator, zig_triple: []const
293297

294298
// Compose the download URL, e.g.:
295299
// https://github.com/hexops/mach-gpu-dawn/releases/download/release-6b59025/libdawn_x86_64-macos-gnu_debug.a.gz
300+
const lib_prefix = if (is_windows) "dawn_" else "libdawn_";
301+
const lib_ext = if (is_windows) ".lib" else ".a";
302+
const lib_file_name = if (is_windows) "dawn.lib" else "libdawn.a";
296303
const download_url = std.mem.concat(allocator, u8, &.{
297304
"https://github.com/hexops/mach-gpu-dawn/releases/download/",
298305
version,
299-
"/libdawn_",
306+
"/",
307+
lib_prefix,
300308
github_triple,
301309
"_",
302310
release_tag,
303-
".a.gz",
311+
lib_ext,
312+
".gz",
304313
}) catch unreachable;
305314

306315
// Download and decompress libdawn
307316
const gz_target_file = std.fs.path.join(allocator, &.{ download_dir, "compressed.gz" }) catch unreachable;
308317
downloadFile(allocator, gz_target_file, download_url) catch unreachable;
309-
const target_file = std.fs.path.join(allocator, &.{ target_cache_dir, "libdawn.a" }) catch unreachable;
318+
const target_file = std.fs.path.join(allocator, &.{ target_cache_dir, lib_file_name }) catch unreachable;
310319
gzipDecompress(allocator, gz_target_file, target_file) catch unreachable;
311320

312321
// If we don't yet have the headers (these are shared across architectures), download them.

0 commit comments

Comments
 (0)