Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 47 additions & 41 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,54 +110,60 @@ pub fn build(b: *std.Build) void {
},
});

const zdawn = b.addLibrary(.{
.name = "zdawn",
.use_llvm = true,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
b.installArtifact(zdawn);
const test_step = b.step("test", "Run zgpu tests");

linkSystemDeps(b, zdawn);
addLibraryPathsTo(zdawn);
// Emscripten builds are expected to link against the toolchain-provided WebGPU
// implementation (e.g. `--use-port=emdawnwebgpu`), so we skip building `zdawn`.
if (target.result.os.tag != .emscripten) {
const zdawn = b.addLibrary(.{
.name = "zdawn",
.use_llvm = true,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
b.installArtifact(zdawn);

zdawn.linkSystemLibrary("dawn");
zdawn.linkLibC();
if (target.result.abi != .msvc)
zdawn.linkLibCpp();
linkSystemDeps(b, zdawn);
addLibraryPathsTo(zdawn);

zdawn.addIncludePath(b.path("libs/dawn/include"));
zdawn.addIncludePath(b.path("src"));
zdawn.linkSystemLibrary("dawn");
zdawn.linkLibC();
if (target.result.abi != .msvc)
zdawn.linkLibCpp();

zdawn.addCSourceFile(.{
.file = b.path("src/dawn.cpp"),
.flags = &.{ "-std=c++17", "-fno-sanitize=undefined" },
});
zdawn.addCSourceFile(.{
.file = b.path("src/dawn_proc.c"),
.flags = &.{"-fno-sanitize=undefined"},
});
zdawn.addIncludePath(b.path("libs/dawn/include"));
zdawn.addIncludePath(b.path("src"));

const test_step = b.step("test", "Run zgpu tests");
zdawn.addCSourceFile(.{
.file = b.path("src/dawn.cpp"),
.flags = &.{ "-std=c++17", "-fno-sanitize=undefined" },
});
zdawn.addCSourceFile(.{
.file = b.path("src/dawn_proc.c"),
.flags = &.{"-fno-sanitize=undefined"},
});

const tests = b.addTest(.{
.name = "zgpu-tests",
.use_llvm = true,
.root_module = b.createModule(.{
.root_source_file = b.path("src/zgpu.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.addIncludePath(b.path("libs/dawn/include"));
tests.linkLibrary(zdawn);
linkSystemDeps(b, tests);
addLibraryPathsTo(tests);
b.installArtifact(tests);
const tests = b.addTest(.{
.name = "zgpu-tests",
.use_llvm = true,
.root_module = b.createModule(.{
.root_source_file = b.path("src/zgpu.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.root_module.addImport("zgpu_options", options_module);
tests.root_module.addImport("zpool", b.dependency("zpool", .{}).module("root"));
tests.addIncludePath(b.path("libs/dawn/include"));
tests.linkLibrary(zdawn);
linkSystemDeps(b, tests);
addLibraryPathsTo(tests);
b.installArtifact(tests);

test_step.dependOn(&b.addRunArtifact(tests).step);
test_step.dependOn(&b.addRunArtifact(tests).step);
}
}

pub fn linkSystemDeps(b: *std.Build, compile_step: *std.Build.Step.Compile) void {
Expand Down
Loading
Loading