gpu: update to latest Zig build API

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-02-08 01:38:55 -07:00 committed by Stephen Gutekanst
parent 0f71895634
commit fc45fd594e
2 changed files with 25 additions and 17 deletions

View file

@ -4,8 +4,8 @@ const gpu_dawn_sdk = @import("libs/mach-gpu-dawn/sdk.zig");
const gpu_sdk = @import("sdk.zig"); const gpu_sdk = @import("sdk.zig");
const system_sdk = @import("libs/mach-glfw/system_sdk.zig"); const system_sdk = @import("libs/mach-glfw/system_sdk.zig");
pub fn build(b: *std.build.Builder) !void { pub fn build(b: *std.Build) !void {
const mode = b.standardReleaseOptions(); const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const gpu_dawn = gpu_dawn_sdk.Sdk(.{ const gpu_dawn = gpu_dawn_sdk.Sdk(.{
.glfw_include_dir = "libs/mach-glfw/upstream/glfw/include", .glfw_include_dir = "libs/mach-glfw/upstream/glfw/include",
@ -21,13 +21,16 @@ pub fn build(b: *std.build.Builder) !void {
}; };
const test_step = b.step("test", "Run library tests"); const test_step = b.step("test", "Run library tests");
test_step.dependOn(&(try gpu.testStep(b, mode, target, .{ .gpu_dawn_options = gpu_dawn_options })).step); test_step.dependOn(&(try gpu.testStep(b, optimize, target, .{ .gpu_dawn_options = gpu_dawn_options })).step);
const example = b.addExecutable("gpu-hello-triangle", "examples/main.zig"); const example = b.addExecutable(.{
example.setBuildMode(mode); .name = "gpu-hello-triangle",
example.setTarget(target); .root_source_file = .{ .path = "examples/main.zig" },
example.addPackage(gpu.pkg); .target = target,
example.addPackage(glfw.pkg); .optimize = optimize,
});
example.addModule("gpu", gpu.module(b));
example.addModule("glfw", glfw.module(b));
try gpu.link(b, example, .{ .gpu_dawn_options = gpu_dawn_options }); try gpu.link(b, example, .{ .gpu_dawn_options = gpu_dawn_options });
try glfw.link(b, example, .{}); try glfw.link(b, example, .{});
example.install(); example.install();

View file

@ -2,10 +2,14 @@ const std = @import("std");
pub fn Sdk(comptime deps: anytype) type { pub fn Sdk(comptime deps: anytype) type {
return struct { return struct {
pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) !*std.build.RunStep { pub fn testStep(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, options: Options) !*std.build.RunStep {
const main_tests = b.addTestExe("gpu-tests", sdkPath("/src/main.zig")); const main_tests = b.addTest(.{
main_tests.setBuildMode(mode); .name = "gpu-tests",
main_tests.setTarget(target); .kind = .test_exe,
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
.target = target,
.optimize = optimize,
});
try link(b, main_tests, options); try link(b, main_tests, options);
main_tests.install(); main_tests.install();
return main_tests.run(); return main_tests.run();
@ -15,12 +19,13 @@ pub fn Sdk(comptime deps: anytype) type {
gpu_dawn_options: deps.gpu_dawn.Options = .{}, gpu_dawn_options: deps.gpu_dawn.Options = .{},
}; };
pub const pkg = std.build.Pkg{ pub fn module(b: *std.Build) *std.build.Module {
.name = "gpu", return b.createModule(.{
.source = .{ .path = sdkPath("/src/main.zig") }, .source_file = .{ .path = sdkPath("/src/main.zig") },
}; });
}
pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep, options: Options) !void { pub fn link(b: *std.Build, step: *std.build.CompileStep, options: Options) !void {
if (step.target.toTarget().cpu.arch != .wasm32) { if (step.target.toTarget().cpu.arch != .wasm32) {
try deps.gpu_dawn.link(b, step, options.gpu_dawn_options); try deps.gpu_dawn.link(b, step, options.gpu_dawn_options);
step.addCSourceFile(sdkPath("/src/mach_dawn.cpp"), &.{"-std=c++17"}); step.addCSourceFile(sdkPath("/src/mach_dawn.cpp"), &.{"-std=c++17"});