vulkan-zig/build.zig

94 lines
2.7 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-08-18 16:56:31 +02:00
// exe.addIncludePath(b.path("include/"));
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);
const shader_comp = vkgen.ShaderCompileStep.create(
b,
2024-09-01 17:36:22 +02:00
.{ .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", .{});
2024-09-01 19:20:41 +02:00
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());
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-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-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);
}