vulkan-zig/build.zig

93 lines
2.7 KiB
Zig

const std = @import("std");
const sdl = @import("sdl");
const vkgen = @import("vulkan");
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,
.link_libc = true,
});
// exe.addIncludePath(b.path("include/"));
// --- Dependencies ---
// Vulkan
const vkzig_dep = b.dependency("vulkan", .{
.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,
.{ .real_path = "glslc" },
&[_][]const u8{"--target-env=vulkan1.3"},
"-o",
);
shader_comp.add("shader_frag", "src/shaders/shader.frag", .{});
shader_comp.add("shader_vert", "src/shaders/shader.vert", .{});
shader_comp.add("second_frag", "src/shaders/second.frag", .{});
shader_comp.add("second_vert", "src/shaders/second.vert", .{});
exe.root_module.addImport("shaders", shader_comp.getModule());
// SDL2
const sdl_sdk = sdl.init(b, .{});
sdl_sdk.link(exe, .dynamic, sdl.Library.SDL2);
exe.root_module.addImport("sdl", sdl_sdk.getWrapperModuleVulkan(vkzig_bindings));
// zmath
const zmath = b.dependency("zmath", .{});
exe.root_module.addImport("zmath", zmath.module("root"));
// zstbi
const zstbi = b.dependency("zstbi", .{});
exe.root_module.addImport("zstbi", zstbi.module("root"));
exe.linkLibrary(zstbi.artifact("zstbi"));
// Assimp
exe.linkSystemLibrary("assimp");
// ---
b.installArtifact(exe);
const exe_check = b.addExecutable(.{
.name = "vulkan-test",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const check = b.step("check", "Check if vulkan-test compiles");
check.dependOn(&exe_check.step);
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);
}