Skip to content

Commit

Permalink
[progress #146] custom bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
tiawl committed Mar 12, 2024
1 parent 1ca84a2 commit 345bd81
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 238 deletions.
26 changes: 11 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ fn requirements () !void

fn turbo (builder: *std.Build, profile: *Profile) !void
{
profile.optimize = std.builtin.Mode.ReleaseFast;
profile.optimize = .ReleaseFast;
profile.variables.addOption ([] const u8, "log_dir", "");
profile.variables.addOption (u8, "log_level", 0);
profile.variables.addOption ([] const [] const [] const u8, "vk_optional_extensions", &.{});
profile.command = &.{ "glslc", "-O", try std.fmt.allocPrint (builder.allocator, "--target-env=vulkan1.{s}", .{ profile.options.vkminor, }), };
}

Expand All @@ -55,7 +56,7 @@ fn verbose (builder: *std.Build, profile: *Profile) !void
if (err != std.fs.File.OpenError.PathAlreadyExists) return err;
};

profile.optimize = std.builtin.Mode.Debug;
profile.optimize = .Debug;
profile.variables.addOption ([] const u8, "log_dir", try builder.build_root.join (builder.allocator, &.{ log_dir, }));
profile.variables.addOption (u8, "log_level", 2);
profile.variables.addOption ([] const [] const [] const u8, "vk_optional_extensions", &.{
Expand Down Expand Up @@ -304,7 +305,8 @@ fn generate_prototypes (builder: *std.Build) ![] const u8

var iterator = std.zig.Tokenizer.init (binding.buffer.items [0 .. binding.buffer.items.len - 1 :0]);
var token = iterator.next ();
var precedent: [8] ?std.zig.Token = .{ null, } ** 8;
const size: usize = 6;
var precedent: [size] ?std.zig.Token = .{ null, } ** size;

var prototypes: struct { buffer: std.ArrayList (u8), source: [:0] const u8,
path: [] const u8, structless: std.ArrayList ([] const u8),
Expand All @@ -316,24 +318,20 @@ fn generate_prototypes (builder: *std.Build) ![] const u8

while (token.tag != .eof)
{
//std.debug.print ("{any}: \"{s}\"\n", .{ token, buffer.items [token.loc.start .. token.loc.end], });
if (precedent [0] != null and precedent [1] != null and precedent [2] != null and
precedent [3] != null and precedent [4] != null and precedent [5] != null and
precedent [6] != null and precedent [7] != null)
precedent [3] != null and precedent [4] != null and precedent [5] != null)
{
if (std.mem.startsWith (u8, binding.buffer.items [token.loc.start .. token.loc.end], "vk") and
precedent [0].?.tag == .period and
std.mem.eql (u8, binding.buffer.items [precedent [1].?.loc.start .. precedent [1].?.loc.end], "dispatch") and
precedent [2].?.tag == .period and precedent [4].?.tag == .period and
std.mem.eql (u8, binding.buffer.items [precedent [5].?.loc.start .. precedent [5].?.loc.end], "raw") and
precedent [6].?.tag == .period and
std.mem.eql (u8, binding.buffer.items [precedent [7].?.loc.start .. precedent [7].?.loc.end], "vk"))
precedent [0].?.tag == .period and precedent [2].?.tag == .period and
std.mem.eql (u8, binding.buffer.items [precedent [3].?.loc.start .. precedent [3].?.loc.end], "raw") and
precedent [4].?.tag == .period and
std.mem.eql (u8, binding.buffer.items [precedent [5].?.loc.start .. precedent [5].?.loc.end], "vk"))
{
inline for (@typeInfo (@TypeOf (prototypes)).Struct.fields) |field|
{
if (field.type == std.ArrayList ([] const u8))
{
if (std.mem.eql (u8, binding.buffer.items [precedent [3].?.loc.start .. precedent [3].?.loc.end], field.name))
if (std.mem.eql (u8, binding.buffer.items [precedent [1].?.loc.start .. precedent [1].?.loc.end], field.name))
{
try @field (prototypes, field.name).append (binding.buffer.items [token.loc.start .. token.loc.end]);
break;
Expand All @@ -343,8 +341,6 @@ fn generate_prototypes (builder: *std.Build) ![] const u8
}
}

precedent [7] = precedent [6];
precedent [6] = precedent [5];
precedent [5] = precedent [4];
precedent [4] = precedent [3];
precedent [3] = precedent [2];
Expand Down
Loading

0 comments on commit 345bd81

Please sign in to comment.