From 8faba1992740a31c2c18e970837572c39a1f47a6 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Tue, 28 Oct 2025 15:25:52 +0100 Subject: [PATCH] improving zig build --- build.zig | 65 ++++++++++++++++++++++++++++++++++++------- build.zig.zon | 11 +++++++- src/lib.zig | 1 - src/soft/lib.zig | 0 src/vulkan/Object.zig | 0 src/vulkan/lib.zig | 0 6 files changed, 65 insertions(+), 12 deletions(-) delete mode 100644 src/lib.zig create mode 100644 src/soft/lib.zig create mode 100644 src/vulkan/Object.zig create mode 100644 src/vulkan/lib.zig diff --git a/build.zig b/build.zig index 3f84931..f6eb36e 100644 --- a/build.zig +++ b/build.zig @@ -1,29 +1,74 @@ const std = @import("std"); +const Step = std.Build.Step; -pub fn build(b: *std.Build) void { +const ImplementationDesc = struct { + name: []const u8, + root_source_file: []const u8, +}; + +const implementations = [_]ImplementationDesc{ + .{ + .name = "soft", + .root_source_file = "src/soft/lib.zig", + }, +}; + +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const lib_mod = b.createModule(.{ - .root_source_file = b.path("src/lib.zig"), + const libvulkan_mod = b.createModule(.{ + .root_source_file = b.path("src/vulkan/lib.zig"), .target = target, .optimize = optimize, }); - const lib = b.addLibrary(.{ + const vulkan = b.dependency("vulkan_zig", .{ + .registry = b.dependency("vulkan_headers", .{}).path("registry/vk.xml"), + }).module("vulkan-zig"); + + libvulkan_mod.addImport("vulkan", vulkan); + + const libvulkan = b.addLibrary(.{ .name = "vulkan", - .root_module = lib_mod, + .root_module = libvulkan_mod, .linkage = .dynamic, }); - b.installArtifact(lib); + b.installArtifact(libvulkan); - const lib_tests = b.addTest(.{ - .root_module = lib_mod, + for (implementations) |impl| { + b.installArtifact(try buildImplementation(b, target, optimize, &impl, vulkan)); + } + + const libvulkan_tests = b.addTest(.{ + .root_module = libvulkan_mod, }); - const run_lib_tests = b.addRunArtifact(lib_tests); + const run_libvulkan_tests = b.addRunArtifact(libvulkan_tests); const test_step = b.step("test", "Run tests"); - test_step.dependOn(&run_lib_tests.step); + test_step.dependOn(&run_libvulkan_tests.step); +} + +fn buildImplementation( + b: *std.Build, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, + desc: *const ImplementationDesc, + vulkan_bindings: *std.Build.Module, +) !*Step.Compile { + const lib_mod = b.createModule(.{ + .root_source_file = b.path(desc.root_source_file), + .target = target, + .optimize = optimize, + }); + + lib_mod.addImport("vulkan", vulkan_bindings); + + return b.addLibrary(.{ + .name = try std.fmt.allocPrint(b.allocator, "vulkan_{s}", .{desc.name}), + .root_module = lib_mod, + .linkage = .dynamic, + }); } diff --git a/build.zig.zon b/build.zig.zon index 10e3cbe..1a49e3e 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,7 +4,16 @@ .fingerprint = 0x52cb73649f1107de, .minimum_zig_version = "0.15.1", - .dependencies = .{}, + .dependencies = .{ + .vulkan_headers = .{ + .url = "git+https://github.com/KhronosGroup/Vulkan-Headers?ref=v1.4.330#ee3b5caaa7e372715873c7b9c390ee1c3ca5db25", + .hash = "N-V-__8AAFXYAQKsK51AAGXB9HziPDFjS_DVUq6_QHVxHrBM", + }, + .vulkan_zig = .{ + .url = "git+https://github.com/catmeow72/vulkan-zig/#8961518db28f88d2cf09ea68e146923de2cfa7f0", + .hash = "vulkan-0.0.0-r7Ytx6hBAwD8X_TN32qlkzul4riK6vFvjtK9fZfRvALg", + }, + }, .paths = .{ "build.zig", diff --git a/src/lib.zig b/src/lib.zig deleted file mode 100644 index 95a0b68..0000000 --- a/src/lib.zig +++ /dev/null @@ -1 +0,0 @@ -const std = @import("std"); diff --git a/src/soft/lib.zig b/src/soft/lib.zig new file mode 100644 index 0000000..e69de29 diff --git a/src/vulkan/Object.zig b/src/vulkan/Object.zig new file mode 100644 index 0000000..e69de29 diff --git a/src/vulkan/lib.zig b/src/vulkan/lib.zig new file mode 100644 index 0000000..e69de29