forked from mirror/vulkan-zig
update build to use new build API
This commit is contained in:
@@ -37,10 +37,10 @@ pub fn build(b: *Builder) void {
|
|||||||
const gen = vkgen.VkGenerateStep.create(b, "path/to/vk.xml", "vk.zig");
|
const gen = vkgen.VkGenerateStep.create(b, "path/to/vk.xml", "vk.zig");
|
||||||
|
|
||||||
// Add the generated file as package to the final executable
|
// Add the generated file as package to the final executable
|
||||||
exe.addPackage(gen.getPackage("vulkan"));
|
exe.addModule("vulkan", gen.getModule());
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
This reads vk.xml, parses its contents, and renders the Vulkan bindings to "vk.zig", which is then formatted and placed in `zig-cache`. The resulting file can then be added to an executable by using `addPackage`, after which the bindings will be made available to the executable under the name passed to `getPackage`.
|
This reads vk.xml, parses its contents, and renders the Vulkan bindings to "vk.zig", which is then formatted and placed in `zig-cache`. The resulting file can then be added to an executable by using `addModule`, after which the bindings will be made available to the executable under the name passed to `getModule`.
|
||||||
|
|
||||||
### Function & field renaming
|
### Function & field renaming
|
||||||
Functions and fields are renamed to be more or less in line with [Zig's standard library style](https://ziglang.org/documentation/master/#Style-Guide):
|
Functions and fields are renamed to be more or less in line with [Zig's standard library style](https://ziglang.org/documentation/master/#Style-Guide):
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
const vk_xml_path = b.option([]const u8, "vulkan-registry", "Override the path to the Vulkan registry") orelse "examples/vk.xml";
|
const vk_xml_path = b.option([]const u8, "vulkan-registry", "Override the path to the Vulkan registry") orelse "examples/vk.xml";
|
||||||
|
|
||||||
const gen = vkgen.VkGenerateStep.create(b, vk_xml_path, "vk.zig");
|
const gen = vkgen.VkGenerateStep.create(b, vk_xml_path, "vk.zig");
|
||||||
triangle_exe.addPackage(gen.getPackage("vulkan"));
|
triangle_exe.addModule("vulkan", gen.getModule());
|
||||||
|
|
||||||
const shaders = vkgen.ShaderCompileStep.create(
|
const shaders = vkgen.ShaderCompileStep.create(
|
||||||
b,
|
b,
|
||||||
@@ -36,7 +36,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
);
|
);
|
||||||
shaders.add("triangle_vert", "examples/shaders/triangle.vert", .{});
|
shaders.add("triangle_vert", "examples/shaders/triangle.vert", .{});
|
||||||
shaders.add("triangle_frag", "examples/shaders/triangle.frag", .{});
|
shaders.add("triangle_frag", "examples/shaders/triangle.frag", .{});
|
||||||
triangle_exe.addPackage(shaders.getPackage("shaders"));
|
triangle_exe.addModule("shaders", shaders.getModule());
|
||||||
|
|
||||||
const triangle_run_cmd = triangle_exe.run();
|
const triangle_run_cmd = triangle_exe.run();
|
||||||
triangle_run_cmd.step.dependOn(b.getInstallStep());
|
triangle_run_cmd.step.dependOn(b.getInstallStep());
|
||||||
@@ -58,6 +58,6 @@ pub fn build(b: *std.Build) void {
|
|||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
ref_all_decls_test.addPackage(gen.getPackage("vulkan"));
|
ref_all_decls_test.addModule("vulkan", gen.getModule());
|
||||||
test_step.dependOn(&ref_all_decls_test.step);
|
test_step.dependOn(&ref_all_decls_test.step);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,9 +96,11 @@ pub const ShaderCompileStep = struct {
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the shaders package with name `package_name`.
|
/// Returns the shaders module with name.
|
||||||
pub fn getPackage(self: *ShaderCompileStep, package_name: []const u8) std.build.Pkg {
|
pub fn getModule(self: *ShaderCompileStep) *std.build.Module {
|
||||||
return .{ .name = package_name, .source = self.getSource() };
|
return self.b.createModule(.{
|
||||||
|
.source_file = self.getSource(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the file source for the generated shader resource code.
|
/// Returns the file source for the generated shader resource code.
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const generate = @import("generator.zig").generate;
|
const generate = @import("generator.zig").generate;
|
||||||
const path = std.fs.path;
|
const path = std.fs.path;
|
||||||
const Builder = std.build.Builder;
|
const Build = std.Build;
|
||||||
const Step = std.build.Step;
|
const Step = Build.Step;
|
||||||
|
|
||||||
/// build.zig integration for Vulkan binding generation. This step can be used to generate
|
/// build.zig integration for Vulkan binding generation. This step can be used to generate
|
||||||
/// Vulkan bindings at compiletime from vk.xml, by providing the path to vk.xml and the output
|
/// Vulkan bindings at compiletime from vk.xml, by providing the path to vk.xml and the output
|
||||||
/// path relative to zig-cache. The final package can then be obtained by `package()`, the result
|
/// path relative to zig-cache. The final package can then be obtained by `package()`, the result
|
||||||
/// of which can be added to the project using `std.build.Builder.addPackage`.
|
/// of which can be added to the project using `std.Build.addModule`.
|
||||||
pub const GenerateStep = struct {
|
pub const GenerateStep = struct {
|
||||||
step: Step,
|
step: Step,
|
||||||
builder: *Builder,
|
builder: *Build,
|
||||||
|
|
||||||
/// The path to vk.xml
|
/// The path to vk.xml
|
||||||
spec_path: []const u8,
|
spec_path: []const u8,
|
||||||
@@ -20,7 +20,7 @@ pub const GenerateStep = struct {
|
|||||||
/// Initialize a Vulkan generation step, for `builder`. `spec_path` is the path to
|
/// Initialize a Vulkan generation step, for `builder`. `spec_path` is the path to
|
||||||
/// vk.xml, relative to the project root. The generated bindings will be placed at
|
/// vk.xml, relative to the project root. The generated bindings will be placed at
|
||||||
/// `out_path`, which is relative to the zig-cache directory.
|
/// `out_path`, which is relative to the zig-cache directory.
|
||||||
pub fn create(builder: *Builder, spec_path: []const u8, out_path: []const u8) *GenerateStep {
|
pub fn create(builder: *Build, spec_path: []const u8, out_path: []const u8) *GenerateStep {
|
||||||
const self = builder.allocator.create(GenerateStep) catch unreachable;
|
const self = builder.allocator.create(GenerateStep) catch unreachable;
|
||||||
const full_out_path = path.join(builder.allocator, &[_][]const u8{
|
const full_out_path = path.join(builder.allocator, &[_][]const u8{
|
||||||
builder.build_root,
|
builder.build_root,
|
||||||
@@ -44,7 +44,7 @@ pub const GenerateStep = struct {
|
|||||||
/// root. Typically, the location of the LunarG SDK root can be retrieved by querying for the VULKAN_SDK
|
/// root. Typically, the location of the LunarG SDK root can be retrieved by querying for the VULKAN_SDK
|
||||||
/// environment variable, set by activating the environment setup script located in the SDK root.
|
/// environment variable, set by activating the environment setup script located in the SDK root.
|
||||||
/// `builder` and `out_path` are used in the same manner as `init`.
|
/// `builder` and `out_path` are used in the same manner as `init`.
|
||||||
pub fn createFromSdk(builder: *Builder, sdk_path: []const u8, out_path: []const u8) *GenerateStep {
|
pub fn createFromSdk(builder: *Build, sdk_path: []const u8, out_path: []const u8) *GenerateStep {
|
||||||
const spec_path = std.fs.path.join(
|
const spec_path = std.fs.path.join(
|
||||||
builder.allocator,
|
builder.allocator,
|
||||||
&[_][]const u8{ sdk_path, "share/vulkan/registry/vk.xml" },
|
&[_][]const u8{ sdk_path, "share/vulkan/registry/vk.xml" },
|
||||||
@@ -53,9 +53,11 @@ pub const GenerateStep = struct {
|
|||||||
return create(builder, spec_path, out_path);
|
return create(builder, spec_path, out_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the package with the generated budings, with name `package_name`.
|
/// Returns the module with the generated budings, with name `module_name`.
|
||||||
pub fn getPackage(self: *GenerateStep, package_name: []const u8) std.build.Pkg {
|
pub fn getModule(self: *GenerateStep) *std.build.Module {
|
||||||
return .{ .name = package_name, .source = self.getSource() };
|
return self.builder.createModule(.{
|
||||||
|
.source_file = self.getSource(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the file source for the generated bindings.
|
/// Returns the file source for the generated bindings.
|
||||||
|
|||||||
Reference in New Issue
Block a user