Skip to content

Commit

Permalink
update to Zig 2024.1.0-mach
Browse files Browse the repository at this point in the history
helps hexops/mach#1135

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
  • Loading branch information
slimsag committed Jan 13, 2024
1 parent 26d2da2 commit bcf91a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
47 changes: 20 additions & 27 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,30 @@ pub fn build(b: *std.Build) !void {
};

const module = b.addModule("mach-gpu", .{
.source_file = .{ .path = "src/main.zig" },
.root_source_file = .{ .path = "src/main.zig" },
});
gpu_dawn.addPathsToModule(b, module, gpu_dawn_options);
module.addIncludePath(.{ .path = sdkPath("/src") });

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&(try testStep(b, optimize, target, .{ .gpu_dawn_options = gpu_dawn_options })).step);

const main_tests = b.addTest(.{
.name = "gpu-tests",
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
.target = target,
.optimize = optimize,
});
try link(b, main_tests, .{ .gpu_dawn_options = gpu_dawn_options });
b.installArtifact(main_tests);
test_step.dependOn(&b.addRunArtifact(main_tests).step);

const example = b.addExecutable(.{
.name = "gpu-hello-triangle",
.root_source_file = .{ .path = "examples/main.zig" },
.target = target,
.optimize = optimize,
});
example.addModule("gpu", module);
example.root_module.addImport("gpu", module);

try link(b, example, .{ .gpu_dawn_options = gpu_dawn_options });

Expand All @@ -31,14 +42,8 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
});
example.addModule("glfw", glfw_dep.module("mach-glfw"));
@import("mach_glfw").link(
b.dependency("mach_glfw", .{
.target = target,
.optimize = optimize,
}).builder,
example,
);
example.root_module.addImport("glfw", glfw_dep.module("mach-glfw"));
@import("mach_glfw").addPaths(example);

b.installArtifact(example);

Expand All @@ -48,28 +53,16 @@ pub fn build(b: *std.Build) !void {
example_run_step.dependOn(&example_run_cmd.step);
}

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",
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
.target = target,
.optimize = optimize,
});
try link(b, main_tests, options);
b.installArtifact(main_tests);
return b.addRunArtifact(main_tests);
}

pub const Options = struct {
gpu_dawn_options: gpu_dawn.Options = .{},
};

pub fn link(b: *std.Build, step: *std.build.CompileStep, options: Options) !void {
if (step.target.toTarget().cpu.arch != .wasm32) {
pub fn link(b: *std.Build, step: *std.Build.Step.Compile, options: Options) !void {
if (step.rootModuleTarget().cpu.arch != .wasm32) {
gpu_dawn.link(
b.dependency("mach_gpu_dawn", .{
.target = step.target,
.optimize = step.optimize,
.target = step.root_module.resolved_target.?,
.optimize = step.root_module.optimize.?,
}).builder,
step,
options.gpu_dawn_options,
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
},
.dependencies = .{
.mach_glfw = .{
.url = "https://pkg.machengine.org/mach-glfw/20d247fa4b70c0b3951cb3c439d3466f204754e1.tar.gz",
.hash = "1220533928f944fe59f6dd2807db71cd69108cc810101e627835c3abcc4afea4fb06",
.url = "https://pkg.machengine.org/mach-glfw/10b1e64333f4962d94e13fdd12f970d8cfe6ac75.tar.gz",
.hash = "1220b353b101648ba4782a49130a2f9498513f502055012184cefd76d847885aad5c",
},
.mach_gpu_dawn = .{
.url = "https://pkg.machengine.org/mach-gpu-dawn/5fe75438b824f92798c6d511d2502049f4a09c9f.tar.gz",
.hash = "1220c54d7621c0a12abefb0fbf61769eb1d054ae21990b85c079bf36ae5b8d4f1cbe",
.url = "https://pkg.machengine.org/mach-gpu-dawn/4d1b85f19c67b76fcfca9a8964a03d3cb4c3e624.tar.gz",
.hash = "12204fa11af4fa1c67c49bfb934f59fa0a94a3c825b4d01715998292aaa4733c081b",
},
},
}

0 comments on commit bcf91a0

Please sign in to comment.