|
1 | 1 | const std = @import("std"); |
| 2 | +const Step = std.Build.Step; |
2 | 3 |
|
3 | | -pub fn build(b: *std.Build) void { |
| 4 | +const ImplementationDesc = struct { |
| 5 | + name: []const u8, |
| 6 | + root_source_file: []const u8, |
| 7 | +}; |
| 8 | + |
| 9 | +const implementations = [_]ImplementationDesc{ |
| 10 | + .{ |
| 11 | + .name = "soft", |
| 12 | + .root_source_file = "src/soft/lib.zig", |
| 13 | + }, |
| 14 | +}; |
| 15 | + |
| 16 | +pub fn build(b: *std.Build) !void { |
4 | 17 | const target = b.standardTargetOptions(.{}); |
5 | 18 | const optimize = b.standardOptimizeOption(.{}); |
6 | 19 |
|
7 | | - const lib_mod = b.createModule(.{ |
8 | | - .root_source_file = b.path("src/lib.zig"), |
| 20 | + const libvulkan_mod = b.createModule(.{ |
| 21 | + .root_source_file = b.path("src/vulkan/lib.zig"), |
9 | 22 | .target = target, |
10 | 23 | .optimize = optimize, |
11 | 24 | }); |
12 | 25 |
|
13 | | - const lib = b.addLibrary(.{ |
| 26 | + const vulkan = b.dependency("vulkan_zig", .{ |
| 27 | + .registry = b.dependency("vulkan_headers", .{}).path("registry/vk.xml"), |
| 28 | + }).module("vulkan-zig"); |
| 29 | + |
| 30 | + libvulkan_mod.addImport("vulkan", vulkan); |
| 31 | + |
| 32 | + const libvulkan = b.addLibrary(.{ |
14 | 33 | .name = "vulkan", |
15 | | - .root_module = lib_mod, |
| 34 | + .root_module = libvulkan_mod, |
16 | 35 | .linkage = .dynamic, |
17 | 36 | }); |
18 | 37 |
|
19 | | - b.installArtifact(lib); |
| 38 | + b.installArtifact(libvulkan); |
20 | 39 |
|
21 | | - const lib_tests = b.addTest(.{ |
22 | | - .root_module = lib_mod, |
| 40 | + for (implementations) |impl| { |
| 41 | + b.installArtifact(try buildImplementation(b, target, optimize, &impl, vulkan)); |
| 42 | + } |
| 43 | + |
| 44 | + const libvulkan_tests = b.addTest(.{ |
| 45 | + .root_module = libvulkan_mod, |
23 | 46 | }); |
24 | 47 |
|
25 | | - const run_lib_tests = b.addRunArtifact(lib_tests); |
| 48 | + const run_libvulkan_tests = b.addRunArtifact(libvulkan_tests); |
26 | 49 |
|
27 | 50 | const test_step = b.step("test", "Run tests"); |
28 | | - test_step.dependOn(&run_lib_tests.step); |
| 51 | + test_step.dependOn(&run_libvulkan_tests.step); |
| 52 | +} |
| 53 | + |
| 54 | +fn buildImplementation( |
| 55 | + b: *std.Build, |
| 56 | + target: std.Build.ResolvedTarget, |
| 57 | + optimize: std.builtin.OptimizeMode, |
| 58 | + desc: *const ImplementationDesc, |
| 59 | + vulkan_bindings: *std.Build.Module, |
| 60 | +) !*Step.Compile { |
| 61 | + const lib_mod = b.createModule(.{ |
| 62 | + .root_source_file = b.path(desc.root_source_file), |
| 63 | + .target = target, |
| 64 | + .optimize = optimize, |
| 65 | + }); |
| 66 | + |
| 67 | + lib_mod.addImport("vulkan", vulkan_bindings); |
| 68 | + |
| 69 | + return b.addLibrary(.{ |
| 70 | + .name = try std.fmt.allocPrint(b.allocator, "vulkan_{s}", .{desc.name}), |
| 71 | + .root_module = lib_mod, |
| 72 | + .linkage = .dynamic, |
| 73 | + }); |
29 | 74 | } |
0 commit comments