gpu: update to latest Zig build API
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
0f71895634
commit
fc45fd594e
2 changed files with 25 additions and 17 deletions
|
|
@ -4,8 +4,8 @@ const gpu_dawn_sdk = @import("libs/mach-gpu-dawn/sdk.zig");
|
|||
const gpu_sdk = @import("sdk.zig");
|
||||
const system_sdk = @import("libs/mach-glfw/system_sdk.zig");
|
||||
|
||||
pub fn build(b: *std.build.Builder) !void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const gpu_dawn = gpu_dawn_sdk.Sdk(.{
|
||||
.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");
|
||||
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");
|
||||
example.setBuildMode(mode);
|
||||
example.setTarget(target);
|
||||
example.addPackage(gpu.pkg);
|
||||
example.addPackage(glfw.pkg);
|
||||
const example = b.addExecutable(.{
|
||||
.name = "gpu-hello-triangle",
|
||||
.root_source_file = .{ .path = "examples/main.zig" },
|
||||
.target = target,
|
||||
.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 glfw.link(b, example, .{});
|
||||
example.install();
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@ const std = @import("std");
|
|||
|
||||
pub fn Sdk(comptime deps: anytype) type {
|
||||
return struct {
|
||||
pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) !*std.build.RunStep {
|
||||
const main_tests = b.addTestExe("gpu-tests", sdkPath("/src/main.zig"));
|
||||
main_tests.setBuildMode(mode);
|
||||
main_tests.setTarget(target);
|
||||
pub fn testStep(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, options: Options) !*std.build.RunStep {
|
||||
const main_tests = b.addTest(.{
|
||||
.name = "gpu-tests",
|
||||
.kind = .test_exe,
|
||||
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
try link(b, main_tests, options);
|
||||
main_tests.install();
|
||||
return main_tests.run();
|
||||
|
|
@ -15,12 +19,13 @@ pub fn Sdk(comptime deps: anytype) type {
|
|||
gpu_dawn_options: deps.gpu_dawn.Options = .{},
|
||||
};
|
||||
|
||||
pub const pkg = std.build.Pkg{
|
||||
.name = "gpu",
|
||||
.source = .{ .path = sdkPath("/src/main.zig") },
|
||||
};
|
||||
pub fn module(b: *std.Build) *std.build.Module {
|
||||
return b.createModule(.{
|
||||
.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) {
|
||||
try deps.gpu_dawn.link(b, step, options.gpu_dawn_options);
|
||||
step.addCSourceFile(sdkPath("/src/mach_dawn.cpp"), &.{"-std=c++17"});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue