Skip SDL_vulkan.h in bindings generation

This commit is contained in:
Peterino2 2026-01-22 19:08:12 -08:00
parent 2339ac2268
commit 00ced6e2d9
6 changed files with 60 additions and 19 deletions

2
lib/sdl3/build.zig vendored
View File

@ -197,7 +197,7 @@ pub fn build(b: *std.Build) void {
// .{ .header = "SDL/include/SDL3/SDL_tray.h", .output = "v2/tray.zig" }, // Skipped: not core API
.{ .header = "SDL/include/SDL3/SDL_version.h", .output = "v2/version.zig" },
.{ .header = "SDL/include/SDL3/SDL_video.h", .output = "v2/video.zig" },
.{ .header = "SDL/include/SDL3/SDL_vulkan.h", .output = "v2/vulkan.zig" },
// .{ .header = "SDL/include/SDL3/SDL_vulkan.h", .output = "v2/vulkan.zig" }, // Skipped: Vulkan interop
};
const regenerate_step = b.step("regenerate-zig", "Regenerate bindings from SDL headers");

View File

@ -1141,15 +1141,35 @@ pub const Scanner = struct {
}
}
// Simple heuristic: last space or * separates type from name
// Find the parameter name - it's the last identifier that's not a keyword
// Start from the end and find the last word that's not 'const' or 'restrict'
var name_start: usize = 0;
var i = working_param.len;
while (i > 0) {
var found_name = false;
// First, find the last identifier
while (i > 0 and !found_name) {
i -= 1;
const c = working_param[i];
if (c == ' ' or c == '*' or c == '\t') {
name_start = i + 1;
break;
const potential_name = std.mem.trim(u8, working_param[i + 1 ..], " \t");
// Check if this is a C keyword (const, restrict, etc.)
if (!std.mem.eql(u8, potential_name, "const") and
!std.mem.eql(u8, potential_name, "restrict") and
potential_name.len > 0)
{
name_start = i + 1;
found_name = true;
break;
}
}
}
if (!found_name and working_param.len > 0) {
// If we never found a separator, the whole thing might be the name
// Check if it's not a type keyword
if (!std.mem.eql(u8, working_param, "void")) {
name_start = 0; // Will be handled as type-only below
}
}

View File

@ -86,6 +86,7 @@ pub fn convertType(c_type: []const u8, allocator: Allocator) ![]const u8 {
if (std.mem.eql(u8, trimmed, "Uint16 *")) return try allocator.dupe(u8, "*u16");
if (std.mem.eql(u8, trimmed, "Uint32 *")) return try allocator.dupe(u8, "*u32");
if (std.mem.eql(u8, trimmed, "Uint64 *")) return try allocator.dupe(u8, "*u64");
if (std.mem.eql(u8, trimmed, "Sint8 *")) return try allocator.dupe(u8, "*i8");
if (std.mem.eql(u8, trimmed, "Sint16 *")) return try allocator.dupe(u8, "*i16");
if (std.mem.eql(u8, trimmed, "Sint32 *")) return try allocator.dupe(u8, "*i32");
if (std.mem.eql(u8, trimmed, "const bool *")) return try allocator.dupe(u8, "*const bool");
@ -123,6 +124,25 @@ pub fn convertType(c_type: []const u8, allocator: Allocator) ![]const u8 {
return try allocator.dupe(u8, trimmed[4..]);
}
// Generic pointer handling for any remaining pointer types
// Handle "const struct Foo *" -> "*const Foo"
if (std.mem.startsWith(u8, trimmed, "const struct ")) {
if (std.mem.endsWith(u8, trimmed, " *")) {
const struct_name = trimmed[13 .. trimmed.len - 2]; // Remove "const struct " and " *"
return std.fmt.allocPrint(allocator, "*const {s}", .{struct_name});
}
}
// Handle "Foo *" for any remaining types (fallback to C pointer)
if (std.mem.endsWith(u8, trimmed, " *")) {
const base_type = trimmed[0 .. trimmed.len - 2];
return std.fmt.allocPrint(allocator, "[*c]{s}", .{base_type});
}
if (std.mem.endsWith(u8, trimmed, "*")) {
const base_type = trimmed[0 .. trimmed.len - 1];
return std.fmt.allocPrint(allocator, "[*c]{s}", .{base_type});
}
// Fallback: return as-is
return try allocator.dupe(u8, trimmed);
}

View File

@ -47,7 +47,10 @@ pub const IOStream = opaque {
}
pub inline fn iOprintf(iostream: *IOStream, fmt: [*c]const u8, ...) usize {
return c.SDL_IOprintf(iostream, fmt, );
return c.SDL_IOprintf(
iostream,
fmt,
);
}
pub inline fn iOvprintf(iostream: *IOStream, fmt: [*c]const u8, ap: std.builtin.VaList) usize {
@ -70,8 +73,8 @@ pub const IOStream = opaque {
return c.SDL_ReadU8(iostream, value);
}
pub inline fn readS8(iostream: *IOStream, value: Sint8 *) bool {
return c.SDL_ReadS8(iostream, value);
pub inline fn readS8(iostream: *IOStream, value: *i8) bool {
return c.SDL_ReadS8(iostream, @ptrCast(value));
}
pub inline fn readU16LE(iostream: *IOStream, value: *u16) bool {
@ -110,7 +113,7 @@ pub const IOStream = opaque {
return c.SDL_ReadU64LE(iostream, @ptrCast(value));
}
pub inline fn readS64LE(iostream: *IOStream, value: Sint64 *) bool {
pub inline fn readS64LE(iostream: *IOStream, value: [*c]Sint64) bool {
return c.SDL_ReadS64LE(iostream, value);
}
@ -118,7 +121,7 @@ pub const IOStream = opaque {
return c.SDL_ReadU64BE(iostream, @ptrCast(value));
}
pub inline fn readS64BE(iostream: *IOStream, value: Sint64 *) bool {
pub inline fn readS64BE(iostream: *IOStream, value: [*c]Sint64) bool {
return c.SDL_ReadS64BE(iostream, value);
}
@ -177,7 +180,6 @@ pub const IOStream = opaque {
pub inline fn writeS64BE(iostream: *IOStream, value: i64) bool {
return c.SDL_WriteS64BE(iostream, value);
}
};
pub inline fn ioFromFile(file: [*c]const u8, mode: [*c]const u8) ?*IOStream {
@ -207,4 +209,3 @@ pub inline fn loadFile(file: [*c]const u8, datasize: *usize) ?*anyopaque {
pub inline fn saveFile(file: [*c]const u8, data: ?*const anyopaque, datasize: usize) bool {
return c.SDL_SaveFile(file, data, datasize);
}

View File

@ -37,11 +37,11 @@ pub inline fn onApplicationDidChangeStatusBarOrientation() void {
return c.SDL_OnApplicationDidChangeStatusBarOrientation();
}
pub inline fn getGDKTaskQueue(outTaskQueue: XTaskQueueHandle *) bool {
pub inline fn getGDKTaskQueue(outTaskQueue: [*c]XTaskQueueHandle) bool {
return c.SDL_GetGDKTaskQueue(outTaskQueue);
}
pub inline fn getGDKDefaultUser(outUserHandle: XUserHandle *) bool {
pub inline fn getGDKDefaultUser(outUserHandle: [*c]XUserHandle) bool {
return c.SDL_GetGDKDefaultUser(outUserHandle);
}

View File

@ -2,8 +2,8 @@ const std = @import("std");
pub const c = @import("c.zig").c;
pub const Window = opaque {
pub inline fn vulkan_CreateSurface(window: *Window, instance: VkInstance, allocator: const struct VkAllocationCallbacks *, surface: VkSurfaceKHR *) bool {
return c.SDL_Vulkan_CreateSurface(window, instance, allocator, surface);
pub inline fn vulkan_CreateSurface(window: *Window, instance: VkInstance, allocator: *const VkAllocationCallbacks, surface: [*c]VkSurfaceKHR) bool {
return c.SDL_Vulkan_CreateSurface(window, instance, @ptrCast(allocator), surface);
}
};
@ -20,12 +20,12 @@ pub inline fn vulkan_UnloadLibrary() void {
return c.SDL_Vulkan_UnloadLibrary();
}
pub inline fn vulkan_GetInstanceExtensions(count: *u32) char const * const * {
pub inline fn vulkan_GetInstanceExtensions(count: *u32) [*c]char const * const {
return c.SDL_Vulkan_GetInstanceExtensions(@ptrCast(count));
}
pub inline fn vulkan_DestroySurface(instance: VkInstance, surface: VkSurfaceKHR, allocator: const struct VkAllocationCallbacks *) void {
return c.SDL_Vulkan_DestroySurface(instance, surface, allocator);
pub inline fn vulkan_DestroySurface(instance: VkInstance, surface: VkSurfaceKHR, allocator: *const VkAllocationCallbacks) void {
return c.SDL_Vulkan_DestroySurface(instance, surface, @ptrCast(allocator));
}
pub inline fn vulkan_GetPresentationSupport(instance: VkInstance, physicalDevice: VkPhysicalDevice, queueFamilyIndex: u32) bool {