From b09e14a649f67a162a384b3bcef4de39989c8043 Mon Sep 17 00:00:00 2001 From: avokadoen Date: Tue, 7 Feb 2023 21:51:46 +0100 Subject: [PATCH] update build to use new build API --- README.md | 4 ++-- build.zig | 6 +++--- generator/build_integration.zig | 8 +++++--- generator/vulkan/build_integration.zig | 20 +++++++++++--------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ae532bb..e6fda32 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ pub fn build(b: *Builder) void { const gen = vkgen.VkGenerateStep.create(b, "path/to/vk.xml", "vk.zig"); // 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 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): diff --git a/build.zig b/build.zig index e9fb258..99b565f 100644 --- a/build.zig +++ b/build.zig @@ -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 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( b, @@ -36,7 +36,7 @@ pub fn build(b: *std.Build) void { ); shaders.add("triangle_vert", "examples/shaders/triangle.vert", .{}); 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(); triangle_run_cmd.step.dependOn(b.getInstallStep()); @@ -58,6 +58,6 @@ pub fn build(b: *std.Build) void { .target = target, .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); } diff --git a/generator/build_integration.zig b/generator/build_integration.zig index 6d34e6d..3252a31 100644 --- a/generator/build_integration.zig +++ b/generator/build_integration.zig @@ -96,9 +96,11 @@ pub const ShaderCompileStep = struct { return self; } - /// Returns the shaders package with name `package_name`. - pub fn getPackage(self: *ShaderCompileStep, package_name: []const u8) std.build.Pkg { - return .{ .name = package_name, .source = self.getSource() }; + /// Returns the shaders module with name. + pub fn getModule(self: *ShaderCompileStep) *std.build.Module { + return self.b.createModule(.{ + .source_file = self.getSource(), + }); } /// Returns the file source for the generated shader resource code. diff --git a/generator/vulkan/build_integration.zig b/generator/vulkan/build_integration.zig index 7af8aca..6beab76 100644 --- a/generator/vulkan/build_integration.zig +++ b/generator/vulkan/build_integration.zig @@ -1,16 +1,16 @@ const std = @import("std"); const generate = @import("generator.zig").generate; const path = std.fs.path; -const Builder = std.build.Builder; -const Step = std.build.Step; +const Build = std.Build; +const Step = Build.Step; /// 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 /// 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 { step: Step, - builder: *Builder, + builder: *Build, /// The path to vk.xml 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 /// vk.xml, relative to the project root. The generated bindings will be placed at /// `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 full_out_path = path.join(builder.allocator, &[_][]const u8{ 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 /// 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`. - 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( builder.allocator, &[_][]const u8{ sdk_path, "share/vulkan/registry/vk.xml" }, @@ -53,9 +53,11 @@ pub const GenerateStep = struct { return create(builder, spec_path, out_path); } - /// Returns the package with the generated budings, with name `package_name`. - pub fn getPackage(self: *GenerateStep, package_name: []const u8) std.build.Pkg { - return .{ .name = package_name, .source = self.getSource() }; + /// Returns the module with the generated budings, with name `module_name`. + pub fn getModule(self: *GenerateStep) *std.build.Module { + return self.builder.createModule(.{ + .source_file = self.getSource(), + }); } /// Returns the file source for the generated bindings.