Skip to content

Commit 425ae65

Browse files
committed
improving zig build
1 parent b3bc3c7 commit 425ae65

6 files changed

Lines changed: 65 additions & 12 deletions

File tree

build.zig

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,74 @@
11
const std = @import("std");
2+
const Step = std.Build.Step;
23

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 {
417
const target = b.standardTargetOptions(.{});
518
const optimize = b.standardOptimizeOption(.{});
619

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"),
922
.target = target,
1023
.optimize = optimize,
1124
});
1225

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(.{
1433
.name = "vulkan",
15-
.root_module = lib_mod,
34+
.root_module = libvulkan_mod,
1635
.linkage = .dynamic,
1736
});
1837

19-
b.installArtifact(lib);
38+
b.installArtifact(libvulkan);
2039

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,
2346
});
2447

25-
const run_lib_tests = b.addRunArtifact(lib_tests);
48+
const run_libvulkan_tests = b.addRunArtifact(libvulkan_tests);
2649

2750
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+
});
2974
}

build.zig.zon

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
.fingerprint = 0x52cb73649f1107de,
55
.minimum_zig_version = "0.15.1",
66

7-
.dependencies = .{},
7+
.dependencies = .{
8+
.vulkan_headers = .{
9+
.url = "git+https://github.com/KhronosGroup/Vulkan-Headers?ref=v1.4.330#ee3b5caaa7e372715873c7b9c390ee1c3ca5db25",
10+
.hash = "N-V-__8AAFXYAQKsK51AAGXB9HziPDFjS_DVUq6_QHVxHrBM",
11+
},
12+
.vulkan_zig = .{
13+
.url = "git+https://github.com/catmeow72/vulkan-zig/#8961518db28f88d2cf09ea68e146923de2cfa7f0",
14+
.hash = "vulkan-0.0.0-r7Ytx6hBAwD8X_TN32qlkzul4riK6vFvjtK9fZfRvALg",
15+
},
16+
},
817

918
.paths = .{
1019
"build.zig",

src/lib.zig

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/soft/lib.zig

Whitespace-only changes.

src/vulkan/Object.zig

Whitespace-only changes.

src/vulkan/lib.zig

Whitespace-only changes.

0 commit comments

Comments
 (0)