102 lines
3.2 KiB
Zig
102 lines
3.2 KiB
Zig
const std = @import("std");
|
|
const Step = std.Build.Step;
|
|
|
|
const ImplementationDesc = struct {
|
|
name: []const u8,
|
|
root_source_file: []const u8,
|
|
custom: ?*const fn (*std.Build, *std.Build.Module) anyerror!void = null,
|
|
};
|
|
|
|
const implementations = [_]ImplementationDesc{
|
|
.{
|
|
.name = "soft",
|
|
.root_source_file = "src/soft/lib.zig",
|
|
.custom = customSoft,
|
|
},
|
|
};
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const base_mod = b.createModule(.{
|
|
.root_source_file = b.path("src/vulkan/lib.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
});
|
|
|
|
const zdt = b.dependency("zdt", .{}).module("zdt");
|
|
const vulkan_headers = b.dependency("vulkan_headers", .{});
|
|
|
|
const vulkan = b.dependency("vulkan_zig", .{
|
|
.registry = vulkan_headers.path("registry/vk.xml"),
|
|
}).module("vulkan-zig");
|
|
|
|
base_mod.addImport("zdt", zdt);
|
|
base_mod.addImport("vulkan", vulkan);
|
|
base_mod.addSystemIncludePath(vulkan_headers.path("include"));
|
|
|
|
for (implementations) |impl| {
|
|
const lib_mod = b.createModule(.{
|
|
.root_source_file = b.path(impl.root_source_file),
|
|
.target = target,
|
|
.link_libc = true,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "base", .module = base_mod },
|
|
.{ .name = "vulkan", .module = vulkan },
|
|
},
|
|
});
|
|
|
|
lib_mod.addSystemIncludePath(vulkan_headers.path("include"));
|
|
|
|
if (impl.custom) |custom| {
|
|
custom(b, lib_mod) catch continue;
|
|
}
|
|
|
|
const lib = b.addLibrary(.{
|
|
.name = b.fmt("vulkan_{s}", .{impl.name}),
|
|
.root_module = lib_mod,
|
|
.linkage = .dynamic,
|
|
});
|
|
b.installArtifact(lib);
|
|
|
|
const lib_tests = b.addTest(.{ .root_module = lib_mod });
|
|
|
|
const run_tests = b.addRunArtifact(lib_tests);
|
|
const test_step = b.step(b.fmt("test-{s}", .{impl.name}), b.fmt("Run lib{s} tests", .{impl.name}));
|
|
test_step.dependOn(&run_tests.step);
|
|
|
|
const volk = b.lazyDependency("volk", .{}) orelse continue;
|
|
|
|
const c_test_exe = b.addExecutable(.{
|
|
.name = b.fmt("c_test_vulkan_{s}", .{impl.name}),
|
|
.root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
|
|
c_test_exe.root_module.addSystemIncludePath(volk.path(""));
|
|
|
|
c_test_exe.root_module.addCSourceFile(.{
|
|
.file = b.path("test/c/main.c"),
|
|
.flags = &.{b.fmt("-DLIBVK=\"{s}\"", .{lib.name})},
|
|
});
|
|
|
|
b.installArtifact(c_test_exe);
|
|
|
|
const run_c_test = b.addRunArtifact(c_test_exe);
|
|
const test_c_step = b.step(b.fmt("test-c-{s}", .{impl.name}), b.fmt("Run lib{s} C test", .{impl.name}));
|
|
test_c_step.dependOn(b.getInstallStep());
|
|
test_c_step.dependOn(&run_c_test.step);
|
|
}
|
|
}
|
|
|
|
fn customSoft(b: *std.Build, mod: *std.Build.Module) !void {
|
|
const cpuinfo = b.lazyDependency("cpuinfo", .{}) orelse return error.UnresolvedDependency;
|
|
mod.addImport("cpuinfo", cpuinfo.module("cpuinfo"));
|
|
}
|