Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing up vulkan-zig for new build sys #113

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
zig-cache/
zig-out/
.vscode/
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn build(b: *std.Build) void {
generate_cmd.addArg(path);

_ = b.addModule("vulkan-zig", .{
.source_file = generate_cmd.addOutputFileArg("vk.zig"),
.root_source_file = generate_cmd.addOutputFileArg("vk.zig"),
});
}

Expand All @@ -40,15 +40,15 @@ pub fn build(b: *std.Build) void {
.name = "triangle",
.root_source_file = .{ .path = "examples/triangle.zig" },
.target = target,
.link_libc = true,
.optimize = optimize,
});
b.installArtifact(triangle_exe);
triangle_exe.linkLibC();
triangle_exe.linkSystemLibrary("glfw");

const example_registry = b.option([]const u8, "example-registry", "Override the path to the Vulkan registry used for the examples") orelse "examples/vk.xml";
const gen = VkGenerateStep.create(b, example_registry);
triangle_exe.addModule("vulkan", gen.getModule());
triangle_exe.root_module.addImport("vulkan", gen.getModule());

const vk_zig_install_step = b.addInstallFile(gen.getSource(), "src/vk.zig");
b.getInstallStep().dependOn(&vk_zig_install_step.step);
Expand All @@ -60,7 +60,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.addModule("shaders", shaders.getModule());
triangle_exe.root_module.addImport("shaders", shaders.getModule());

const triangle_run_cmd = b.addRunArtifact(triangle_exe);
triangle_run_cmd.step.dependOn(b.getInstallStep());
Expand All @@ -83,6 +83,6 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
ref_all_decls_test.addModule("vulkan", gen.getModule());
ref_all_decls_test.root_module.addImport("vulkan", gen.getModule());
test_step.dependOn(&ref_all_decls_test.step);
}
4 changes: 2 additions & 2 deletions generator/build_integration.zig
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ pub const ShaderCompileStep = struct {
/// Returns the shaders module with name.
pub fn getModule(self: *ShaderCompileStep) *Build.Module {
return self.step.owner.createModule(.{
.source_file = self.getSource(),
.root_source_file = self.getSource(),
});
}

/// Returns the file source for the generated shader resource code.
pub fn getSource(self: *ShaderCompileStep) Build.FileSource {
pub fn getSource(self: *ShaderCompileStep) Build.LazyPath {
return .{ .generated = &self.generated_file };
}

Expand Down
41 changes: 26 additions & 15 deletions generator/vulkan/build_integration.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ pub const GenerateStep = struct {
/// Returns the module with the generated budings, with name `module_name`.
pub fn getModule(self: *GenerateStep) *Build.Module {
return self.step.owner.createModule(.{
.source_file = self.getSource(),
.root_source_file = self.getSource(),
});
}

/// Returns the file source for the generated bindings.
pub fn getSource(self: *GenerateStep) Build.FileSource {
pub fn getSource(self: *GenerateStep) Build.LazyPath {
return .{ .generated = &self.generated_file };
}

Expand Down Expand Up @@ -124,21 +124,22 @@ pub const GenerateStep = struct {
var end: usize = undefined;
var index: usize = undefined;
var repeat: usize = undefined;
var spaces: [] const u8 = undefined;
var carets: [] const u8 = undefined;
var spaces: []const u8 = undefined;
var carets: []const u8 = undefined;
var current_token: std.zig.Token = undefined;

std.debug.print("{s}\n", .{ src, });
std.debug.print("{s}\n", .{
src,
});

var tokens = try std.ArrayList (std.zig.Ast.Error).initCapacity(b.allocator, tree.errors.len);
var tokens = try std.ArrayList(std.zig.Ast.Error).initCapacity(b.allocator, tree.errors.len);
try tokens.appendSlice(tree.errors);

std.mem.sort(std.zig.Ast.Error, tokens.items, {},
struct {
pub fn desc(_: void, l_err: std.zig.Ast.Error, r_err: std.zig.Ast.Error) bool {
return l_err.token > r_err.token;
}
}.desc);
std.mem.sort(std.zig.Ast.Error, tokens.items, {}, struct {
pub fn desc(_: void, l_err: std.zig.Ast.Error, r_err: std.zig.Ast.Error) bool {
return l_err.token > r_err.token;
}
}.desc);

var iterator = std.zig.Tokenizer.init(src);

Expand All @@ -153,18 +154,28 @@ pub const GenerateStep = struct {
repeat = 1;
spaces = "";
while (repeat < current_token.loc.start - start) {
spaces = try std.fmt.allocPrint(b.allocator, "{s} ", .{ spaces, });
spaces = try std.fmt.allocPrint(b.allocator, "{s} ", .{
spaces,
});
repeat += 1;
}

repeat = 1;
carets = "";
while (repeat < current_token.loc.end + 1 - current_token.loc.start) {
carets = try std.fmt.allocPrint(b.allocator, "{s}^", .{ carets, });
carets = try std.fmt.allocPrint(b.allocator, "{s}^", .{
carets,
});
repeat += 1;
}

std.debug.print("ERROR: {}\nTOKEN: {}\n\n{s}\n{s}{s}\n", .{ tokens.items[tokens.items.len - 1], current_token, if(src[start] == '\n') src[start + 1..end] else src[start..end], spaces, carets, });
std.debug.print("ERROR: {}\nTOKEN: {}\n\n{s}\n{s}{s}\n", .{
tokens.items[tokens.items.len - 1],
current_token,
if (src[start] == '\n') src[start + 1 .. end] else src[start..end],
spaces,
carets,
});

_ = tokens.pop();
}
Expand Down
Loading