forked from mirror/vulkan-zig
This changes the name of the generator binary from something very generic to something a little more descriptive. If using the package manager method to use the generator, this will require updating to the new name.
91 lines
3.6 KiB
Zig
91 lines
3.6 KiB
Zig
const std = @import("std");
|
|
const vkgen = @import("src/index.zig");
|
|
|
|
pub const ShaderCompileStep = vkgen.ShaderCompileStep;
|
|
pub const VkGenerateStep = vkgen.VkGenerateStep;
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
const vk_xml_path: ?[]const u8 = b.option([]const u8, "registry", "Override the path to the Vulkan registry");
|
|
|
|
// using the package manager, this artifact can be obtained by the user
|
|
// through `b.dependency(<name in build.zig.zon>, .{}).artifact("vulkan-zig-generator")`.
|
|
// with that, the user need only `.addArg("path/to/vk.xml")`, and then obtain
|
|
// a file source to the generated code with `.addOutputArg("vk.zig")`
|
|
const generator_exe = b.addExecutable(.{
|
|
.name = "vulkan-zig-generator",
|
|
.root_source_file = .{ .path = "src/main.zig" },
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
b.installArtifact(generator_exe);
|
|
|
|
// or they can skip all that, and just make sure to pass `.registry = "path/to/vk.xml"` to `b.dependency`,
|
|
// and then obtain the module directly via `.module("vulkan-zig")`.
|
|
if (vk_xml_path) |path| {
|
|
const generate_cmd = b.addRunArtifact(generator_exe);
|
|
|
|
if (!std.fs.path.isAbsolute(path)) @panic("Make sure to assign an absolute path to the `registry` option (see: std.Build.pathFromRoot).\n");
|
|
generate_cmd.addArg(path);
|
|
|
|
_ = b.addModule("vulkan-zig", .{
|
|
.root_source_file = generate_cmd.addOutputFileArg("vk.zig"),
|
|
});
|
|
}
|
|
|
|
// remainder of the script is for local testing
|
|
|
|
const triangle_exe = b.addExecutable(.{
|
|
.name = "triangle",
|
|
.root_source_file = .{ .path = "examples/triangle.zig" },
|
|
.target = target,
|
|
.link_libc = true,
|
|
.optimize = optimize,
|
|
});
|
|
b.installArtifact(triangle_exe);
|
|
triangle_exe.linkSystemLibrary("glfw");
|
|
|
|
const example_registry = b.option([]const u8, "example-registry", "Override the path to the Vulkan registry used for the examples") orelse "examples/vk.xml";
|
|
const gen = VkGenerateStep.create(b, example_registry);
|
|
triangle_exe.root_module.addImport("vulkan", gen.getModule());
|
|
|
|
const vk_zig_install_step = b.addInstallFile(gen.getSource(), "src/vk.zig");
|
|
b.getInstallStep().dependOn(&vk_zig_install_step.step);
|
|
|
|
const shaders = ShaderCompileStep.create(
|
|
b,
|
|
&[_][]const u8{ "glslc", "--target-env=vulkan1.2" },
|
|
"-o",
|
|
);
|
|
shaders.add("triangle_vert", "examples/shaders/triangle.vert", .{});
|
|
shaders.add("triangle_frag", "examples/shaders/triangle.frag", .{});
|
|
triangle_exe.root_module.addImport("shaders", shaders.getModule());
|
|
|
|
const triangle_run_cmd = b.addRunArtifact(triangle_exe);
|
|
triangle_run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
const triangle_run_step = b.step("run-triangle", "Run the triangle example");
|
|
triangle_run_step.dependOn(&triangle_run_cmd.step);
|
|
|
|
const test_target = b.addTest(.{
|
|
.root_source_file = .{ .path = "src/index.zig" },
|
|
});
|
|
|
|
const run_test = b.addRunArtifact(test_target);
|
|
|
|
const test_step = b.step("test", "Run all the tests");
|
|
test_step.dependOn(&run_test.step);
|
|
|
|
// This test needs to be an object so that vulkan-zig can import types from the root.
|
|
// It does not need to run anyway.
|
|
const ref_all_decls_test = b.addObject(.{
|
|
.name = "ref-all-decls-test",
|
|
.root_source_file = .{ .path = "test/ref_all_decls.zig" },
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
ref_all_decls_test.root_module.addImport("vulkan", gen.getModule());
|
|
test_step.dependOn(&ref_all_decls_test.step);
|
|
}
|