forked from mirror/vulkan-zig
Basic setup for examples
This commit is contained in:
40
build.zig
40
build.zig
@@ -1,21 +1,35 @@
|
||||
const std = @import("std");
|
||||
const vkgen = @import("generator/generator.zig");
|
||||
const Builder = std.build.Builder;
|
||||
const FmtStep = std.build.FmtStep;
|
||||
|
||||
pub fn generateVk(b: *Builder) []const u8 {
|
||||
const spec = std.fs.cwd().readFileAlloc(b.allocator, "examples/vk.xml", std.math.maxInt(usize)) catch unreachable;
|
||||
const output = std.fs.path.join(
|
||||
b.allocator,
|
||||
&[_][]const u8{b.cache_root, "vk.zig"},
|
||||
) catch unreachable;
|
||||
|
||||
const output_file = std.fs.cwd().createFile(output, .{}) catch unreachable;
|
||||
defer output_file.close();
|
||||
vkgen.generate(b.allocator, spec, output_file.writer()) catch unreachable;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const generator = b.addExecutable("vulkan-zig-gen", "generator/main.zig");
|
||||
generator.setBuildMode(b.standardReleaseOptions());
|
||||
|
||||
var test_step = b.step("test", "Run all the tests");
|
||||
test_step.dependOn(&b.addTest("generator/main.zig").step);
|
||||
test_step.dependOn(&b.addTest("generator/generator.zig").step);
|
||||
|
||||
const run_cmd = generator.run();
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const mode = b.standardReleaseOptions();
|
||||
const exe = b.addExecutable("example", "examples/main.zig");
|
||||
exe.setTarget(target);
|
||||
exe.setBuildMode(mode);
|
||||
exe.install();
|
||||
|
||||
const run_step = b.step("run", "");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
b.default_step.dependOn(&generator.step);
|
||||
b.installArtifact(generator);
|
||||
const vk_path = generateVk(b);
|
||||
const fmt_step = b.addFmt(&[_][]const u8{vk_path});
|
||||
exe.step.dependOn(&fmt_step.step);
|
||||
exe.addPackagePath("vk", vk_path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user