improving zig build

This commit is contained in:
2025-10-28 15:25:52 +01:00
parent b5d27126af
commit 8faba19927
6 changed files with 65 additions and 12 deletions

View File

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

View File

@@ -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",

View File

@@ -1 +0,0 @@
const std = @import("std");

0
src/soft/lib.zig git.filemode.normal_file
View File

0
src/vulkan/Object.zig git.filemode.normal_file
View File

0
src/vulkan/lib.zig git.filemode.normal_file
View File