vulkan-zig/build.zig

99 lines
2.8 KiB
Zig
Raw Normal View History

2024-06-22 22:10:45 +02:00
const std = @import("std");
2024-09-01 19:20:41 +02:00
const sdl = @import("sdl");
const vkgen = @import("vulkan");
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-08-18 16:56:31 +02:00
.link_libc = true,
2024-06-22 22:10:45 +02:00
});
2024-07-22 00:27:24 +02:00
// --- Dependencies ---
2024-07-14 19:53:53 +02:00
// Vulkan
2024-09-01 19:20:41 +02:00
const vkzig_dep = b.dependency("vulkan", .{
2024-06-22 22:10:45 +02:00
.registry = @as([]const u8, b.pathFromRoot("./vk.xml")),
});
const vkzig_bindings = vkzig_dep.module("vulkan-zig");
exe.root_module.addImport("vulkan", vkzig_bindings);
2024-10-06 18:41:22 +02:00
// Shaders
compileShader(b, exe, "shader_frag", "shader.frag");
compileShader(b, exe, "shader_vert", "shader.vert");
compileShader(b, exe, "second_frag", "second.frag");
compileShader(b, exe, "second_vert", "second.vert");
2024-07-14 19:53:53 +02:00
// SDL2
2024-09-01 19:20:41 +02:00
const sdl_sdk = sdl.init(b, .{});
2024-07-25 23:38:44 +02:00
sdl_sdk.link(exe, .dynamic, sdl.Library.SDL2);
2024-09-01 23:09:24 +02:00
exe.root_module.addImport("sdl", 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-08-06 15:54:44 +02:00
// zstbi
const zstbi = b.dependency("zstbi", .{});
exe.root_module.addImport("zstbi", zstbi.module("root"));
exe.linkLibrary(zstbi.artifact("zstbi"));
2024-08-05 17:54:40 +02:00
2024-08-18 16:56:31 +02:00
// Assimp
exe.linkSystemLibrary("assimp");
2024-07-22 00:27:24 +02:00
// ---
2024-06-22 22:10:45 +02:00
b.installArtifact(exe);
2024-08-05 17:54:40 +02:00
const exe_check = b.addExecutable(.{
.name = "vulkan-test",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
2024-07-14 19:53:53 +02:00
const check = b.step("check", "Check if vulkan-test compiles");
2024-08-05 17:54:40 +02:00
check.dependOn(&exe_check.step);
2024-07-14 19:53:53 +02:00
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);
}
2024-10-06 18:41:22 +02:00
fn compileShader(
b: *std.Build,
exe: *std.Build.Step.Compile,
comptime name: []const u8,
comptime file_name: []const u8,
) void {
const cmd = b.addSystemCommand(&.{ "glslc", "--target-env=vulkan1.3", "-o" });
const spv = cmd.addOutputFileArg(name ++ ".spv");
cmd.addFileArg(b.path("src/shaders/" ++ file_name));
exe.root_module.addAnonymousImport(name, .{ .root_source_file = spv });
}