vulkan-zig/build.zig

73 lines
2.1 KiB
Zig
Raw Normal View History

2024-06-22 22:10:45 +02:00
const std = @import("std");
2024-07-25 23:38:44 +02:00
const sdl = @import("libs/sdl/build.zig");
const vkgen = @import("vulkan_zig");
2024-06-22 22:10:45 +02:00
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "vulkan-test",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
2024-07-22 00:27:24 +02:00
// --- Dependencies ---
2024-07-14 19:53:53 +02:00
// Vulkan
2024-06-22 22:10:45 +02:00
const vkzig_dep = b.dependency("vulkan_zig", .{
.registry = @as([]const u8, b.pathFromRoot("./vk.xml")),
});
const vkzig_bindings = vkzig_dep.module("vulkan-zig");
exe.root_module.addImport("vulkan", vkzig_bindings);
const shader_comp = vkgen.ShaderCompileStep.create(
b,
&[_][]const u8{ "glslc", "--target-env=vulkan1.3" },
"-o",
);
shader_comp.add("shader_frag", "src/shaders/shader.frag", .{});
shader_comp.add("shader_vert", "src/shaders/shader.vert", .{});
exe.root_module.addImport("shaders", shader_comp.getModule());
2024-07-14 19:53:53 +02:00
// SDL2
2024-07-14 22:13:14 +02:00
const sdl_sdk = sdl.init(b, null, null);
2024-07-25 23:38:44 +02:00
sdl_sdk.link(exe, .dynamic, sdl.Library.SDL2);
2024-06-22 22:10:45 +02:00
exe.root_module.addImport("sdl2", sdl_sdk.getWrapperModuleVulkan(vkzig_bindings));
2024-07-14 19:53:53 +02:00
2024-07-22 00:27:24 +02:00
// zmath
const zmath = b.dependency("zmath", .{});
exe.root_module.addImport("zmath", zmath.module("root"));
// ---
2024-06-22 22:10:45 +02:00
b.installArtifact(exe);
2024-07-14 19:53:53 +02:00
const check = b.step("check", "Check if vulkan-test compiles");
check.dependOn(&exe.step);
2024-06-22 22:10:45 +02:00
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_exe_unit_tests.step);
}