webgpu: build dawn-common into a library

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-11-16 06:38:12 -07:00 committed by Stephen Gutekanst
parent 3c5be625af
commit 13d26d3587

View file

@ -27,6 +27,9 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
const lib_mach_dawn_native = buildLibMachDawnNative(b, step); const lib_mach_dawn_native = buildLibMachDawnNative(b, step);
step.linkLibrary(lib_mach_dawn_native); step.linkLibrary(lib_mach_dawn_native);
const lib_dawn_common = buildLibDawnCommon(b, step);
step.linkLibrary(lib_dawn_common);
// dawn-native dependencies // dawn-native dependencies
const lib_abseil_cpp = buildLibAbseilCpp(b, step); const lib_abseil_cpp = buildLibAbseilCpp(b, step);
step.linkLibrary(lib_abseil_cpp); step.linkLibrary(lib_abseil_cpp);
@ -43,7 +46,6 @@ fn buildLibDawn(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *
lib.linkLibCpp(); lib.linkLibCpp();
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
addCommonSources(b, lib, options, target);
addDawnPlatformSources(b, lib, options); addDawnPlatformSources(b, lib, options);
addDawnNativeSources(b, lib, options, target); addDawnNativeSources(b, lib, options, target);
addDawnWireSources(b, lib, options, target); addDawnWireSources(b, lib, options, target);
@ -70,9 +72,14 @@ fn buildLibMachDawnNative(b: *Builder, step: *std.build.LibExeObjStep) *std.buil
return lib; return lib;
} }
// Adds common sources; derived from src/common/BUILD.gn // Builds common sources; derived from src/common/BUILD.gn
fn addCommonSources(b: *Builder, step: *std.build.LibExeObjStep, options: Options, target: std.Target) void { fn buildLibDawnCommon(b: *Builder, step: *std.build.LibExeObjStep) *std.build.LibExeObjStep {
_ = options; var main_abs = std.fs.path.join(b.allocator, &.{ thisDir(), "src/dawn/dummy.zig" }) catch unreachable;
const lib = b.addStaticLibrary("dawn-common", main_abs);
lib.setBuildMode(step.build_mode);
lib.setTarget(step.target);
lib.linkLibCpp();
for ([_][]const u8{ for ([_][]const u8{
"src/common/Assert.cpp", "src/common/Assert.cpp",
"src/common/DynamicLib.cpp", "src/common/DynamicLib.cpp",
@ -85,13 +92,17 @@ fn addCommonSources(b: *Builder, step: *std.build.LibExeObjStep, options: Option
"src/common/SystemUtils.cpp", "src/common/SystemUtils.cpp",
}) |path| { }) |path| {
var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), "libs/dawn", path }) catch unreachable; var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), "libs/dawn", path }) catch unreachable;
step.addCSourceFile(abs_path, &.{include("libs/dawn/src")}); lib.addCSourceFile(abs_path, &.{include("libs/dawn/src")});
} }
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
if (target.os.tag == .macos) { if (target.os.tag == .macos) {
system_sdk.include(b, lib, .{});
lib.linkFramework("Foundation");
var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), "libs/dawn/src/common/SystemUtils_mac.mm" }) catch unreachable; var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), "libs/dawn/src/common/SystemUtils_mac.mm" }) catch unreachable;
step.addCSourceFile(abs_path, &.{include("libs/dawn/src")}); lib.addCSourceFile(abs_path, &.{include("libs/dawn/src")});
} }
return lib;
} }
// Adds dawn platform sources; derived from src/dawn_platform/BUILD.gn // Adds dawn platform sources; derived from src/dawn_platform/BUILD.gn