Attempt to fix vulkan-zig on windows: Make dispatchers accept anytype as loader, properly escape paths in build.zig

This commit is contained in:
Robin Voetter
2020-09-24 13:41:58 +02:00
parent e0000e4818
commit 7888df1bd3
2 changed files with 27 additions and 10 deletions

View File

@@ -2,7 +2,6 @@ const std = @import("std");
const vkgen = @import("generator/index.zig");
const Step = std.build.Step;
const Builder = std.build.Builder;
const path = std.fs.path;
pub const ResourceGenStep = struct {
step: Step,
@@ -13,7 +12,7 @@ pub const ResourceGenStep = struct {
pub fn init(builder: *Builder, out: []const u8) *ResourceGenStep {
const self = builder.allocator.create(ResourceGenStep) catch unreachable;
const full_out_path = path.join(builder.allocator, &[_][]const u8{
const full_out_path = std.fs.path.join(builder.allocator, &[_][]const u8{
builder.build_root,
builder.cache_root,
out,
@@ -35,18 +34,36 @@ pub const ResourceGenStep = struct {
return self;
}
fn renderPath(self: *ResourceGenStep, path: []const u8, writer: anytype) void {
const separators = &[_]u8{ std.fs.path.sep_windows, std.fs.path.sep_posix };
var i: usize = 0;
while (std.mem.indexOfAnyPos(u8, path, i, separators)) |j| {
writer.writeAll(path[i .. j]) catch unreachable;
switch (std.fs.path.sep) {
std.fs.path.sep_windows => writer.writeAll("\\\\") catch unreachable,
std.fs.path.sep_posix => writer.writeByte(std.fs.path.sep_posix) catch unreachable,
else => unreachable
}
i = j + 1;
}
writer.writeAll(path[i..]) catch unreachable;
}
pub fn addShader(self: *ResourceGenStep, name: []const u8, source: []const u8) void {
self.resources.writer().print(
"pub const {} = @embedFile(\"{}\");\n",
.{name, self.shader_step.add(source)}
) catch unreachable;
const shader_out_path = self.shader_step.add(source);
var writer = self.resources.writer();
writer.print("pub const {} = @embedFile(\"", .{ name }) catch unreachable;
self.renderPath(shader_out_path, writer);
writer.writeAll("\");\n") catch unreachable;
}
fn make(step: *Step) !void {
const self = @fieldParentPtr(ResourceGenStep, "step", step);
const cwd = std.fs.cwd();
const dir = path.dirname(self.package.path).?;
const dir = std.fs.path.dirname(self.package.path).?;
try cwd.makePath(dir);
try cwd.writeFile(self.package.path, self.resources.items);
}

View File

@@ -810,9 +810,9 @@ fn Renderer(comptime WriterType: type) type {
fn renderWrapperLoader(self: *Self, dispatch_type: CommandDispatchType) !void {
const params = switch (dispatch_type) {
.base => "loader: PfnGetInstanceProcAddr",
.instance => "instance: Instance, loader: PfnGetInstanceProcAddr",
.device => "device: Device, loader: PfnGetDeviceProcAddr",
.base => "loader: anytype",
.instance => "instance: Instance, loader: anytype",
.device => "device: Device, loader: anytype",
};
const loader_first_param = switch (dispatch_type) {