Add Khronos license information to generated bindings

This commit is contained in:
Robin Voetter
2020-07-08 01:41:03 +02:00
parent f2edf4f674
commit 0928b25a53
3 changed files with 13 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ pub fn parseXml(backing_allocator: *Allocator, root: *xml.Element) !ParseResult
const allocator = &arena.allocator; const allocator = &arena.allocator;
var reg = registry.Registry{ var reg = registry.Registry{
.copyright = root.getCharData("comment") orelse return error.InvalidRegistry,
.decls = try parseDeclarations(allocator, root), .decls = try parseDeclarations(allocator, root),
.api_constants = try parseApiConstants(allocator, root), .api_constants = try parseApiConstants(allocator, root),
.tags = try parseTags(allocator, root), .tags = try parseTags(allocator, root),

View File

@@ -1,4 +1,5 @@
pub const Registry = struct { pub const Registry = struct {
copyright: []const u8,
decls: []Declaration, decls: []Declaration,
api_constants: []ApiConstant, api_constants: []ApiConstant,
tags: []Tag, tags: []Tag,

View File

@@ -6,6 +6,9 @@ const mem = std.mem;
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
const preamble = const preamble =
\\
\\// This file is generated from the Khronos Vulkan XML API Registry
\\
\\const std = @import("std"); \\const std = @import("std");
\\const builtin = @import("builtin"); \\const builtin = @import("builtin");
\\const root = @import("root"); \\const root = @import("root");
@@ -294,6 +297,7 @@ fn Renderer(comptime WriterType: type) type {
} }
fn render(self: *Self) !void { fn render(self: *Self) !void {
try self.renderCopyright();
try self.writer.writeAll(preamble); try self.writer.writeAll(preamble);
for (self.registry.api_constants) |api_constant| { for (self.registry.api_constants) |api_constant| {
@@ -309,6 +313,13 @@ fn Renderer(comptime WriterType: type) type {
try self.renderWrappers(); try self.renderWrappers();
} }
fn renderCopyright(self: *Self) !void {
var it = mem.split(self.registry.copyright, "\n");
while (it.next()) |line| {
try self.writer.print("// {}\n", .{line});
}
}
fn renderApiConstant(self: *Self, api_constant: reg.ApiConstant) !void { fn renderApiConstant(self: *Self, api_constant: reg.ApiConstant) !void {
try self.writer.writeAll("pub const "); try self.writer.writeAll("pub const ");
try self.renderName(api_constant.name); try self.renderName(api_constant.name);