zig-webgpu-gen

git clone git://git.electrosoup.com/zig-webgpu-gen
Log | Files | Refs

commit 83a4801c7d2ec8e05d76e129ea6bb99b493c1885
parent d7e3dfb74fdb7c4f197cdb80dd2d56ebc79f13a5
Author: Christian Ermann <christianermann@gmail.com>
Date:   Sun, 17 May 2026 14:28:22 -0700

Link against wgpu-native

Diffstat:
Mbuild.zig | 48+++++++++++++++++++++++++++++++++++++++++-------
Mbuild.zig.zon | 22+++++++++++++++++++++-
2 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/build.zig b/build.zig @@ -1,14 +1,39 @@ const std = @import("std"); -pub fn build(b: *std.Build) void { +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const webgpu_headers = b.dependency("webgpu_headers", .{ - .target = target, - .optimize = optimize, - }); - const webgpu_json = webgpu_headers.path("webgpu.json"); + const webgpu_headers = b.lazyDependency("webgpu_headers", .{}); + const wgpu_native = try switch (target.result.os.tag) { + .linux => switch (target.result.cpu.arch) { + .x86_64 => switch (optimize) { + .Debug => b.lazyDependency( + "wgpu_native_linux_x86_64_debug", + .{}, + ), + .ReleaseFast, .ReleaseSafe, .ReleaseSmall => b.lazyDependency( + "wgpu_native_linux_x86_64_release", + .{}, + ), + }, + else => error.NotSupported, + }, + .macos => switch (target.result.cpu.arch) { + .x86_64 => switch (optimize) { + .Debug => b.lazyDependency( + "wgpu_native_macos_x86_64_debug", + .{}, + ), + .ReleaseFast, .ReleaseSafe, .ReleaseSmall => b.lazyDependency( + "wgpu_native_macos_x86_64_release", + .{}, + ), + }, + else => error.NotSupported, + }, + else => error.NotSupported, + }; const exe_mod = b.createModule(.{ .root_source_file = b.path("src/main.zig"), @@ -20,7 +45,10 @@ pub fn build(b: *std.Build) void { .root_module = exe_mod, }); const run_cmd = b.addRunArtifact(exe); - run_cmd.addFileArg(webgpu_json); + if (webgpu_headers) |dep| { + const webgpu_json = dep.path("webgpu.json"); + run_cmd.addFileArg(webgpu_json); + } const gen_file = run_cmd.addOutputFileArg("webgpu.zig"); const install_raw = b.addInstallFile(gen_file, "webgpu-raw.zig"); @@ -38,6 +66,7 @@ pub fn build(b: *std.Build) void { .root_source_file = gen_file, .target = target, .optimize = optimize, + .link_libc = true, }); const lib = b.addLibrary(.{ .linkage = .static, @@ -46,5 +75,10 @@ pub fn build(b: *std.Build) void { }); lib.step.dependOn(&fmt_cmd.step); + if (wgpu_native) |dep| { + const wgpu_lib = dep.path("lib/libwgpu_native.a"); + lib_mod.addObjectFile(wgpu_lib); + } + b.installArtifact(lib); } diff --git a/build.zig.zon b/build.zig.zon @@ -68,7 +68,27 @@ .webgpu_headers = .{ .url = "https://github.com/webgpu-native/webgpu-headers/archive/7d3186c3dd2c708703524027b46b8703534ab3cc.tar.gz", .hash = "N-V-__8AAKfVCwACaVDbxAcElqWNITTDQQSvqtRBmFQOAqNe", - .lazy = false + .lazy = true, + }, + .wgpu_native_macos_x86_64_debug = .{ + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-macos-x86_64-debug.zip", + .hash = "N-V-__8AAD3zzgk2_Za_1BnKJTDKjIWKAybnN_AREgeWnU7c", + .lazy = true, + }, + .wgpu_native_macos_x86_64_release = .{ + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-macos-x86_64-release.zip", + .hash = "N-V-__8AAF0KeQIPjq2ZGVZ2r_mwwK6lDxHhxsko_HfbMLqO", + .lazy = true, + }, + .wgpu_native_linux_x86_64_debug = .{ + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-linux-x86_64-debug.zip", + .hash = "N-V-__8AAI0zpRP5NvcMEE7UL_eWX3DbOhCbLnzOMGg44neR", + .lazy = true, + }, + .wgpu_native_linux_x86_64_release = .{ + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-linux-x86_64-release.zip", + .hash = "N-V-__8AAO3k0AME91yU7p-wkAjsf9Fudl9z8rFKgyS-aTY9", + .lazy = true, }, },