diff --git a/.gitignore b/.gitignore index d023d22..e3734e7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ sdl3/ archive/ tmp/ debug/ +all-releases/ diff --git a/AGENTS.md b/AGENTS.md index 0bff171..e4c3bdf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,7 +8,7 @@ This is an SDL3 header parser that converts C header files into Zig interfaces, - Not a real C parser - best-effort text transformation specifically for SDL3 headers - Does not do proper AST elaboration or tokenization - Simple to modify but brittle -- Requires Zig 0.15.2 and git +- Requires Zig 0.17.0 and git ## Architecture @@ -54,6 +54,8 @@ The parser converts C headers to Zig files: - `--generate-json=` - Generate JSON representation - `--timestamp=` - Set custom timestamp - `--basedir=` - Set base directory for dependency resolution +- `--c-import=` - Path the generated file imports `c` from (default `c.zig`) +- `--skip-missing` - Exit successfully when the header does not exist (older SDL releases lack some headers); `zig build generate` passes this ### Output Directories @@ -66,37 +68,18 @@ The parser converts C headers to Zig files: ### Build System Patterns -**Custom Build Steps:** -The project uses custom Zig build steps for operations that need to happen during the build process: +**Build Helper Executable:** +Zig 0.17 no longer supports custom build steps with a `makeFn` (the configure and make phases run in separate processes). Filesystem work that has to happen at make time is done by a small helper executable, `src/build_helper.zig`, which build.zig runs through `addHelperStep`: ```zig -const MakeDirStep = struct { - step: std.Build.Step, - dir_path: []const u8, - - pub fn create(b: *std.Build, dir_path: []const u8) *std.Build.Step { - const self = b.allocator.create(MakeDirStep) catch @panic("OOM"); - self.* = .{ - .step = std.Build.Step.init(.{ - .id = .custom, - .name = b.fmt("mkdir {s}", .{dir_path}), - .owner = b, - .makeFn = make, - }), - .dir_path = dir_path, - }; - return &self.step; - } - - fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void { - _ = options; - const self: *MakeDirStep = @fieldParentPtr("step", step); - try std.fs.cwd().makePath(self.dir_path); - } -}; +// build-helper archive [base_dir] | mkdir | write | rmtree +const mkdir_step = addHelperStep(b, helper_exe, b.fmt("mkdir {s}", .{dir}), &.{ "mkdir", dir }); +mkdir_step.dependOn(previous_step); ``` -This pattern allows cross-platform directory creation and other filesystem operations during build without relying on shell commands. +This allows cross-platform directory creation and other filesystem operations during build without relying on shell commands. + +build.zig also checks whether `sdl3/` exists and takes a timestamp at configure time, so it calls `b.graph.poisonCache()` to keep the configuration from being cached. ### Error Handling **CRITICAL:** Whenever actual errors are encountered (parsing failures, invalid declarations, missing types, etc.), you MUST call `io.emitError` to report them properly. Do NOT use `std.debug.print` for actual errors. @@ -113,16 +96,24 @@ std.debug.print("Error: Failed to parse...\n", .{}); The code generator automatically adds appropriate casts when calling C functions: -**Parameters:** -- Opaque pointers (`*Window`, `?*GPUDevice`) → `@ptrCast` -- Enums → `@intFromEnum` -- Flags (packed structs) → `@bitCast` -- Booleans → `@bitCast` +Casts are chosen from how the C type is declared (see `castForCType` in `src/codegen.zig`), not from its name. The same rules apply to parameters and return values: -**Return values:** -- Opaque pointers (`?*Window`) → `@ptrCast` -- Booleans → `@bitCast` -- Flags (packed structs) → `@bitCast` +| C type | Parameter | Return value | +|---|---|---| +| Pointer to an SDL opaque type, struct, union, enum or flags type (any pointer depth) | `@ptrCast(@alignCast(x))` | `@ptrCast(@alignCast(...))` | +| Pointer to a primitive (`int *`, `const char *`, `void *`) | no cast | no cast | +| Enum (`enum(c_int)` in Zig; `c_uint` or `c_int` in C depending on the target) | `@intCast(@backingInt(x))` | `@fromBackingInt(@intCast(...))` | +| Flags (packed struct), `bool` | `@bitCast(x)` | `@bitCast(...)` | +| Struct/union passed by value | `@as(*const c.SDL_Foo, @ptrCast(@alignCast(&x))).*` | `@as(*const Foo, @ptrCast(@alignCast(&...))).*` | +| Function pointer typedef re-declared in Zig | `@ptrCast(@alignCast(x))` | `@ptrCast(@alignCast(...))` | +| Typedef | follows the underlying type | follows the underlying type | + +**Enums:** +- Enumerators are numbered the way C numbers them. An enumerator whose value repeats an earlier one becomes an alias (`pub const eventDisplayFirst = .eventDisplayOrientation;`) because Zig enums cannot have duplicate values. +- Inside `#if SDL_BYTEORDER == ...` blocks the little endian branch is used. + +**Flags:** +- Packed struct fields are emitted in bit order with `padN` fields for unused bits, so each flag sits on the bit the header assigns to it. **Pointer Optionality:** - All pointer parameters in standalone functions are optional (`?*const Type`) to allow null values @@ -182,17 +173,22 @@ Use `zig build generate` to regenerate all SDL3 headers and verify no regression - `freeDeclDeep()` - frees a single declaration - Both free all nested allocations (names, types, doc comments, params/fields/values/flags) -### Zig 0.15 Specifics -**IMPORTANT:** In Zig 0.15, `std.ArrayList` is an alias to `std.ArrayListUnmanaged`. This means: +### Zig 0.17 Specifics +**IMPORTANT:** `std.ArrayList` is unmanaged. This means: - ArrayList methods require an explicit allocator parameter - Use `list.append(allocator, item)` instead of `list.append(item)` - Use `list.toOwnedSlice(allocator)` instead of `list.toOwnedSlice()` - Use `list.deinit(allocator)` instead of `list.deinit()` -- Initialize with `std.ArrayList(T){}` (empty init) +- Initialize with `.empty` +- There is no `list.writer()`; use `list.print(allocator, fmt, args)` or wrap the list in a `std.Io.Writer.Allocating` (`.fromArrayList` / `.toArrayList`) + +File system, process and clock APIs take an `std.Io` instance. `main` receives it via `std.process.Init` and stores it in `src/io.zig`; use `io.get()` and `io.cwd()` (e.g. `io.cwd().readFileAlloc(io.get(), path, allocator, .limited(max))`). + +Generated code uses the 0.17 builtin names `@backingInt` / `@fromBackingInt` (formerly `@intFromEnum` / `@enumFromInt`) and `callconv(.c)`. Example: ```zig -var list = std.ArrayList(MyType){}; +var list: std.ArrayList(MyType) = .empty; errdefer list.deinit(allocator); try list.append(allocator, item); const slice = try list.toOwnedSlice(allocator); diff --git a/README.md b/README.md index 595896e..5508c3f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The zig code has gone through some manual fixups but only where there was actual works on any header in the sdl3 library. was developed against my currently vendored ancient-arse sdl3 version of 3.2.10 -requires zig 0.15.2 and git to be installed +requires zig 0.17.0 and git to be installed ## Automated usage diff --git a/build.zig b/build.zig index 6109544..b5be822 100644 --- a/build.zig +++ b/build.zig @@ -1,22 +1,22 @@ const std = @import("std"); -fn resolveHeaderRoot(allocator: std.mem.Allocator, source_dir: []const u8) ![]const u8 { +fn resolveHeaderRoot(io: std.Io, allocator: std.mem.Allocator, source_dir: []const u8) ![]const u8 { const include_sdl3 = try std.fs.path.join(allocator, &.{ source_dir, "include", "SDL3" }); defer allocator.free(include_sdl3); - if (std.fs.cwd().access(include_sdl3, .{})) { + if (std.Io.Dir.cwd().access(io, include_sdl3, .{})) { return try allocator.dupe(u8, "include/SDL3"); } else |_| {} const sdl3_dir = try std.fs.path.join(allocator, &.{ source_dir, "SDL3" }); defer allocator.free(sdl3_dir); - if (std.fs.cwd().access(sdl3_dir, .{})) { + if (std.Io.Dir.cwd().access(io, sdl3_dir, .{})) { return try allocator.dupe(u8, "SDL3"); } else |_| {} return try allocator.dupe(u8, "."); } -fn addFetchSdlStep(b: *std.Build) *std.Build.Step { +fn addFetchSdlStep(b: *std.Build, helper_exe: *std.Build.Step.Compile) *std.Build.Step { const default_sdl_url = "git@github.com:castholm/SDL.git"; const official_sdl_url = "git@github.com:libsdl-org/SDL.git"; const sdl_url_option = b.option([]const u8, "sdl-url", "URL to fetch SDL3 from (use 'official' for libsdl-org/SDL)") orelse default_sdl_url; @@ -33,13 +33,16 @@ fn addFetchSdlStep(b: *std.Build) *std.Build.Step { const fetch_step = b.step("fetch-sdl", "Fetch SDL3 source from git"); - const sdl_exists = if (std.fs.cwd().access("sdl3", .{})) true else |_| false; + // The build graph depends on whether sdl3/ exists right now, which the + // configuration cache cannot track. + b.graph.poisonCache(); + const sdl_exists = if (std.Io.Dir.cwd().access(b.graph.io, "sdl3", .{})) true else |_| false; var end_step: *std.Build.Step = undefined; if (clean_sdl) { - const remove_dir = b.addRemoveDirTree(b.path("sdl3")); + const remove_dir = addHelperStep(b, helper_exe, "rmtree sdl3", &.{ "rmtree", "sdl3" }); const fetch_sdl = b.addSystemCommand(&.{ "git", "clone", sdl_url, "sdl3" }); - fetch_sdl.step.dependOn(&remove_dir.step); + fetch_sdl.step.dependOn(remove_dir); end_step = &fetch_sdl.step; // fetch_step.dependOn(&fetch_sdl.step); } else if (sdl_exists) { @@ -61,166 +64,55 @@ fn addFetchSdlStep(b: *std.Build) *std.Build.Step { return fetch_step; } -const ArchiveStep = struct { - step: std.Build.Step, - base_dir: ?[]const u8, +/// Runs the build helper (src/build_helper.zig) with the given arguments. +/// Used for filesystem work that has to happen at make time. +fn addHelperStep(b: *std.Build, helper_exe: *std.Build.Step.Compile, name: []const u8, args: []const []const u8) *std.Build.Step { + const run = b.addRunArtifact(helper_exe); + run.addArgs(args); + run.has_side_effects = true; + run.setName(name); + return &run.step; +} - pub fn create(b: *std.Build, base_dir: ?[]const u8) *std.Build.Step { - const self = b.allocator.create(ArchiveStep) catch @panic("OOM"); - self.* = .{ - .step = std.Build.Step.init(.{ - .id = .custom, - .name = "archive generate outputs", - .owner = b, - .makeFn = make, - }), - .base_dir = base_dir, - }; - return &self.step; - } - - fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void { - _ = options; - - const self: *ArchiveStep = @fieldParentPtr("step", step); - - const cwd = std.fs.cwd(); - const json_path = if (self.base_dir) |base_dir| - try std.fs.path.join(step.owner.allocator, &.{ base_dir, "json" }) - else - try step.owner.allocator.dupe(u8, "json"); - defer step.owner.allocator.free(json_path); - - const api_path = if (self.base_dir) |base_dir| - try std.fs.path.join(step.owner.allocator, &.{ base_dir, "api" }) - else - try step.owner.allocator.dupe(u8, "api"); - defer step.owner.allocator.free(api_path); - - const archive_root = if (self.base_dir) |base_dir| - try std.fs.path.join(step.owner.allocator, &.{ base_dir, "archive", "generate" }) - else - try step.owner.allocator.dupe(u8, "archive/generate"); - defer step.owner.allocator.free(archive_root); - - const json_exists = if (cwd.access(json_path, .{})) true else |_| false; - const api_exists = if (cwd.access(api_path, .{})) true else |_| false; - - if (!json_exists and !api_exists) return; - - const timestamp = std.time.timestamp(); - const timestamp_dir = try std.fmt.allocPrint(step.owner.allocator, "{d}", .{timestamp}); - defer step.owner.allocator.free(timestamp_dir); - const archive_path = try std.fs.path.join(step.owner.allocator, &.{ archive_root, timestamp_dir }); - defer step.owner.allocator.free(archive_path); - - try cwd.makePath(archive_path); - - if (json_exists) { - const json_dest = try std.fs.path.join(step.owner.allocator, &.{ archive_path, "json" }); - defer step.owner.allocator.free(json_dest); - try cwd.rename(json_path, json_dest); - } - - if (api_exists) { - const api_dest = try std.fs.path.join(step.owner.allocator, &.{ archive_path, "api" }); - defer step.owner.allocator.free(api_dest); - try cwd.rename(api_path, api_dest); - } - } -}; - -const MakeDirStep = struct { - step: std.Build.Step, - dir_path: []const u8, - - pub fn create(b: *std.Build, dir_path: []const u8) *std.Build.Step { - const self = b.allocator.create(MakeDirStep) catch @panic("OOM"); - self.* = .{ - .step = std.Build.Step.init(.{ - .id = .custom, - .name = b.fmt("mkdir {s}", .{dir_path}), - .owner = b, - .makeFn = make, - }), - .dir_path = dir_path, - }; - return &self.step; - } - - fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void { - _ = options; - const self: *MakeDirStep = @fieldParentPtr("step", step); - try std.fs.cwd().makePath(self.dir_path); - } -}; - -const WriteStaticFileStep = struct { - step: std.Build.Step, - path: []const u8, - contents: []const u8, - - pub fn create(b: *std.Build, path: []const u8, contents: []const u8) *std.Build.Step { - const self = b.allocator.create(WriteStaticFileStep) catch @panic("OOM"); - self.* = .{ - .step = std.Build.Step.init(.{ - .id = .custom, - .name = b.fmt("write {s}", .{path}), - .owner = b, - .makeFn = make, - }), - .path = b.dupe(path), - .contents = b.dupe(contents), - }; - return &self.step; - } - - fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void { - _ = options; - const self: *WriteStaticFileStep = @fieldParentPtr("step", step); - - if (std.fs.path.dirname(self.path)) |dir| { - try std.fs.cwd().makePath(dir); - } - - try std.fs.cwd().writeFile(.{ - .sub_path = self.path, - .data = self.contents, - }); - } -}; - -pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl_step: *std.Build.Step) void { +pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, helper_exe: *std.Build.Step.Compile, fetch_sdl_step: *std.Build.Step) void { const source_dir = b.option([]const u8, "sourceDir", "Parse SDL headers from an existing local directory instead of fetching git"); const output_dir = b.option([]const u8, "outputDir", "Directory where generated api/ and json/ folders should be written"); const basedir = b.option([]const u8, "basedir", "Working directory for the parser to execute in"); const c_import_path = b.option([]const u8, "cImportPath", "Path used by generated files when importing c.zig"); const effective_output_dir = output_dir orelse source_dir; - const header_root_suffix = if (source_dir) |dir| resolveHeaderRoot(b.allocator, dir) catch @panic("OOM") else null; + const header_root_suffix = if (source_dir) |dir| resolveHeaderRoot(b.graph.io, b.allocator, dir) catch @panic("OOM") else null; // Archive existing json/ and api/ directories before regenerating - const archive_step = ArchiveStep.create(b, effective_output_dir); + const archive_step = addHelperStep( + b, + helper_exe, + "archive generate outputs", + if (effective_output_dir) |dir| &.{ "archive", dir } else &.{"archive"}, + ); + // Generation needs the previous outputs archived and, unless a local + // source directory is used, SDL fetched. `fetch-sdl` on its own must not + // touch the generated outputs. const generation_root = if (source_dir != null) archive_step else fetch_sdl_step; - if (source_dir == null) { - fetch_sdl_step.dependOn(archive_step); - } - // Write a build marker file after the source selection step to enable caching - const timestamp = std.time.timestamp(); + // Write a build marker file after the source selection step to enable caching. + // The timestamp is taken at configure time, so the configuration must not be cached. + b.graph.poisonCache(); + const timestamp = std.Io.Clock.real.now(b.graph.io).toSeconds(); const wf = b.addWriteFiles(); const marker_file = wf.add(".buildmarker", b.fmt("{d}", .{timestamp})); _ = marker_file; wf.step.dependOn(generation_root); + wf.step.dependOn(archive_step); var path_prep_step: *std.Build.Step = &wf.step; if (effective_output_dir) |dir| { - const output_dir_step = MakeDirStep.create(b, dir); + const output_dir_step = addHelperStep(b, helper_exe, b.fmt("mkdir {s}", .{dir}), &.{ "mkdir", dir }); output_dir_step.dependOn(path_prep_step); path_prep_step = output_dir_step; } if (basedir) |dir| { - const basedir_step = MakeDirStep.create(b, dir); + const basedir_step = addHelperStep(b, helper_exe, b.fmt("mkdir {s}", .{dir}), &.{ "mkdir", dir }); basedir_step.dependOn(path_prep_step); path_prep_step = basedir_step; } @@ -229,22 +121,24 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl const json_root = if (effective_output_dir) |dir| b.fmt("{s}/json", .{dir}) else "json"; const effective_c_import_path = c_import_path orelse "c.zig"; const c_bridge_target = if (c_import_path) |path| path else "../c.zig"; - const c_bridge_step = WriteStaticFileStep.create( - b, - b.fmt("{s}/c.zig", .{output_root}), + const c_bridge_path = b.fmt("{s}/c.zig", .{output_root}); + const c_bridge_step = addHelperStep(b, helper_exe, b.fmt("write {s}", .{c_bridge_path}), &.{ + "write", + c_bridge_path, b.fmt("pub const c = @import(\"{s}\").c;\n", .{c_bridge_target}), - ); + }); c_bridge_step.dependOn(path_prep_step); path_prep_step = c_bridge_step; - const stdinc_bridge_step = WriteStaticFileStep.create( - b, - b.fmt("{s}/stdinc.zig", .{output_root}), + const stdinc_bridge_path = b.fmt("{s}/stdinc.zig", .{output_root}); + const stdinc_bridge_step = addHelperStep(b, helper_exe, b.fmt("write {s}", .{stdinc_bridge_path}), &.{ + "write", + stdinc_bridge_path, \\pub const c = @import("c.zig").c; \\pub const Time = i64; \\pub const FunctionPointer = c.SDL_FunctionPointer; \\ - ); + }); stdinc_bridge_step.dependOn(path_prep_step); path_prep_step = stdinc_bridge_step; @@ -264,7 +158,7 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl .{ .header = "SDL_filesystem.h", .output = "filesystem" }, .{ .header = "SDL_gamepad.h", .output = "gamepad" }, .{ .header = "SDL_gpu.h", .output = "gpu" }, - // .{ .header = "SDL_guid.h", .output = "guid" }, + .{ .header = "SDL_guid.h", .output = "guid" }, .{ .header = "SDL_haptic.h", .output = "haptic" }, // .{ .header = "SDL_hidapi.h", .output = "hidapi" }, // Skipped: not core API .{ .header = "SDL_hints.h", .output = "hints" }, @@ -282,7 +176,7 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl .{ .header = "SDL_mouse.h", .output = "mouse" }, // .{ .header = "SDL_mutex.h", .output = "mutex" }, // Skipped: not core API .{ .header = "SDL_opengl.h", .output = "opengl" }, - // .{ .header = "SDL_pen.h", .output = "pen" }, + .{ .header = "SDL_pen.h", .output = "pen" }, .{ .header = "SDL_pixels.h", .output = "pixels" }, .{ .header = "SDL_power.h", .output = "power" }, .{ .header = "SDL_process.h", .output = "process" }, @@ -320,6 +214,7 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl regenerate.addArg(b.fmt("--basedir={s}", .{dir})); } regenerate.addArg(b.fmt("--c-import={s}", .{effective_c_import_path})); + regenerate.addArg("--skip-missing"); // regenerate.addArg(b.fmt("--output=api/{s}.zig --mocks=mocks/{s}.c", .{ header_info.output, header_info.output })); regenerate.step.dependOn(path_prep_step); regenerate_step.dependOn(®enerate.step); @@ -328,6 +223,7 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl regenerateJson.addArg(b.fmt("{s}/{s}", .{ header_root, header_info.header })); regenerateJson.addArg(b.fmt("--generate-json={s}/{s}.json", .{ json_root, header_info.output })); regenerateJson.addArg(timestamp_arg); + regenerateJson.addArg("--skip-missing"); if (basedir) |dir| { regenerateJson.addArg(b.fmt("--basedir={s}", .{dir})); } @@ -340,7 +236,17 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const fetch_sdl_step = addFetchSdlStep(b); + // Helper executable for make-time filesystem work (always built for the host). + const helper_exe = b.addExecutable(.{ + .name = "build-helper", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/build_helper.zig"), + .target = b.graph.host, + .optimize = .Debug, + }), + }); + + const fetch_sdl_step = addFetchSdlStep(b, helper_exe); // Parser executable const parser_exe = b.addExecutable(.{ @@ -354,15 +260,13 @@ pub fn build(b: *std.Build) void { b.installArtifact(parser_exe); - generateApi(b, parser_exe, fetch_sdl_step); + generateApi(b, parser_exe, helper_exe, fetch_sdl_step); // Run command const run_cmd = b.addRunArtifact(parser_exe); run_cmd.step.dependOn(b.getInstallStep()); - if (b.args) |args| { - run_cmd.addArgs(args); - } + run_cmd.addPassthruArgs(); const run_step = b.step("run", "Run the SDL3 header parser"); run_step.dependOn(&run_cmd.step); @@ -371,13 +275,9 @@ pub fn build(b: *std.Build) void { const test_mocks_cmd = b.addRunArtifact(parser_exe); test_mocks_cmd.step.dependOn(b.getInstallStep()); - const test_header_path = b.path("test_small.h"); - const test_output = b.path("zig-out/test_small.zig"); - const test_mocks = b.path("zig-out/test_small_mock.c"); - - test_mocks_cmd.addArg(test_header_path.getPath(b)); - test_mocks_cmd.addArg(b.fmt("--output={s}", .{test_output.getPath(b)})); - test_mocks_cmd.addArg(b.fmt("--mocks={s}", .{test_mocks.getPath(b)})); + test_mocks_cmd.addArg("test_small.h"); + test_mocks_cmd.addArg("--output=zig-out/test_small.zig"); + test_mocks_cmd.addArg("--mocks=zig-out/test_small_mock.c"); const test_mocks_step = b.step("test-mocks", "Test mock generation with test_small.h"); test_mocks_step.dependOn(&test_mocks_cmd.step); diff --git a/build.zig.zon b/build.zig.zon index c8dd616..e2ef62c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,7 @@ .{ .name = .sdl3_parser, .version = "0.1.0", + .minimum_zig_version = "0.17.0", .fingerprint=0x2eb3fcb4d5ae107b, .dependencies = .{}, .paths = .{ diff --git a/scripts/castholm_tags.json b/scripts/castholm_tags.json index 700ed9b..0eb986a 100644 --- a/scripts/castholm_tags.json +++ b/scripts/castholm_tags.json @@ -1,4 +1,94 @@ [ + { + "name": "v0.6.1+3.4.20", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.6.1+3.4.20", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.6.1+3.4.20", + "commit": { + "sha": "ce475292f172d506468218f939ef607d9be5e083", + "url": "https://api.github.com/repos/castholm/SDL/commits/ce475292f172d506468218f939ef607d9be5e083" + }, + "node_id": "REF_kwDONdlsr7dyZWZzL3RhZ3MvdjAuNi4xKzMuNC4yMA" + }, + { + "name": "v0.6.0+3.4.18", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.6.0+3.4.18", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.6.0+3.4.18", + "commit": { + "sha": "dbcb19aa3583c318556ecae3ecbeb29b102d37c5", + "url": "https://api.github.com/repos/castholm/SDL/commits/dbcb19aa3583c318556ecae3ecbeb29b102d37c5" + }, + "node_id": "REF_kwDONdlsr7dyZWZzL3RhZ3MvdjAuNi4wKzMuNC4xOA" + }, + { + "name": "v0.5.4+3.4.16", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.5.4+3.4.16", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.5.4+3.4.16", + "commit": { + "sha": "b72b3671502a70e109350ecac90afdc480dcfcc6", + "url": "https://api.github.com/repos/castholm/SDL/commits/b72b3671502a70e109350ecac90afdc480dcfcc6" + }, + "node_id": "REF_kwDONdlsr7dyZWZzL3RhZ3MvdjAuNS40KzMuNC4xNg" + }, + { + "name": "v0.5.3+3.4.14", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.5.3+3.4.14", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.5.3+3.4.14", + "commit": { + "sha": "fb2d799c4778832a34ccb3739e40dded700684bd", + "url": "https://api.github.com/repos/castholm/SDL/commits/fb2d799c4778832a34ccb3739e40dded700684bd" + }, + "node_id": "REF_kwDONdlsr7dyZWZzL3RhZ3MvdjAuNS4zKzMuNC4xNA" + }, + { + "name": "v0.5.2+3.4.12", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.5.2+3.4.12", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.5.2+3.4.12", + "commit": { + "sha": "1b67d371a531ecb0499d4b80a865631c299f472a", + "url": "https://api.github.com/repos/castholm/SDL/commits/1b67d371a531ecb0499d4b80a865631c299f472a" + }, + "node_id": "REF_kwDONdlsr7dyZWZzL3RhZ3MvdjAuNS4yKzMuNC4xMg" + }, + { + "name": "v0.5.1+3.4.10", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.5.1+3.4.10", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.5.1+3.4.10", + "commit": { + "sha": "018241066ffdae90d8b11f8bdc6242202f0f5451", + "url": "https://api.github.com/repos/castholm/SDL/commits/018241066ffdae90d8b11f8bdc6242202f0f5451" + }, + "node_id": "REF_kwDONdlsr7dyZWZzL3RhZ3MvdjAuNS4xKzMuNC4xMA" + }, + { + "name": "v0.5.0+3.4.8", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.5.0+3.4.8", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.5.0+3.4.8", + "commit": { + "sha": "21c6b79840d123e94a9f183f4b0fa1731668f48d", + "url": "https://api.github.com/repos/castholm/SDL/commits/21c6b79840d123e94a9f183f4b0fa1731668f48d" + }, + "node_id": "REF_kwDONdlsr7ZyZWZzL3RhZ3MvdjAuNS4wKzMuNC44" + }, + { + "name": "v0.4.2+3.4.4", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.4.2+3.4.4", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.4.2+3.4.4", + "commit": { + "sha": "76ee7f13177b5dfad124e7066dec29c90f7db275", + "url": "https://api.github.com/repos/castholm/SDL/commits/76ee7f13177b5dfad124e7066dec29c90f7db275" + }, + "node_id": "REF_kwDONdlsr7ZyZWZzL3RhZ3MvdjAuNC4yKzMuNC40" + }, + { + "name": "v0.4.1+3.4.2", + "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.4.1+3.4.2", + "tarball_url": "https://api.github.com/repos/castholm/SDL/tarball/refs/tags/v0.4.1+3.4.2", + "commit": { + "sha": "701da66369221654c501e9661c648dd3aa2cfe52", + "url": "https://api.github.com/repos/castholm/SDL/commits/701da66369221654c501e9661c648dd3aa2cfe52" + }, + "node_id": "REF_kwDONdlsr7ZyZWZzL3RhZ3MvdjAuNC4xKzMuNC4y" + }, { "name": "v0.4.0+3.4.0", "zipball_url": "https://api.github.com/repos/castholm/SDL/zipball/refs/tags/v0.4.0+3.4.0", diff --git a/scripts/official_tags.json b/scripts/official_tags.json index 7d0fe14..f4c6f96 100644 --- a/scripts/official_tags.json +++ b/scripts/official_tags.json @@ -1,4 +1,104 @@ [ + { + "name": "release-3.4.20", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.20", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.20", + "commit": { + "sha": "f00dc919ca35b9756316e86c4777392de442f9b2", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/f00dc919ca35b9756316e86c4777392de442f9b2" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC4yMA==" + }, + { + "name": "release-3.4.18", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.18", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.18", + "commit": { + "sha": "829a65d769d935c4852f8159e964312c0957260a", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/829a65d769d935c4852f8159e964312c0957260a" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC4xOA==" + }, + { + "name": "release-3.4.16", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.16", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.16", + "commit": { + "sha": "fa2c02bb6e21974a89ea9824bc53c9932abe5f9c", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/fa2c02bb6e21974a89ea9824bc53c9932abe5f9c" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC4xNg==" + }, + { + "name": "release-3.4.14", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.14", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.14", + "commit": { + "sha": "147a8ee32dbf9ac02f3794964490687b6bbda1bc", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/147a8ee32dbf9ac02f3794964490687b6bbda1bc" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC4xNA==" + }, + { + "name": "release-3.4.12", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.12", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.12", + "commit": { + "sha": "f87239e71e42da91ca317a12eefb82cfbf3393eb", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/f87239e71e42da91ca317a12eefb82cfbf3393eb" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC4xMg==" + }, + { + "name": "release-3.4.10", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.10", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.10", + "commit": { + "sha": "8e37db5e797b6167f3a00d697d816a684bd259c7", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/8e37db5e797b6167f3a00d697d816a684bd259c7" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC4xMA==" + }, + { + "name": "release-3.4.8", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.8", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.8", + "commit": { + "sha": "d9d5536704d585616d4db3c8ba3c4ff6fc2757e1", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/d9d5536704d585616d4db3c8ba3c4ff6fc2757e1" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC44" + }, + { + "name": "release-3.4.6", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.6", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.6", + "commit": { + "sha": "3aabb7bc5307324b67db9d45b6e0c48e7ad3a400", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/3aabb7bc5307324b67db9d45b6e0c48e7ad3a400" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC42" + }, + { + "name": "release-3.4.4", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.4", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.4", + "commit": { + "sha": "5848e584a1b606de26e3dbd1c7e4ecbc34f807a6", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/5848e584a1b606de26e3dbd1c7e4ecbc34f807a6" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC40" + }, + { + "name": "release-3.4.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-3.4.2", + "commit": { + "sha": "683181b47cfabd293e3ea409f838915b8297a4fd", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/683181b47cfabd293e3ea409f838915b8297a4fd" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTMuNC4y" + }, { "name": "release-3.4.0", "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-3.4.0", @@ -298,5 +398,555 @@ "url": "https://api.github.com/repos/libsdl-org/SDL/commits/ba2f78a0069118a6c583f1fbf1420144ffa35bad" }, "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMzAuNg==" + }, + { + "name": "release-2.30.5", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.30.5", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.30.5", + "commit": { + "sha": "2eef7ca475decd2b864214cdbfe72b143b16d459", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/2eef7ca475decd2b864214cdbfe72b143b16d459" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMzAuNQ==" + }, + { + "name": "release-2.30.4", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.30.4", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.30.4", + "commit": { + "sha": "92fe3b19c868ad062c323dde2cfc9d8b4bfdd785", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/92fe3b19c868ad062c323dde2cfc9d8b4bfdd785" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMzAuNA==" + }, + { + "name": "release-2.30.3", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.30.3", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.30.3", + "commit": { + "sha": "fb1497566c5a05e2babdcf45ef0ab5c7cca2c4ae", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/fb1497566c5a05e2babdcf45ef0ab5c7cca2c4ae" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMzAuMw==" + }, + { + "name": "release-2.30.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.30.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.30.2", + "commit": { + "sha": "f461d91cd265d7b9a44b4d472b1df0c0ad2855a0", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/f461d91cd265d7b9a44b4d472b1df0c0ad2855a0" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMzAuMg==" + }, + { + "name": "release-2.30.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.30.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.30.1", + "commit": { + "sha": "5adbf3765a57dc5931c2a3137390bfee2370c945", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/5adbf3765a57dc5931c2a3137390bfee2370c945" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMzAuMQ==" + }, + { + "name": "release-2.30.0", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.30.0", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.30.0", + "commit": { + "sha": "859844eae358447be8d66e6da59b6fb3df0ed778", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/859844eae358447be8d66e6da59b6fb3df0ed778" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMzAuMA==" + }, + { + "name": "release-2.28.5", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.28.5", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.28.5", + "commit": { + "sha": "15ead9a40d09a1eb9972215cceac2bf29c9b77f6", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/15ead9a40d09a1eb9972215cceac2bf29c9b77f6" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjguNQ==" + }, + { + "name": "release-2.28.4", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.28.4", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.28.4", + "commit": { + "sha": "cc016b0046d563287f0aa9f09b958b5e70d43696", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/cc016b0046d563287f0aa9f09b958b5e70d43696" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjguNA==" + }, + { + "name": "release-2.28.3", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.28.3", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.28.3", + "commit": { + "sha": "8a5ba43d00252c6c8b33c9aa4f1048222955ab4d", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/8a5ba43d00252c6c8b33c9aa4f1048222955ab4d" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjguMw==" + }, + { + "name": "release-2.28.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.28.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.28.2", + "commit": { + "sha": "031912c4b6c5db80b443f04aa56fec3e4e645153", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/031912c4b6c5db80b443f04aa56fec3e4e645153" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjguMg==" + }, + { + "name": "release-2.28.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.28.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.28.1", + "commit": { + "sha": "4761467b2e8cc7db3d6bc98747daca0051858f09", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/4761467b2e8cc7db3d6bc98747daca0051858f09" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjguMQ==" + }, + { + "name": "release-2.28.0", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.28.0", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.28.0", + "commit": { + "sha": "ffa78e6bead23e2ba3adf8ec2367ff2218d4343c", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/ffa78e6bead23e2ba3adf8ec2367ff2218d4343c" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjguMA==" + }, + { + "name": "release-2.26.5", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.26.5", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.26.5", + "commit": { + "sha": "ac13ca9ab691e13e8eebe9684740ddcb0d716203", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/ac13ca9ab691e13e8eebe9684740ddcb0d716203" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjYuNQ==" + }, + { + "name": "release-2.26.4", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.26.4", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.26.4", + "commit": { + "sha": "07d0f51fa292895443f563f0cbde4cb3802d87fa", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/07d0f51fa292895443f563f0cbde4cb3802d87fa" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjYuNA==" + }, + { + "name": "release-2.26.3", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.26.3", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.26.3", + "commit": { + "sha": "adf31f6ec0be0f9ba562889398f71172c7941023", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/adf31f6ec0be0f9ba562889398f71172c7941023" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjYuMw==" + }, + { + "name": "release-2.26.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.26.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.26.2", + "commit": { + "sha": "f070c83a6059c604cbd098680ddaee391b0a7341", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/f070c83a6059c604cbd098680ddaee391b0a7341" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjYuMg==" + }, + { + "name": "release-2.26.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.26.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.26.1", + "commit": { + "sha": "f17058b562c8a1090c0c996b42982721ace90903", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/f17058b562c8a1090c0c996b42982721ace90903" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjYuMQ==" + }, + { + "name": "release-2.26.0", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.26.0", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.26.0", + "commit": { + "sha": "0bfeed061b10ea7dd37c88d9bae1824bad760f3a", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/0bfeed061b10ea7dd37c88d9bae1824bad760f3a" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjYuMA==" + }, + { + "name": "release-2.24.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.24.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.24.2", + "commit": { + "sha": "55b03c7493a7abed33cf803d1380a40fa8af903f", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/55b03c7493a7abed33cf803d1380a40fa8af903f" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjQuMg==" + }, + { + "name": "release-2.24.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.24.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.24.1", + "commit": { + "sha": "a1d1946dcba6509f0679f507b57e7b228d32e6f8", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/a1d1946dcba6509f0679f507b57e7b228d32e6f8" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjQuMQ==" + }, + { + "name": "release-2.24.0", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.24.0", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.24.0", + "commit": { + "sha": "8c9beb0c873f6ca5efbd88f1ad2648bfc793b2ac", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/8c9beb0c873f6ca5efbd88f1ad2648bfc793b2ac" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMjQuMA==" + }, + { + "name": "release-2.0.22", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.22", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.22", + "commit": { + "sha": "53dea9830964eee8b5c2a7ee0a65d6e268dc78a1", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/53dea9830964eee8b5c2a7ee0a65d6e268dc78a1" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4yMg==" + }, + { + "name": "release-2.0.20", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.20", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.20", + "commit": { + "sha": "b424665e0899769b200231ba943353a5fee1b6b6", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/b424665e0899769b200231ba943353a5fee1b6b6" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4yMA==" + }, + { + "name": "release-2.0.18", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.18", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.18", + "commit": { + "sha": "2e9821423a237a1206e3c09020778faacfe430be", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/2e9821423a237a1206e3c09020778faacfe430be" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4xOA==" + }, + { + "name": "release-2.0.16", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.16", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.16", + "commit": { + "sha": "25f9ed87ff6947d9576fc9d79dee0784e638ac58", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/25f9ed87ff6947d9576fc9d79dee0784e638ac58" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4xNg==" + }, + { + "name": "release-2.0.14", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.14", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.14", + "commit": { + "sha": "4cd981609b50ed273d80c635c1ca4c1e5518fb21", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/4cd981609b50ed273d80c635c1ca4c1e5518fb21" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4xNA==" + }, + { + "name": "release-2.0.12", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.12", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.12", + "commit": { + "sha": "983bbf9ef3e572a073a6f5877faf1c0b4803527c", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/983bbf9ef3e572a073a6f5877faf1c0b4803527c" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4xMg==" + }, + { + "name": "release-2.0.10", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.10", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.10", + "commit": { + "sha": "0e9560aea22818884921e5e5064953257bfe7fa7", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/0e9560aea22818884921e5e5064953257bfe7fa7" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4xMA==" + }, + { + "name": "release-2.0.9", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.9", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.9", + "commit": { + "sha": "c49ecf6f7c10b668ebd87b89dfc3c7bfd215cb75", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/c49ecf6f7c10b668ebd87b89dfc3c7bfd215cb75" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC45" + }, + { + "name": "release-2.0.8", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.8", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.8", + "commit": { + "sha": "e9fc66a038304be0b892b83c16d6dcf5ee36f388", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/e9fc66a038304be0b892b83c16d6dcf5ee36f388" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC44" + }, + { + "name": "release-2.0.7", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.7", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.7", + "commit": { + "sha": "b89cac6761e9ab48e1b6149a0da90d47baf6f925", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/b89cac6761e9ab48e1b6149a0da90d47baf6f925" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC43" + }, + { + "name": "release-2.0.6", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.6", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.6", + "commit": { + "sha": "fe6b8f1c314e94f58db8119e40ad4e1f849fb667", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/fe6b8f1c314e94f58db8119e40ad4e1f849fb667" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC42" + }, + { + "name": "release-2.0.5", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.5", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.5", + "commit": { + "sha": "54eb9067e15adcf0d978d0b672fe70cef0c05528", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/54eb9067e15adcf0d978d0b672fe70cef0c05528" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC41" + }, + { + "name": "release-2.0.4", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.4", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.4", + "commit": { + "sha": "e2fd1c0fe39d83ecdee1e0c6359a299f0afad13b", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/e2fd1c0fe39d83ecdee1e0c6359a299f0afad13b" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC40" + }, + { + "name": "release-2.0.3", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.3", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.3", + "commit": { + "sha": "d4f2f01580454deef8ac43d8939ebc907d4ad759", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/d4f2f01580454deef8ac43d8939ebc907d4ad759" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4z" + }, + { + "name": "release-2.0.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.2", + "commit": { + "sha": "2b92d9b431fa8620807a48a90df578fa80d61d4b", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/2b92d9b431fa8620807a48a90df578fa80d61d4b" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4y" + }, + { + "name": "release-2.0.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.1", + "commit": { + "sha": "7108aac5ac1060a32d785ef63f2f3bfaa91d7c06", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/7108aac5ac1060a32d785ef63f2f3bfaa91d7c06" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4x" + }, + { + "name": "release-2.0.0", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/release-2.0.0", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/release-2.0.0", + "commit": { + "sha": "1ad936eb29cf4506a7a103e8288d732f23e9c2b0", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/1ad936eb29cf4506a7a103e8288d732f23e9c2b0" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9yZWxlYXNlLTIuMC4w" + }, + { + "name": "preview-3.3.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/preview-3.3.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/preview-3.3.2", + "commit": { + "sha": "b31c4b70b3031dc4eb873612d65595a31b439a30", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/b31c4b70b3031dc4eb873612d65595a31b439a30" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmV2aWV3LTMuMy4y" + }, + { + "name": "preview-3.1.8", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/preview-3.1.8", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/preview-3.1.8", + "commit": { + "sha": "22422f7748d5128135995ed34c8f8012861c7332", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/22422f7748d5128135995ed34c8f8012861c7332" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmV2aWV3LTMuMS44" + }, + { + "name": "preview-3.1.6", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/preview-3.1.6", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/preview-3.1.6", + "commit": { + "sha": "78cc5c173404488d80751af226d1eaf67033bcc4", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/78cc5c173404488d80751af226d1eaf67033bcc4" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmV2aWV3LTMuMS42" + }, + { + "name": "preview-3.1.3", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/preview-3.1.3", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/preview-3.1.3", + "commit": { + "sha": "e292d1f5ace469f718d7b6b4dec8c28e37dcaa0e", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/e292d1f5ace469f718d7b6b4dec8c28e37dcaa0e" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmV2aWV3LTMuMS4z" + }, + { + "name": "prerelease-3.3.6", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-3.3.6", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-3.3.6", + "commit": { + "sha": "ef0a604d44f5e44d4c1b34c215d68be5a985cd7e", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/ef0a604d44f5e44d4c1b34c215d68be5a985cd7e" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTMuMy42" + }, + { + "name": "prerelease-3.3.4", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-3.3.4", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-3.3.4", + "commit": { + "sha": "f173fd28f04cb64ae054d6a97edb5d33925f539b", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/f173fd28f04cb64ae054d6a97edb5d33925f539b" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTMuMy40" + }, + { + "name": "prerelease-3.1.10", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-3.1.10", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-3.1.10", + "commit": { + "sha": "b96bb152c2dffd39f49cec431f23ac60cec395b4", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/b96bb152c2dffd39f49cec431f23ac60cec395b4" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTMuMS4xMA==" + }, + { + "name": "prerelease-2.29.3", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-2.29.3", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-2.29.3", + "commit": { + "sha": "4a62e1c0ca60052e78a7e843f2522f8831999e08", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/4a62e1c0ca60052e78a7e843f2522f8831999e08" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTIuMjkuMw==" + }, + { + "name": "prerelease-2.29.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-2.29.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-2.29.2", + "commit": { + "sha": "ef7261bc41e23a2c16d7219ccf7bc1e7bce61da4", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/ef7261bc41e23a2c16d7219ccf7bc1e7bce61da4" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTIuMjkuMg==" + }, + { + "name": "prerelease-2.29.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-2.29.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-2.29.1", + "commit": { + "sha": "cfc22ac7d7a1fb898096236fe8eabf0062616055", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/cfc22ac7d7a1fb898096236fe8eabf0062616055" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTIuMjkuMQ==" + }, + { + "name": "prerelease-2.27.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-2.27.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-2.27.1", + "commit": { + "sha": "d4f9be44160b4767753bc8756b9819d47e957121", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/d4f9be44160b4767753bc8756b9819d47e957121" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTIuMjcuMQ==" + }, + { + "name": "prerelease-2.25.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-2.25.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-2.25.1", + "commit": { + "sha": "78ea6af2cddfa050a394ff9030d0ddd631099848", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/78ea6af2cddfa050a394ff9030d0ddd631099848" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTIuMjUuMQ==" + }, + { + "name": "prerelease-2.23.2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-2.23.2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-2.23.2", + "commit": { + "sha": "cb46e1b3f06a08d57b4ccd83127d1ec3139e1c0f", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/cb46e1b3f06a08d57b4ccd83127d1ec3139e1c0f" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTIuMjMuMg==" + }, + { + "name": "prerelease-2.23.1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/prerelease-2.23.1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/prerelease-2.23.1", + "commit": { + "sha": "59fb7acbf7af9d64a2d5432bb6677585a0ddd50a", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/59fb7acbf7af9d64a2d5432bb6677585a0ddd50a" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy9wcmVyZWxlYXNlLTIuMjMuMQ==" + }, + { + "name": "2.0.22-RC3", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/2.0.22-RC3", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/2.0.22-RC3", + "commit": { + "sha": "981e1e3c4489add5bf6d4df5415af3cf1ef2773d", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/981e1e3c4489add5bf6d4df5415af3cf1ef2773d" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy8yLjAuMjItUkMz" + }, + { + "name": "2.0.22-RC2", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/2.0.22-RC2", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/2.0.22-RC2", + "commit": { + "sha": "ba62ead5ecc111070381c4d32d7b21dfc9bb1493", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/ba62ead5ecc111070381c4d32d7b21dfc9bb1493" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy8yLjAuMjItUkMy" + }, + { + "name": "2.0.22-RC1", + "zipball_url": "https://api.github.com/repos/libsdl-org/SDL/zipball/refs/tags/2.0.22-RC1", + "tarball_url": "https://api.github.com/repos/libsdl-org/SDL/tarball/refs/tags/2.0.22-RC1", + "commit": { + "sha": "505d6a4a052592b2676f87456c1f564daa8d2c50", + "url": "https://api.github.com/repos/libsdl-org/SDL/commits/505d6a4a052592b2676f87456c1f564daa8d2c50" + }, + "node_id": "MDM6UmVmMzMwMDA4ODAxOnJlZnMvdGFncy8yLjAuMjItUkMx" } ] diff --git a/scripts/releases.json b/scripts/releases.json index 43d9f52..1476124 100644 --- a/scripts/releases.json +++ b/scripts/releases.json @@ -3,6 +3,15 @@ "castholm": { "url": "git@github.com:castholm/SDL.git", "tags": [ + "v0.6.1+3.4.20", + "v0.6.0+3.4.18", + "v0.5.4+3.4.16", + "v0.5.3+3.4.14", + "v0.5.2+3.4.12", + "v0.5.1+3.4.10", + "v0.5.0+3.4.8", + "v0.4.2+3.4.4", + "v0.4.1+3.4.2", "v0.4.0+3.4.0", "v0.3.3+3.2.28", "v0.3.2+3.2.26", @@ -26,6 +35,16 @@ "official": { "url": "git@github.com:libsdl-org/SDL.git", "tags": [ + "release-3.4.20", + "release-3.4.18", + "release-3.4.16", + "release-3.4.14", + "release-3.4.12", + "release-3.4.10", + "release-3.4.8", + "release-3.4.6", + "release-3.4.4", + "release-3.4.2", "release-3.4.0", "release-3.2.30", "release-3.2.28", diff --git a/scripts/test-all-releases.py b/scripts/test-all-releases.py index 611d5b5..964417e 100644 --- a/scripts/test-all-releases.py +++ b/scripts/test-all-releases.py @@ -80,6 +80,7 @@ def test_release(repo_name, tag, sdl_url_flag, clean=False): "zig", "build", "generate", f"-Dref={tag}", f"-Dbasedir={basedir}", + f"-DoutputDir={basedir}", sdl_url_flag ] diff --git a/src/build_helper.zig b/src/build_helper.zig new file mode 100644 index 0000000..bff1c34 --- /dev/null +++ b/src/build_helper.zig @@ -0,0 +1,74 @@ +//! Small helper executable used by build.zig for filesystem work that has to +//! happen at make time (the build system no longer supports custom steps). +//! +//! Usage: +//! build-helper archive [base_dir] move /json and /api to /archive/generate// +//! build-helper mkdir create a directory and its parents +//! build-helper write write a file, creating parent directories +//! build-helper rmtree recursively delete a directory +const std = @import("std"); +const Dir = std.Io.Dir; + +pub fn main(init: std.process.Init) !void { + const io = init.io; + const arena = init.arena.allocator(); + const args = try init.minimal.args.toSlice(arena); + + if (args.len < 2) return usage(); + const command = args[1]; + const rest = args[2..]; + + if (std.mem.eql(u8, command, "archive")) { + if (rest.len > 1) return usage(); + try archive(io, arena, if (rest.len == 1) rest[0] else null); + } else if (std.mem.eql(u8, command, "mkdir")) { + if (rest.len != 1) return usage(); + try Dir.cwd().createDirPath(io, rest[0]); + } else if (std.mem.eql(u8, command, "write")) { + if (rest.len != 2) return usage(); + if (std.fs.path.dirname(rest[0])) |dir| { + try Dir.cwd().createDirPath(io, dir); + } + try Dir.cwd().writeFile(io, .{ .sub_path = rest[0], .data = rest[1] }); + } else if (std.mem.eql(u8, command, "rmtree")) { + if (rest.len != 1) return usage(); + try Dir.cwd().deleteTree(io, rest[0]); + } else { + return usage(); + } +} + +fn usage() error{InvalidArgument} { + std.debug.print("usage: build-helper (archive [base_dir] | mkdir | write | rmtree )\n", .{}); + return error.InvalidArgument; +} + +fn exists(io: std.Io, path: []const u8) bool { + Dir.cwd().access(io, path, .{}) catch return false; + return true; +} + +/// Moves existing json/ and api/ directories out of the way before regenerating. +fn archive(io: std.Io, arena: std.mem.Allocator, base_dir: ?[]const u8) !void { + const base = base_dir orelse "."; + const cwd = Dir.cwd(); + + const json_path = try std.fs.path.join(arena, &.{ base, "json" }); + const api_path = try std.fs.path.join(arena, &.{ base, "api" }); + + const json_exists = exists(io, json_path); + const api_exists = exists(io, api_path); + if (!json_exists and !api_exists) return; + + const timestamp = std.Io.Clock.real.now(io).toSeconds(); + const timestamp_dir = try std.fmt.allocPrint(arena, "{d}", .{timestamp}); + const archive_path = try std.fs.path.join(arena, &.{ base, "archive", "generate", timestamp_dir }); + try cwd.createDirPath(io, archive_path); + + if (json_exists) { + try cwd.rename(json_path, cwd, try std.fs.path.join(arena, &.{ archive_path, "json" }), io); + } + if (api_exists) { + try cwd.rename(api_path, cwd, try std.fs.path.join(arena, &.{ archive_path, "api" }), io); + } +} diff --git a/src/codegen.zig b/src/codegen.zig index 87c144c..37d157d 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -22,6 +22,39 @@ const TypeAlias = struct { target_name: []const u8, }; +/// Conversion applied to a value crossing the Zig <-> C boundary. +const Cast = enum { + none, + /// Pointer to a type that is declared differently on the Zig side. + ptr, + /// Same-sized value: bool or packed flags. + bit, + /// Extern struct/union passed by value; reinterpreted through a pointer + /// because `@bitCast` does not accept extern aggregates. + aggregate, + /// Zig `enum(c_int)` <-> C enum (whose integer type is platform dependent). + enumeration, + + fn returnPrefix(cast: Cast) []const u8 { + return switch (cast) { + .none => "", + .ptr => "@ptrCast(@alignCast(", + .bit => "@bitCast(", + .enumeration => "@fromBackingInt(@intCast(", + .aggregate => unreachable, // needs the type name, see writeReturnPrefix + }; + } + + fn returnSuffix(cast: Cast) []const u8 { + return switch (cast) { + .none => "", + .bit => ")", + .ptr, .enumeration => "))", + .aggregate => "))).*", + }; + } +}; + pub const CodeGenOptions = struct { decls: []const ResolvedDecl, module_name: []const u8, @@ -177,14 +210,14 @@ pub const CodeGen = struct { } fn writeHeader(self: *CodeGen) !void { - try self.output.writer(self.allocator).print( + try self.output.print(self.allocator, \\const std = @import("std"); \\pub const c = @import("{s}").c; \\ , .{self.c_import_path}); for (self.import_modules.items) |module| { - try self.output.writer(self.allocator).print("const {s} = @import(\"{s}.zig\");\n", .{ + try self.output.print(self.allocator, "const {s} = @import(\"{s}.zig\");\n", .{ module.import_name, module.module_name, }); @@ -194,7 +227,7 @@ pub const CodeGen = struct { } for (self.aliases.items) |alias_decl| { - try self.output.writer(self.allocator).print("pub const {s} = {s}.{s};\n", .{ + try self.output.print(self.allocator, "pub const {s} = {s}.{s};\n", .{ alias_decl.name, alias_decl.import_name, alias_decl.target_name, @@ -207,7 +240,7 @@ pub const CodeGen = struct { if (self.skipped.len > 0) { try self.output.appendSlice(self.allocator, "pub const unsupported = struct {\n"); for (self.skipped) |item| { - try self.output.writer(self.allocator).print(" pub const @\"{s}\" = \"{s}\";\n", .{ item.name, item.reason }); + try self.output.print(self.allocator, " pub const @\"{s}\" = \"{s}\";\n", .{ item.name, item.reason }); } try self.output.appendSlice(self.allocator, "};\n\n"); } @@ -258,7 +291,7 @@ pub const CodeGen = struct { if (self.opaque_methods.get(zig_name)) |method_list| { if (method_list.items.len > 0) { - try self.output.writer(self.allocator).print("pub const {s} = opaque {{\n", .{zig_name}); + try self.output.print(self.allocator, "pub const {s} = opaque {{\n", .{zig_name}); for (method_list.items) |func| { try self.writeFunctionAsMethod(func, zig_name); } @@ -267,7 +300,7 @@ pub const CodeGen = struct { } } - try self.output.writer(self.allocator).print("pub const {s} = opaque {{}};\n\n", .{zig_name}); + try self.output.print(self.allocator, "pub const {s} = opaque {{}};\n\n", .{zig_name}); } fn writeTypedef(self: *CodeGen, typedef_decl: patterns.TypedefDecl) !void { @@ -289,20 +322,20 @@ pub const CodeGen = struct { const return_type = try types.convertType(func_ptr_decl.return_type, self.allocator); defer self.allocator.free(return_type); - try self.output.writer(self.allocator).print("pub const {s} = *const fn(", .{zig_name}); + try self.output.print(self.allocator, "pub const {s} = *const fn(", .{zig_name}); for (func_ptr_decl.params, 0..) |param, i| { if (i > 0) try self.output.appendSlice(self.allocator, ", "); const param_type = try types.convertType(param.type_name, self.allocator); defer self.allocator.free(param_type); - try self.output.writer(self.allocator).print("{s}: {s}", .{ param.name, param_type }); + try self.output.print(self.allocator, "{s}: {s}", .{ param.name, param_type }); } - try self.output.writer(self.allocator).print(") callconv(.C) {s};\n\n", .{return_type}); + try self.output.print(self.allocator, ") callconv(.c) {s};\n\n", .{return_type}); } fn writeCTypeAlias(self: *CodeGen, alias: patterns.CTypeAlias) !void { if (alias.doc_comment) |doc| try self.writeDocComment(doc); const zig_name = naming.typeNameToZig(alias.name); - try self.output.writer(self.allocator).print("pub const {s} = c.{s};\n\n", .{ zig_name, alias.name }); + try self.output.print(self.allocator, "pub const {s} = c.{s};\n\n", .{ zig_name, alias.name }); } fn enumShouldBeFlags(self: *CodeGen, enum_decl: EnumDecl) bool { @@ -354,6 +387,14 @@ pub const CodeGen = struct { }; } + /// Parses an integer literal as written in a C enum (`12`, `-1`, `0x8000u`). + fn parseEnumLiteral(text: []const u8) ?i128 { + var trimmed = std.mem.trim(u8, text, " \t()"); + trimmed = std.mem.trimEnd(u8, trimmed, "uUlL"); + if (trimmed.len == 0) return null; + return std.fmt.parseInt(i128, trimmed, 0) catch null; + } + fn writeEnum(self: *CodeGen, enum_decl: EnumDecl) !void { if (enum_decl.values.len == 0) return; if (self.enumShouldBeFlags(enum_decl)) { @@ -364,7 +405,7 @@ pub const CodeGen = struct { const zig_name = naming.typeNameToZig(enum_decl.name); if (enum_decl.doc_comment) |doc| try self.writeDocComment(doc); - try self.output.writer(self.allocator).print("pub const {s} = enum(c_int) {{\n", .{zig_name}); + try self.output.print(self.allocator, "pub const {s} = enum(c_int) {{\n", .{zig_name}); const value_names = try self.allocator.alloc([]const u8, enum_decl.values.len); defer self.allocator.free(value_names); @@ -372,60 +413,68 @@ pub const CodeGen = struct { const prefix = try naming.detectCommonPrefix(value_names, self.allocator); defer self.allocator.free(prefix); - var identifier_to_value = std.StringHashMap([]const u8).init(self.allocator); - defer identifier_to_value.deinit(); - var value_to_name = std.StringHashMap([]const u8).init(self.allocator); + // Work out the numeric value of every enumerator the way a C compiler + // would, so that duplicates (which Zig does not allow) become aliases + // and implicit values stay correct. + var name_to_value = std.StringHashMap(i128).init(self.allocator); + defer name_to_value.deinit(); + var value_to_name = std.AutoHashMap(i128, []const u8).init(self.allocator); defer value_to_name.deinit(); - for (enum_decl.values) |value| { - if (value.value) |explicit_value| { - const clean_value = if (std.mem.endsWith(u8, explicit_value, "u")) explicit_value[0 .. explicit_value.len - 1] else explicit_value; - try identifier_to_value.put(value.name, clean_value); - } - } - - const resolved_values = try self.allocator.alloc(?[]const u8, enum_decl.values.len); - defer self.allocator.free(resolved_values); - for (enum_decl.values, 0..) |value, i| { - if (value.value) |explicit_value| { - const clean_value = if (std.mem.endsWith(u8, explicit_value, "u")) explicit_value[0 .. explicit_value.len - 1] else explicit_value; - if (clean_value.len > 0 and !std.ascii.isDigit(clean_value[0])) { - resolved_values[i] = identifier_to_value.get(clean_value) orelse clean_value; - } else { - resolved_values[i] = clean_value; - } - } else { - resolved_values[i] = null; - } - } - const EnumAlias = struct { name: []const u8, target: []const u8, comment: ?[]const u8 }; var aliases: std.ArrayList(EnumAlias) = .empty; defer aliases.deinit(self.allocator); - for (enum_decl.values, 0..) |value, i| { + // Value the next enumerator gets in C / in the emitted Zig enum when no + // explicit value is written. Null when a value could not be evaluated. + var next_c_value: ?i128 = 0; + var next_zig_value: ?i128 = 0; + + for (enum_decl.values) |value| { const zig_value = try naming.enumValueToZig(value.name, prefix, self.allocator); defer self.allocator.free(zig_value); - if (resolved_values[i]) |numeric_value| { - if (value_to_name.get(numeric_value)) |first_name| { + const numeric: ?i128 = if (value.value) |explicit_value| + parseEnumLiteral(explicit_value) orelse name_to_value.get(std.mem.trim(u8, explicit_value, " \t()")) + else + next_c_value; + next_c_value = if (numeric) |n| n + 1 else null; + + if (numeric) |n| { + try name_to_value.put(value.name, n); + + if (value_to_name.get(n)) |first_name| { try aliases.append(self.allocator, .{ .name = try self.allocator.dupe(u8, zig_value), .target = try naming.enumValueToZig(first_name, prefix, self.allocator), .comment = if (value.comment) |c| try self.allocator.dupe(u8, c) else null, }); - } else { - try value_to_name.put(numeric_value, value.name); - if (value.comment) |comment| { - try self.output.writer(self.allocator).print(" {s} = {s}, //{s}\n", .{ zig_value, numeric_value, comment }); + continue; + } + try value_to_name.put(n, value.name); + + try self.output.print(self.allocator, " {s}", .{zig_value}); + if (value.value != null or next_zig_value == null or next_zig_value.? != n) { + if (value.value != null and parseEnumLiteral(value.value.?) != null) { + // Keep the spelling used in the header (hex stays hex). + const literal = std.mem.trim(u8, value.value.?, " \t()"); + const clean = std.mem.trimEnd(u8, literal, "uUlL"); + try self.output.print(self.allocator, " = {s}", .{clean}); } else { - try self.output.writer(self.allocator).print(" {s} = {s},\n", .{ zig_value, numeric_value }); + try self.output.print(self.allocator, " = {d}", .{n}); } } - } else if (value.comment) |comment| { - try self.output.writer(self.allocator).print(" {s}, //{s}\n", .{ zig_value, comment }); + next_zig_value = n + 1; } else { - try self.output.writer(self.allocator).print(" {s},\n", .{zig_value}); + // Not evaluable (e.g. a macro expression): emit it verbatim. + try self.output.print(self.allocator, " {s} = {s}", .{ zig_value, value.value.? }); + next_zig_value = null; + } + + if (value.comment) |comment| { + try self.output.print(self.allocator, ", //{s}\n", .{comment}); + } else { + try self.output.appendSlice(self.allocator, ",\n"); } } @@ -433,9 +482,9 @@ pub const CodeGen = struct { try self.output.appendSlice(self.allocator, "\n"); for (aliases.items) |alias_decl| { if (alias_decl.comment) |comment| { - try self.output.writer(self.allocator).print(" pub const {s} = .{s}; //{s}\n", .{ alias_decl.name, alias_decl.target, comment }); + try self.output.print(self.allocator, " pub const {s} = .{s}; //{s}\n", .{ alias_decl.name, alias_decl.target, comment }); } else { - try self.output.writer(self.allocator).print(" pub const {s} = .{s};\n", .{ alias_decl.name, alias_decl.target }); + try self.output.print(self.allocator, " pub const {s} = .{s};\n", .{ alias_decl.name, alias_decl.target }); } self.allocator.free(alias_decl.name); self.allocator.free(alias_decl.target); @@ -451,18 +500,18 @@ pub const CodeGen = struct { if (struct_decl.doc_comment) |doc| try self.writeDocComment(doc); if (struct_decl.has_unions) { - try self.output.writer(self.allocator).print("pub const {s} = opaque {{}};\n\n", .{zig_name}); + try self.output.print(self.allocator, "pub const {s} = opaque {{}};\n\n", .{zig_name}); return; } - try self.output.writer(self.allocator).print("pub const {s} = extern struct {{\n", .{zig_name}); + try self.output.print(self.allocator, "pub const {s} = extern struct {{\n", .{zig_name}); for (struct_decl.fields) |field| { const zig_type = try self.convertAggregateFieldType(field.type_name); defer self.allocator.free(zig_type); if (field.comment) |comment| { - try self.output.writer(self.allocator).print(" {s}: {s}, // {s}\n", .{ field.name, zig_type, comment }); + try self.output.print(self.allocator, " {s}: {s}, // {s}\n", .{ field.name, zig_type, comment }); } else { - try self.output.writer(self.allocator).print(" {s}: {s},\n", .{ field.name, zig_type }); + try self.output.print(self.allocator, " {s}: {s},\n", .{ field.name, zig_type }); } } try self.output.appendSlice(self.allocator, "};\n\n"); @@ -471,14 +520,14 @@ pub const CodeGen = struct { fn writeUnion(self: *CodeGen, union_decl: patterns.UnionDecl) !void { const zig_name = naming.typeNameToZig(union_decl.name); if (union_decl.doc_comment) |doc| try self.writeDocComment(doc); - try self.output.writer(self.allocator).print("pub const {s} = extern union {{\n", .{zig_name}); + try self.output.print(self.allocator, "pub const {s} = extern union {{\n", .{zig_name}); for (union_decl.fields) |field| { const zig_type = try self.convertAggregateFieldType(field.type_name); defer self.allocator.free(zig_type); if (field.comment) |comment| { - try self.output.writer(self.allocator).print(" {s}: {s}, // {s}\n", .{ field.name, zig_type, comment }); + try self.output.print(self.allocator, " {s}: {s}, // {s}\n", .{ field.name, zig_type, comment }); } else { - try self.output.writer(self.allocator).print(" {s}: {s},\n", .{ field.name, zig_type }); + try self.output.print(self.allocator, " {s}: {s},\n", .{ field.name, zig_type }); } } try self.output.appendSlice(self.allocator, "};\n\n"); @@ -506,7 +555,7 @@ pub const CodeGen = struct { else 32; - try self.output.writer(self.allocator).print("pub const {s} = packed struct({s}) {{\n", .{ zig_name, underlying_type }); + try self.output.print(self.allocator, "pub const {s} = packed struct({s}) {{\n", .{ zig_name, underlying_type }); const flag_names = try self.allocator.alloc([]const u8, flag_decl.flags.len); defer self.allocator.free(flag_names); @@ -514,25 +563,66 @@ pub const CodeGen = struct { const prefix = try naming.detectCommonPrefix(flag_names, self.allocator); defer self.allocator.free(prefix); - var used_bits = std.bit_set.IntegerBitSet(64).initEmpty(); - for (flag_decl.flags) |flag| { + // Fields of a packed struct are laid out in declaration order, so the + // flags have to be emitted by bit position with padding for the gaps. + const FlagBit = struct { bit: u6, index: usize }; + var flag_bits: std.ArrayList(FlagBit) = .empty; + defer flag_bits.deinit(self.allocator); + // Flags that share a bit with an earlier flag become constants. + var duplicate_flags: std.ArrayList(FlagBit) = .empty; + defer duplicate_flags.deinit(self.allocator); + + var used_bits = std.bit_set.Integer(64).empty; + for (flag_decl.flags, 0..) |flag, i| { + const bit_pos = self.parseBitPosition(flag.value) catch continue; + if (bit_pos >= type_bits) continue; + if (used_bits.isSet(bit_pos)) { + try duplicate_flags.append(self.allocator, .{ .bit = bit_pos, .index = i }); + continue; + } + used_bits.set(bit_pos); + try flag_bits.append(self.allocator, .{ .bit = bit_pos, .index = i }); + } + std.mem.sort(FlagBit, flag_bits.items, {}, struct { + fn lessThan(_: void, lhs: FlagBit, rhs: FlagBit) bool { + return lhs.bit < rhs.bit; + } + }.lessThan); + + var next_bit: u32 = 0; + var pad_index: u32 = 0; + for (flag_bits.items) |flag_bit| { + if (flag_bit.bit > next_bit) { + try self.output.print(self.allocator, " pad{d}: u{d} = 0,\n", .{ pad_index, flag_bit.bit - next_bit }); + pad_index += 1; + } + const flag = flag_decl.flags[flag_bit.index]; const zig_flag = try naming.flagNameToZig(flag.name, prefix, self.allocator); defer self.allocator.free(zig_flag); - const bit_pos = self.parseBitPosition(flag.value) catch continue; - used_bits.set(bit_pos); if (flag.comment) |comment| { - try self.output.writer(self.allocator).print(" {s}: bool = false, // {s}\n", .{ zig_flag, comment }); + try self.output.print(self.allocator, " {s}: bool = false, // {s}\n", .{ zig_flag, comment }); } else { - try self.output.writer(self.allocator).print(" {s}: bool = false,\n", .{zig_flag}); + try self.output.print(self.allocator, " {s}: bool = false,\n", .{zig_flag}); } + next_bit = @as(u32, flag_bit.bit) + 1; } - const padding_bits = type_bits - used_bits.count() - 1; - if (padding_bits > 0) { - try self.output.writer(self.allocator).print(" pad0: u{d} = 0,\n", .{padding_bits}); + if (next_bit < type_bits) { + const remaining = type_bits - next_bit; + if (remaining > 1) { + try self.output.print(self.allocator, " pad{d}: u{d} = 0,\n", .{ pad_index, remaining - 1 }); + } + try self.output.appendSlice(self.allocator, " rsvd: bool = false,\n"); + } + try self.output.appendSlice(self.allocator, "\n"); + try self.output.print(self.allocator, " pub const None = {s}{{}};\n", .{zig_name}); + + for (duplicate_flags.items) |flag_bit| { + const flag = flag_decl.flags[flag_bit.index]; + const zig_flag = try naming.flagNameToZig(flag.name, prefix, self.allocator); + defer self.allocator.free(zig_flag); + try self.output.print(self.allocator, " pub const {s}: {s} = @bitCast(@as({s}, 1 << {d}));\n", .{ zig_flag, zig_name, underlying_type, flag_bit.bit }); } - try self.output.appendSlice(self.allocator, " rsvd: bool = false,\n\n"); - try self.output.writer(self.allocator).print(" pub const None = {s}{{}};\n", .{zig_name}); for (flag_decl.constants) |constant| { const zig_const_camel = try naming.flagNameToZig(constant.name, prefix, self.allocator); @@ -542,9 +632,9 @@ pub const CodeGen = struct { if (zig_const.len > 0) zig_const[0] = std.ascii.toUpper(zig_const[0]); if (constant.comment) |comment| { - try self.output.writer(self.allocator).print(" pub const {s}: {s} = @bitCast(@as({s}, {s})); // {s}\n", .{ zig_const, zig_name, underlying_type, constant.value, comment }); + try self.output.print(self.allocator, " pub const {s}: {s} = @bitCast(@as({s}, {s})); // {s}\n", .{ zig_const, zig_name, underlying_type, constant.value, comment }); } else { - try self.output.writer(self.allocator).print(" pub const {s}: {s} = @bitCast(@as({s}, {s}));\n", .{ zig_const, zig_name, underlying_type, constant.value }); + try self.output.print(self.allocator, " pub const {s}: {s} = @bitCast(@as({s}, {s}));\n", .{ zig_const, zig_name, underlying_type, constant.value }); } } @@ -559,7 +649,7 @@ pub const CodeGen = struct { const zig_return_type = try types.convertType(func.return_type, self.allocator); defer self.allocator.free(zig_return_type); - try self.output.writer(self.allocator).print(" pub inline fn {s}(", .{zig_name}); + try self.output.print(self.allocator, " pub inline fn {s}(", .{zig_name}); for (func.params, 0..) |param, i| { const zig_type = try self.convertFunctionParamType(func, param); defer self.allocator.free(zig_type); @@ -569,22 +659,20 @@ pub const CodeGen = struct { const lower_name = try std.ascii.allocLowerString(self.allocator, owner_type); defer self.allocator.free(lower_name); const non_nullable = if (std.mem.startsWith(u8, zig_type, "?*")) zig_type[1..] else zig_type; - try self.output.writer(self.allocator).print("{s}: {s}", .{ lower_name, non_nullable }); + try self.output.print(self.allocator, "{s}: {s}", .{ lower_name, non_nullable }); } else if (param.name.len > 0) { - try self.output.writer(self.allocator).print("{s}: {s}", .{ param.name, zig_type }); + try self.output.print(self.allocator, "{s}: {s}", .{ param.name, zig_type }); } else { - try self.output.writer(self.allocator).print("{s}", .{zig_type}); + try self.output.print(self.allocator, "{s}", .{zig_type}); } } - try self.output.writer(self.allocator).print(") {s} {{\n", .{zig_return_type}); + try self.output.print(self.allocator, ") {s} {{\n", .{zig_return_type}); try self.output.appendSlice(self.allocator, " return "); - const return_cast = if (!std.mem.eql(u8, zig_return_type, "void")) types.getReturnCastType(zig_return_type) else .none; - if (return_cast != .none) { - try self.output.writer(self.allocator).print("{s}(", .{castTypeToString(return_cast)}); - } + const return_cast: Cast = if (!std.mem.eql(u8, zig_return_type, "void")) self.castForCType(func.return_type) else .none; + try self.writeReturnPrefix(return_cast, zig_return_type); - try self.output.writer(self.allocator).print("c.{s}(", .{func.name}); + try self.output.print(self.allocator, "c.{s}(", .{func.name}); for (func.params, 0..) |param, i| { if (i > 0) try self.output.appendSlice(self.allocator, ", "); if (param.name.len > 0 or i == 0) { @@ -595,23 +683,13 @@ pub const CodeGen = struct { } else try self.allocator.dupe(u8, param.name); defer self.allocator.free(param_name); - const zig_param_type = try self.convertFunctionParamType(func, param); - defer self.allocator.free(zig_param_type); - const param_cast = self.getFunctionParamCastType(param, zig_param_type); - - if (param_cast == .none) { - try self.output.writer(self.allocator).print("{s}", .{param_name}); - } else { - try self.output.writer(self.allocator).print("{s}({s})", .{ castTypeToString(param_cast), param_name }); - } + try self.writeCallArg(param_name, param.type_name); } } - if (return_cast != .none) { - try self.output.appendSlice(self.allocator, "));\n"); - } else { - try self.output.appendSlice(self.allocator, ");\n"); - } + try self.output.appendSlice(self.allocator, ")"); + try self.output.appendSlice(self.allocator, return_cast.returnSuffix()); + try self.output.appendSlice(self.allocator, ";\n"); try self.output.appendSlice(self.allocator, " }\n\n"); } @@ -622,47 +700,35 @@ pub const CodeGen = struct { const zig_return_type = try types.convertType(func.return_type, self.allocator); defer self.allocator.free(zig_return_type); - try self.output.writer(self.allocator).print("pub inline fn {s}(", .{zig_name}); + try self.output.print(self.allocator, "pub inline fn {s}(", .{zig_name}); for (func.params, 0..) |param, i| { const zig_type = try self.convertFunctionParamType(func, param); defer self.allocator.free(zig_type); if (i > 0) try self.output.appendSlice(self.allocator, ", "); if (param.name.len > 0) { - try self.output.writer(self.allocator).print("{s}: {s}", .{ param.name, zig_type }); + try self.output.print(self.allocator, "{s}: {s}", .{ param.name, zig_type }); } else { - try self.output.writer(self.allocator).print("{s}", .{zig_type}); + try self.output.print(self.allocator, "{s}", .{zig_type}); } } - try self.output.writer(self.allocator).print(") {s} {{\n", .{zig_return_type}); + try self.output.print(self.allocator, ") {s} {{\n", .{zig_return_type}); try self.output.appendSlice(self.allocator, " return "); - const return_cast = if (!std.mem.eql(u8, zig_return_type, "void")) types.getReturnCastType(zig_return_type) else .none; - if (return_cast != .none) { - try self.output.writer(self.allocator).print("{s}(", .{castTypeToString(return_cast)}); - } + const return_cast: Cast = if (!std.mem.eql(u8, zig_return_type, "void")) self.castForCType(func.return_type) else .none; + try self.writeReturnPrefix(return_cast, zig_return_type); - try self.output.writer(self.allocator).print("c.{s}(", .{func.name}); + try self.output.print(self.allocator, "c.{s}(", .{func.name}); for (func.params, 0..) |param, i| { if (i > 0) try self.output.appendSlice(self.allocator, ", "); if (param.name.len > 0) { - const zig_param_type = try self.convertFunctionParamType(func, param); - defer self.allocator.free(zig_param_type); - const param_cast = self.getFunctionParamCastType(param, zig_param_type); - - if (param_cast == .none) { - try self.output.writer(self.allocator).print("{s}", .{param.name}); - } else { - try self.output.writer(self.allocator).print("{s}({s})", .{ castTypeToString(param_cast), param.name }); - } + try self.writeCallArg(param.name, param.type_name); } } - if (return_cast != .none) { - try self.output.appendSlice(self.allocator, "));\n"); - } else { - try self.output.appendSlice(self.allocator, ");\n"); - } + try self.output.appendSlice(self.allocator, ")"); + try self.output.appendSlice(self.allocator, return_cast.returnSuffix()); + try self.output.appendSlice(self.allocator, ";\n"); try self.output.appendSlice(self.allocator, "}\n\n"); } @@ -694,11 +760,78 @@ pub const CodeGen = struct { return zig_type; } - fn getFunctionParamCastType(self: *CodeGen, param: patterns.ParamDecl, zig_param_type: []const u8) types.CastType { - if (self.isSDLPointerArrayParam(param.type_name)) { - return .ptr_cast; + fn writeCallArg(self: *CodeGen, name: []const u8, c_type: []const u8) !void { + switch (self.castForCType(c_type)) { + .none => try self.output.appendSlice(self.allocator, name), + .ptr => try self.output.print(self.allocator, "@ptrCast(@alignCast({s}))", .{name}), + .bit => try self.output.print(self.allocator, "@bitCast({s})", .{name}), + .enumeration => try self.output.print(self.allocator, "@intCast(@backingInt({s}))", .{name}), + .aggregate => try self.output.print(self.allocator, "@as(*const c.{s}, @ptrCast(@alignCast(&{s}))).*", .{ + std.mem.trim(u8, c_type, " \t"), + name, + }), } - return types.getParamCastType(zig_param_type); + } + + fn writeReturnPrefix(self: *CodeGen, cast: Cast, zig_return_type: []const u8) !void { + switch (cast) { + .aggregate => try self.output.print(self.allocator, "@as(*const {s}, @ptrCast(@alignCast(&", .{zig_return_type}), + else => try self.output.appendSlice(self.allocator, cast.returnPrefix()), + } + } + + /// Finds the declaration of an SDL C type (e.g. "SDL_Window") among the + /// primary and dependency declarations of this module. + fn findTypeDecl(self: *CodeGen, c_name: []const u8) ?patterns.Declaration { + for (self.decls) |resolved| { + const name = resolved.typeName() orelse continue; + if (std.mem.eql(u8, name, c_name)) return resolved.decl; + } + return null; + } + + /// Determines how a value of the given C type has to be converted when it + /// crosses between the generated Zig API and the translated C API. The + /// decision is based on how the type is declared rather than on its name. + fn castForCType(self: *CodeGen, c_type: []const u8) Cast { + return self.castForCTypeDepth(c_type, 0); + } + + fn castForCTypeDepth(self: *CodeGen, c_type: []const u8, depth: u32) Cast { + if (depth > 8) return .none; + const trimmed = std.mem.trim(u8, c_type, " \t"); + + // Inline function pointer types are re-declared with Zig types. + if (std.mem.indexOfScalar(u8, trimmed, '(') != null) return .ptr; + if (std.mem.indexOfScalar(u8, trimmed, '[') != null) return .none; + + if (std.mem.indexOfScalar(u8, trimmed, '*')) |first_star| { + var base = std.mem.trim(u8, trimmed[0..first_star], " \t"); + if (std.mem.startsWith(u8, base, "const ")) base = std.mem.trim(u8, base[6..], " \t"); + if (std.mem.endsWith(u8, base, " const")) base = std.mem.trim(u8, base[0 .. base.len - 6], " \t"); + // Pointers to forward declared structs are exposed as `?*anyopaque`. + if (std.mem.startsWith(u8, base, "struct ")) return .ptr; + // SDL uses C bool, but pointers to it are not guaranteed to coerce. + return switch (self.castForCTypeDepth(base, depth + 1)) { + .none => .none, + else => .ptr, + }; + } + + if (std.mem.eql(u8, trimmed, "bool") or std.mem.eql(u8, trimmed, "SDL_bool")) return .bit; + + const decl = self.findTypeDecl(trimmed) orelse return .none; + return switch (decl) { + .opaque_type => .ptr, + .typedef_decl => |typedef_decl| self.castForCTypeDepth(typedef_decl.underlying_type, depth + 1), + .function_pointer_decl => .ptr, + .c_type_alias => .none, + .enum_decl => |enum_decl| if (self.enumShouldBeFlags(enum_decl)) .bit else .enumeration, + .struct_decl => |struct_decl| if (struct_decl.has_unions) .ptr else .aggregate, + .union_decl => .aggregate, + .flag_decl => .bit, + .function_decl => .none, + }; } fn paramMayBeNull(self: *CodeGen, func: patterns.FunctionDecl, param_name: []const u8) bool { @@ -758,36 +891,6 @@ pub const CodeGen = struct { return false; } - fn isSDLPointerArrayParam(self: *CodeGen, c_type: []const u8) bool { - _ = self; - const trimmed = std.mem.trim(u8, c_type, " \t"); - if (std.mem.indexOf(u8, trimmed, "(SDLCALL *") != null or std.mem.indexOf(u8, trimmed, "(*") != null) { - return false; - } - if (std.mem.count(u8, trimmed, "*") < 2) { - return false; - } - - var rest = trimmed; - if (std.mem.startsWith(u8, rest, "const ")) { - rest = std.mem.trim(u8, rest[6..], " \t"); - } - - const first_star = std.mem.indexOfScalar(u8, rest, '*') orelse return false; - const base_type = std.mem.trim(u8, rest[0..first_star], " \t"); - return std.mem.startsWith(u8, base_type, "SDL_"); - } - - fn castTypeToString(cast_type: types.CastType) []const u8 { - return switch (cast_type) { - .none => "none", - .ptr_cast => "@ptrCast", - .bit_cast => "@bitCast", - .int_from_enum => "@intFromEnum", - .enum_from_int => "@enumFromInt", - }; - } - fn writeDocComment(self: *CodeGen, comment: []const u8) !void { _ = self; _ = comment; @@ -986,5 +1089,147 @@ test "opaque methods cast enum params to C ABI" { }); defer allocator.free(output); - try std.testing.expect(std.mem.indexOf(u8, output, "@intFromEnum(index_element_size)") != null); + try std.testing.expect(std.mem.indexOf(u8, output, "@intCast(@backingInt(index_element_size))") != null); +} + +fn testGenerate(allocator: Allocator, decls: []const ResolvedDecl) ![]const u8 { + return CodeGen.generate(allocator, .{ .decls = decls, .module_name = "video", .c_import_path = "c.zig" }); +} + +test "flags are laid out by bit position with padding for gaps" { + const allocator = std.testing.allocator; + + var decls: std.ArrayList(ResolvedDecl) = .empty; + defer { + for (decls.items) |decl| decl.deinit(allocator); + decls.deinit(allocator); + } + + const flags = try allocator.alloc(patterns.FlagValue, 3); + flags[0] = .{ .name = try allocator.dupe(u8, "SDL_WINDOW_FULLSCREEN"), .value = try allocator.dupe(u8, "SDL_UINT64_C(0x0000000000000001)"), .comment = null }; + flags[1] = .{ .name = try allocator.dupe(u8, "SDL_WINDOW_VULKAN"), .value = try allocator.dupe(u8, "SDL_UINT64_C(0x0000000010000000)"), .comment = null }; + flags[2] = .{ .name = try allocator.dupe(u8, "SDL_WINDOW_OPENGL"), .value = try allocator.dupe(u8, "SDL_UINT64_C(0x0000000000000002)"), .comment = null }; + try decls.append(allocator, .{ + .decl = .{ .flag_decl = .{ + .name = try allocator.dupe(u8, "SDL_WindowFlags"), + .underlying_type = try allocator.dupe(u8, "Uint64"), + .flags = flags, + .constants = &.{}, + .doc_comment = null, + } }, + .source_header = try allocator.dupe(u8, "SDL_video.h"), + .is_primary_header_decl = true, + }); + + const output = try testGenerate(allocator, decls.items); + defer allocator.free(output); + + const expected = + \\pub const WindowFlags = packed struct(u64) { + \\ windowFullscreen: bool = false, + \\ windowOpengl: bool = false, + \\ pad0: u26 = 0, + \\ windowVulkan: bool = false, + \\ pad1: u34 = 0, + \\ rsvd: bool = false, + \\ + ; + try std.testing.expect(std.mem.indexOf(u8, output, expected) != null); +} + +test "enum values are numbered like C and duplicates become aliases" { + const allocator = std.testing.allocator; + + var decls: std.ArrayList(ResolvedDecl) = .empty; + defer { + for (decls.items) |decl| decl.deinit(allocator); + decls.deinit(allocator); + } + + const names = [_][]const u8{ "SDL_EVENT_FIRST", "SDL_EVENT_QUIT", "SDL_EVENT_DISPLAY_ADDED", "SDL_EVENT_DISPLAY_FIRST", "SDL_EVENT_DISPLAY_REMOVED" }; + const raw_values = [_]?[]const u8{ "0", "0x100", null, "SDL_EVENT_DISPLAY_ADDED", null }; + const values = try allocator.alloc(patterns.EnumValue, names.len); + for (names, raw_values, 0..) |name, raw, i| { + values[i] = .{ + .name = try allocator.dupe(u8, name), + .value = if (raw) |r| try allocator.dupe(u8, r) else null, + .comment = null, + }; + } + try decls.append(allocator, .{ + .decl = .{ .enum_decl = .{ + .name = try allocator.dupe(u8, "SDL_EventType"), + .values = values, + .doc_comment = null, + } }, + .source_header = try allocator.dupe(u8, "SDL_video.h"), + .is_primary_header_decl = true, + }); + + const output = try testGenerate(allocator, decls.items); + defer allocator.free(output); + + const expected = + \\pub const EventType = enum(c_int) { + \\ eventFirst = 0, + \\ eventQuit = 0x100, + \\ eventDisplayAdded, + \\ eventDisplayRemoved, + \\ + \\ pub const eventDisplayFirst = .eventDisplayAdded; + \\}; + ; + try std.testing.expect(std.mem.indexOf(u8, output, expected) != null); +} + +test "casts follow how a type is declared" { + const allocator = std.testing.allocator; + + var decls: std.ArrayList(ResolvedDecl) = .empty; + defer { + for (decls.items) |decl| decl.deinit(allocator); + decls.deinit(allocator); + } + + try decls.append(allocator, .{ + .decl = .{ .struct_decl = .{ + .name = try allocator.dupe(u8, "SDL_GUID"), + .fields = &.{}, + .doc_comment = null, + .has_unions = false, + } }, + .source_header = try allocator.dupe(u8, "SDL_video.h"), + .is_primary_header_decl = true, + }); + const enum_values = try allocator.alloc(patterns.EnumValue, 1); + enum_values[0] = .{ .name = try allocator.dupe(u8, "SDL_POWERSTATE_UNKNOWN"), .value = null, .comment = null }; + try decls.append(allocator, .{ + .decl = .{ .enum_decl = .{ + .name = try allocator.dupe(u8, "SDL_PowerState"), + .values = enum_values, + .doc_comment = null, + } }, + .source_header = try allocator.dupe(u8, "SDL_video.h"), + .is_primary_header_decl = true, + }); + const params = try allocator.alloc(patterns.ParamDecl, 3); + params[0] = .{ .name = try allocator.dupe(u8, "guid"), .type_name = try allocator.dupe(u8, "SDL_GUID") }; + params[1] = .{ .name = try allocator.dupe(u8, "out"), .type_name = try allocator.dupe(u8, "SDL_GUID *") }; + params[2] = .{ .name = try allocator.dupe(u8, "percent"), .type_name = try allocator.dupe(u8, "int *") }; + try decls.append(allocator, .{ + .decl = .{ .function_decl = .{ + .name = try allocator.dupe(u8, "SDL_Example"), + .return_type = try allocator.dupe(u8, "SDL_PowerState"), + .params = params, + .doc_comment = null, + } }, + .source_header = try allocator.dupe(u8, "SDL_video.h"), + .is_primary_header_decl = true, + }); + + const output = try testGenerate(allocator, decls.items); + defer allocator.free(output); + + const expected = "return @fromBackingInt(@intCast(c.SDL_Example(@as(*const c.SDL_GUID, @ptrCast(@alignCast(&guid))).*, @ptrCast(@alignCast(out)), percent)));"; + try std.testing.expect(std.mem.indexOf(u8, output, expected) != null); } diff --git a/src/dependency_resolver.zig b/src/dependency_resolver.zig index 46588cc..83fab02 100644 --- a/src/dependency_resolver.zig +++ b/src/dependency_resolver.zig @@ -37,7 +37,7 @@ pub const DependencyResolver = struct { } pub fn getMissingTypes(self: *DependencyResolver, allocator: Allocator) ![][]const u8 { - var missing = std.ArrayList([]const u8){}; + var missing = std.ArrayList([]const u8).empty; var it = self.referenced_types.keyIterator(); while (it.next()) |key| { @@ -220,7 +220,7 @@ fn isSDLType(type_str: []const u8) bool { } pub fn parseIncludes(allocator: Allocator, source: []const u8) ![][]const u8 { - var includes = std.ArrayList([]const u8){}; + var includes = std.ArrayList([]const u8).empty; var lines = std.mem.splitScalar(u8, source, '\n'); while (lines.next()) |line| { diff --git a/src/header_cache.zig b/src/header_cache.zig index 6423275..fb2f7f6 100644 --- a/src/header_cache.zig +++ b/src/header_cache.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const patterns = @import("patterns.zig"); +const io = @import("io.zig"); const resolved_decl = @import("resolved_decl.zig"); const Declaration = patterns.Declaration; @@ -70,7 +71,7 @@ pub const HeaderCache = struct { std.debug.print(" Caching types from: {s}\n", .{filename}); - const content = std.fs.cwd().readFileAlloc(self.allocator, full_path, 10_000_000) catch |err| { + const content = io.cwd().readFileAlloc(io.get(), full_path, self.allocator, .limited(10_000_000)) catch |err| { std.debug.print(" Warning: Could not read {s}: {}\n", .{ filename, err }); return; }; diff --git a/src/io.zig b/src/io.zig index 783d6d6..b3058be 100644 --- a/src/io.zig +++ b/src/io.zig @@ -1,14 +1,22 @@ -var stdout_buffer: [1024]u8 = undefined; -var stdout_writer: *std.Io.Writer = undefined; -var stdout_file: std.fs.Writer = undefined; +//! Process-wide I/O context, set once from `main`. +pub const std = @import("std"); -pub fn stdout() *std.Io.Writer { - return stdout_writer; +var global_io: std.Io = undefined; + +pub fn init(new_io: std.Io) void { + global_io = new_io; } -pub fn initWriter() void { - stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); - stdout = &stdout_writer.interface; +pub fn get() std.Io { + return global_io; +} + +pub fn cwd() std.Io.Dir { + return std.Io.Dir.cwd(); +} + +pub fn writeStdout(bytes: []const u8) !void { + try std.Io.File.stdout().writeStreamingAll(global_io, bytes); } pub fn emitError(src: std.builtin.SourceLocation, errorMessage: []const u8) void { @@ -16,9 +24,6 @@ pub fn emitError(src: std.builtin.SourceLocation, errorMessage: []const u8) void std.debug.print("in {s}:{d} module: {s}", .{ src.file, src.line, src.module }); std.debug.print("function: {s}", .{src.fn_name}); std.debug.print("message: '{s}'", .{errorMessage}); - std.debug.dumpCurrentStackTrace(null); + std.debug.dumpCurrentStackTrace(.{}); std.debug.print("---- /Error occured -----\n", .{}); } - -pub const std = @import("std"); -const buildOptions = @import("buildOptions"); diff --git a/src/json_serializer.zig b/src/json_serializer.zig index 103e57d..bbc0608 100644 --- a/src/json_serializer.zig +++ b/src/json_serializer.zig @@ -18,17 +18,17 @@ pub const JsonSerializer = struct { pub fn init(allocator: std.mem.Allocator, header_name: []const u8) JsonSerializer { return .{ .allocator = allocator, - .output = .{}, + .output = .empty, .header_name = header_name, - .opaque_types = .{}, - .typedefs = .{}, - .function_pointers = .{}, - .c_type_aliases = .{}, - .enums = .{}, - .structs = .{}, - .unions = .{}, - .flags = .{}, - .functions = .{}, + .opaque_types = .empty, + .typedefs = .empty, + .function_pointers = .empty, + .c_type_aliases = .empty, + .enums = .empty, + .structs = .empty, + .unions = .empty, + .flags = .empty, + .functions = .empty, }; } @@ -62,7 +62,9 @@ pub const JsonSerializer = struct { } pub fn finalize(self: *JsonSerializer) ![]const u8 { - var writer = self.output.writer(self.allocator); + var allocating: std.Io.Writer.Allocating = .fromArrayList(self.allocator, &self.output); + errdefer self.output = allocating.toArrayList(); + const writer = &allocating.writer; try writer.writeAll("{\n"); try writer.writeAll(" \"header\": "); @@ -161,6 +163,7 @@ pub const JsonSerializer = struct { try writer.writeAll("}\n"); + self.output = allocating.toArrayList(); return self.output.items; } @@ -222,7 +225,7 @@ pub const JsonSerializer = struct { try writer.writeAll("{\"name\": "); try self.writeString(writer, enum_decl.name); try writer.writeAll(", \"values\": ["); - + for (enum_decl.values, 0..) |value, i| { try writer.writeAll("{\"name\": "); try self.writeString(writer, value.name); @@ -237,7 +240,7 @@ pub const JsonSerializer = struct { try writer.writeAll("}"); if (i < enum_decl.values.len - 1) try writer.writeAll(", "); } - + try writer.writeAll("]"); if (enum_decl.doc_comment) |doc| { try writer.writeAll(", \"doc\": "); @@ -279,7 +282,7 @@ pub const JsonSerializer = struct { try writer.writeAll("{\"name\": "); try self.writeString(writer, union_decl.name); try writer.writeAll(", \"fields\": ["); - + for (union_decl.fields, 0..) |field, i| { try writer.writeAll("{\"name\": "); try self.writeString(writer, field.name); @@ -292,7 +295,7 @@ pub const JsonSerializer = struct { try writer.writeAll("}"); if (i < union_decl.fields.len - 1) try writer.writeAll(", "); } - + try writer.writeAll("]"); if (union_decl.doc_comment) |doc| { try writer.writeAll(", \"doc\": "); @@ -307,7 +310,7 @@ pub const JsonSerializer = struct { try writer.writeAll(", \"underlying_type\": "); try self.writeString(writer, flag.underlying_type); try writer.writeAll(", \"values\": ["); - + for (flag.flags, 0..) |value, i| { try writer.writeAll("{\"name\": "); try self.writeString(writer, value.name); @@ -320,7 +323,7 @@ pub const JsonSerializer = struct { try writer.writeAll("}"); if (i < flag.flags.len - 1) try writer.writeAll(", "); } - + try writer.writeAll("]"); if (flag.doc_comment) |doc| { try writer.writeAll(", \"doc\": "); @@ -335,7 +338,7 @@ pub const JsonSerializer = struct { try writer.writeAll(", \"return_type\": "); try self.writeString(writer, func.return_type); try writer.writeAll(", \"parameters\": ["); - + for (func.params, 0..) |param, i| { try writer.writeAll("{\"name\": "); try self.writeString(writer, param.name); @@ -344,7 +347,7 @@ pub const JsonSerializer = struct { try writer.writeAll("}"); if (i < func.params.len - 1) try writer.writeAll(", "); } - + try writer.writeAll("]"); if (func.doc_comment) |doc| { try writer.writeAll(", \"doc\": "); diff --git a/src/mock_codegen.zig b/src/mock_codegen.zig index fc8337d..3dc1fe2 100644 --- a/src/mock_codegen.zig +++ b/src/mock_codegen.zig @@ -41,7 +41,7 @@ pub const MockCodeGen = struct { fn writeFunctionMocks(self: *MockCodeGen) !void { var has_functions = false; - + for (self.decls) |decl| { if (decl == .function_decl) { if (!has_functions) { @@ -54,11 +54,13 @@ pub const MockCodeGen = struct { } fn writeFunctionMock(self: *MockCodeGen, func: patterns.FunctionDecl) !void { - const writer = self.output.writer(self.allocator); - + var allocating: std.Io.Writer.Allocating = .fromArrayList(self.allocator, &self.output); + defer self.output = allocating.toArrayList(); + const writer = &allocating.writer; + // Write return type and function name try writer.print("{s} {s}(", .{ func.return_type, func.name }); - + // Write parameters if (func.params.len == 0) { try writer.writeAll("void"); @@ -73,42 +75,42 @@ pub const MockCodeGen = struct { } } } - + try writer.writeAll(") {\n"); - + // Void all parameters to avoid unused warnings for (func.params) |param| { if (param.name.len > 0) { try writer.print(" (void){s};\n", .{param.name}); } } - + // Return appropriate default value const return_value = getDefaultReturnValue(func.return_type); if (return_value.len > 0) { try writer.print(" return {s};\n", .{return_value}); } - + try writer.writeAll("}\n\n"); } fn getDefaultReturnValue(return_type: []const u8) []const u8 { const trimmed = std.mem.trim(u8, return_type, " \t"); - + if (std.mem.eql(u8, trimmed, "void")) { return ""; } - + // Check for pointer types if (std.mem.indexOf(u8, trimmed, "*") != null) { return "NULL"; } - + // Check for bool if (std.mem.eql(u8, trimmed, "bool") or std.mem.eql(u8, trimmed, "SDL_bool")) { return "false"; } - + // Check for integer types if (std.mem.indexOf(u8, trimmed, "int") != null or std.mem.startsWith(u8, trimmed, "Uint") or @@ -117,12 +119,12 @@ pub const MockCodeGen = struct { { return "0"; } - + // Check for float types if (std.mem.eql(u8, trimmed, "float") or std.mem.eql(u8, trimmed, "double")) { return "0.0"; } - + // For enum/struct types, return zero return "0"; } diff --git a/src/mock_codegen_test.zig b/src/mock_codegen_test.zig index 9017b1a..5fd2134 100644 --- a/src/mock_codegen_test.zig +++ b/src/mock_codegen_test.zig @@ -24,7 +24,7 @@ test "mock generation - simple function" { }); const output = try mock_codegen.MockCodeGen.generate(allocator, decls); - + // Should contain function declaration try testing.expect(std.mem.indexOf(u8, output, "SDL_CreateGPUDevice") != null); // Should contain parameter @@ -56,14 +56,14 @@ test "mock generation - void function" { }); const output = try mock_codegen.MockCodeGen.generate(allocator, decls); - + // Should not have return statement for void try testing.expect(std.mem.indexOf(u8, output, "return") == null); // Should void the parameter try testing.expect(std.mem.indexOf(u8, output, "(void)device") != null); } -test "mock generation - opaque type forward declaration" { +test "mock generation - opaque types are not redeclared" { var arena = std.heap.ArenaAllocator.init(testing.allocator); defer arena.deinit(); const allocator = arena.allocator(); @@ -78,9 +78,9 @@ test "mock generation - opaque type forward declaration" { }); const output = try mock_codegen.MockCodeGen.generate(allocator, decls); - - // Should have typedef struct - try testing.expect(std.mem.indexOf(u8, output, "typedef struct SDL_GPUDevice SDL_GPUDevice") != null); + + // Opaque types come from the SDL headers and must not be redeclared + try testing.expect(std.mem.indexOf(u8, output, "typedef struct SDL_GPUDevice") == null); } test "mock generation - header and includes" { @@ -90,10 +90,9 @@ test "mock generation - header and includes" { const decls = try allocator.dupe(patterns.Declaration, &[_]patterns.Declaration{}); const output = try mock_codegen.MockCodeGen.generate(allocator, decls); - - // Should have standard headers - try testing.expect(std.mem.indexOf(u8, output, "#include ") != null); - try testing.expect(std.mem.indexOf(u8, output, "#include ") != null); + + // Types are provided by the SDL headers + try testing.expect(std.mem.indexOf(u8, output, "#include ") != null); // Should have auto-generated comment try testing.expect(std.mem.indexOf(u8, output, "Auto-generated") != null); } @@ -120,7 +119,7 @@ test "mock generation - function with multiple parameters" { }); const output = try mock_codegen.MockCodeGen.generate(allocator, decls); - + // Should have both parameters try testing.expect(std.mem.indexOf(u8, output, "render_pass") != null); try testing.expect(std.mem.indexOf(u8, output, "viewport") != null); @@ -150,7 +149,7 @@ test "mock generation - function returning bool" { }); const output = try mock_codegen.MockCodeGen.generate(allocator, decls); - + // Should return false for bool try testing.expect(std.mem.indexOf(u8, output, "return false") != null); } @@ -174,7 +173,7 @@ test "mock generation - function returning int" { }); const output = try mock_codegen.MockCodeGen.generate(allocator, decls); - + // Should return 0 for int try testing.expect(std.mem.indexOf(u8, output, "return 0") != null); } diff --git a/src/parser.zig b/src/parser.zig index e3abd22..a1194d4 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -14,14 +14,14 @@ pub fn freeDecls(allocator: std.mem.Allocator, decls: []patterns.Declaration) vo allocator.free(decls); } -pub fn main() !void { +pub fn main(init: std.process.Init) !void { const allocator = std.heap.smp_allocator; + io.init(init.io); - const args = try std.process.argsAlloc(allocator); - defer std.process.argsFree(allocator, args); + const args = try init.minimal.args.toSlice(init.arena.allocator()); if (args.len < 2) { - std.debug.print("Usage: {s} [--output=] [--mocks=] [--generate-json=] [--timestamp=] [--basedir=]\n", .{args[0]}); + std.debug.print("Usage: {s} [--output=] [--mocks=] [--generate-json=] [--timestamp=] [--basedir=] [--c-import=] [--skip-missing]\n", .{args[0]}); std.debug.print("Example: {s} ../SDL/include/SDL3/SDL_gpu.h --output=gpu.zig\n", .{args[0]}); std.debug.print(" {s} ../SDL/include/SDL3/SDL_gpu.h --output=gpu.zig --mocks=gpu_mock.c\n", .{args[0]}); std.debug.print(" {s} ../SDL/include/SDL3/SDL_gpu.h --generate-json=gpu.json\n", .{args[0]}); @@ -30,7 +30,7 @@ pub fn main() !void { return error.MissingArgument; } - const header_path = args[1]; + var header_path: []const u8 = args[1]; var output_file: ?[]const u8 = null; var mock_output_file: ?[]const u8 = null; @@ -38,6 +38,7 @@ pub fn main() !void { var timestamp: ?i64 = null; var basedir: ?[]const u8 = null; var c_import_path: []const u8 = "c.zig"; + var skip_missing = false; // Parse additional flags for (args[2..]) |arg| { @@ -59,16 +60,27 @@ pub fn main() !void { basedir = arg[basedir_prefix.len..]; } else if (std.mem.startsWith(u8, arg, c_import_prefix)) { c_import_path = arg[c_import_prefix.len..]; + } else if (std.mem.eql(u8, arg, "--skip-missing")) { + skip_missing = true; } else { std.debug.print("Error: Unknown argument '{s}'\n", .{arg}); - std.debug.print("Usage: {s} [--output=] [--mocks=] [--generate-json=] [--timestamp=] [--basedir=]\n", .{args[0]}); + std.debug.print("Usage: {s} [--output=] [--mocks=] [--generate-json=] [--timestamp=] [--basedir=] [--c-import=] [--skip-missing]\n", .{args[0]}); return error.InvalidArgument; } } - // Change working directory if --basedir is specified + // Change working directory if --basedir is specified. The base directory + // only decides where tmp/, debug/ and archive/ end up: input and output + // paths keep referring to the directory the parser was started from. if (basedir) |dir| { - try std.posix.chdir(dir); + const arena = init.arena.allocator(); + const original_cwd = try std.process.currentPathAlloc(io.get(), arena); + header_path = try std.fs.path.resolve(arena, &.{ original_cwd, header_path }); + if (output_file) |path| output_file = try std.fs.path.resolve(arena, &.{ original_cwd, path }); + if (mock_output_file) |path| mock_output_file = try std.fs.path.resolve(arena, &.{ original_cwd, path }); + if (json_output_file) |path| json_output_file = try std.fs.path.resolve(arena, &.{ original_cwd, path }); + + try std.process.setCurrentPath(io.get(), dir); std.debug.print("Changed working directory to: {s}\n\n", .{dir}); } @@ -80,7 +92,14 @@ pub fn main() !void { std.debug.print("Parsing: {s}\n\n", .{header_path}); // Read the header file - const source = try std.fs.cwd().readFileAlloc(allocator, header_path, 10 * 1024 * 1024); // 10MB max + const source = io.cwd().readFileAlloc(io.get(), header_path, allocator, .limited(10 * 1024 * 1024)) catch |err| switch (err) { + // Not every SDL release ships every header (e.g. SDL_tray.h is newer). + error.FileNotFound => if (skip_missing) { + std.debug.print("Skipping {s}: header does not exist in this SDL version\n", .{header_path}); + return; + } else return err, + else => return err, + }; // 10MB max defer allocator.free(source); // Parse declarations @@ -150,16 +169,14 @@ pub fn main() !void { const parsed = try std.json.parseFromSlice(std.json.Value, allocator, json_output, .{}); defer parsed.deinit(); - var formatted_output: std.ArrayList(u8) = .empty; - defer formatted_output.deinit(allocator); - const formatter = std.json.fmt(parsed.value, .{ .whitespace = .indent_2 }); - try std.fmt.format(formatted_output.writer(allocator), "{f}", .{formatter}); + const formatted_output = try std.fmt.allocPrint(allocator, "{f}", .{formatter}); + defer allocator.free(formatted_output); try ensureParentDirExists(json_path); - try std.fs.cwd().writeFile(.{ + try io.cwd().writeFile(io.get(), .{ .sub_path = json_path, - .data = formatted_output.items, + .data = formatted_output, }); serializer.deinit(); std.debug.print("Generated JSON: {s}\n", .{json_path}); @@ -297,10 +314,10 @@ pub fn main() !void { defer allocator.free(output); // Parse and format the AST for validation - const output_z = try allocator.dupeZ(u8, output); + const output_z = try allocator.dupeSentinel(u8, output, 0); defer allocator.free(output_z); - var ast = try std.zig.Ast.parse(allocator, output_z, .zig); + var ast = try std.zig.Ast.parse(allocator, output_z, .{}); defer ast.deinit(allocator); // Check for parse errors @@ -317,7 +334,7 @@ pub fn main() !void { // Write unformatted output for debugging if (output_file) |file_path| { - try std.fs.cwd().writeFile(.{ + try io.cwd().writeFile(io.get(), .{ .sub_path = file_path, .data = output, }); @@ -339,7 +356,7 @@ pub fn main() !void { if (output_file) |file_path| { try writeZigFileWithFmt(allocator, header_path, file_path, formatted_output); } else { - _ = try io.stdout().write(formatted_output); + try io.writeStdout(formatted_output); } // Generate C mocks if requested (with flat declarations) @@ -361,7 +378,7 @@ pub fn main() !void { defer allocator.free(mock_output); try ensureParentDirExists(mock_path); - try std.fs.cwd().writeFile(.{ + try io.cwd().writeFile(io.get(), .{ .sub_path = mock_path, .data = mock_output, }); @@ -374,7 +391,7 @@ fn writeZigFileWithFmt(allocator: std.mem.Allocator, header_path: []const u8, ou const output_basename = std.fs.path.basename(output_path); // Create tmp directory - std.fs.cwd().makePath("tmp") catch |err| switch (err) { + io.cwd().createDirPath(io.get(), "tmp") catch |err| switch (err) { error.PathAlreadyExists => {}, else => return err, }; @@ -383,20 +400,21 @@ fn writeZigFileWithFmt(allocator: std.mem.Allocator, header_path: []const u8, ou const tmp_path = try std.fmt.allocPrint(allocator, "tmp/{s}", .{output_basename}); defer allocator.free(tmp_path); - try std.fs.cwd().writeFile(.{ + try io.cwd().writeFile(io.get(), .{ .sub_path = tmp_path, .data = content, }); // Run zig ast-check on tmp file - var ast_check = std.process.Child.init(&.{ "zig", "ast-check", tmp_path }, allocator); - ast_check.stderr_behavior = .Pipe; - try ast_check.spawn(); - const ast_result = try ast_check.wait(); + var ast_check = try std.process.spawn(io.get(), .{ + .argv = &.{ "zig", "ast-check", tmp_path }, + .stderr = .ignore, + }); + const ast_result = try ast_check.wait(io.get()); - if (ast_result.Exited != 0) { + if (!ast_result.success()) { // zig ast-check failed - copy to debug folder - std.fs.cwd().makePath("debug") catch |err| switch (err) { + io.cwd().createDirPath(io.get(), "debug") catch |err| switch (err) { error.PathAlreadyExists => {}, else => return err, }; @@ -411,7 +429,7 @@ fn writeZigFileWithFmt(allocator: std.mem.Allocator, header_path: []const u8, ou const debug_path = try std.fmt.allocPrint(allocator, "debug/{s}_fmterror.zig", .{safe_name}); defer allocator.free(debug_path); - try std.fs.cwd().writeFile(.{ + try io.cwd().writeFile(io.get(), .{ .sub_path = debug_path, .data = content, }); @@ -420,18 +438,19 @@ fn writeZigFileWithFmt(allocator: std.mem.Allocator, header_path: []const u8, ou } // Run zig fmt on tmp file - var fmt = std.process.Child.init(&.{ "zig", "fmt", tmp_path }, allocator); - fmt.stderr_behavior = .Pipe; - try fmt.spawn(); - _ = try fmt.wait(); + var fmt = try std.process.spawn(io.get(), .{ + .argv = &.{ "zig", "fmt", tmp_path }, + .stderr = .ignore, + }); + _ = try fmt.wait(io.get()); // Copy formatted file to final destination try ensureParentDirExists(output_path); - const formatted_content = try std.fs.cwd().readFileAlloc(allocator, tmp_path, 10 * 1024 * 1024); + const formatted_content = try io.cwd().readFileAlloc(io.get(), tmp_path, allocator, .limited(10 * 1024 * 1024)); defer allocator.free(formatted_content); - try std.fs.cwd().writeFile(.{ + try io.cwd().writeFile(io.get(), .{ .sub_path = output_path, .data = formatted_content, }); @@ -440,7 +459,7 @@ fn writeZigFileWithFmt(allocator: std.mem.Allocator, header_path: []const u8, ou fn ensureParentDirExists(path: []const u8) !void { if (std.fs.path.dirname(path)) |dir| { - std.fs.cwd().makePath(dir) catch |err| switch (err) { + io.cwd().createDirPath(io.get(), dir) catch |err| switch (err) { error.PathAlreadyExists => {}, else => return err, }; @@ -449,19 +468,19 @@ fn ensureParentDirExists(path: []const u8) !void { fn archiveExistingDebugDir(allocator: std.mem.Allocator, provided_timestamp: ?i64) void { // Check if debug/ directory exists - var debug_dir = std.fs.cwd().openDir("debug", .{}) catch return; - debug_dir.close(); + var debug_dir = io.cwd().openDir(io.get(), "debug", .{}) catch return; + debug_dir.close(io.get()); // Use provided timestamp or generate one - const timestamp = provided_timestamp orelse std.time.timestamp(); + const timestamp = provided_timestamp orelse std.Io.Clock.real.now(io.get()).toSeconds(); const archive_path = std.fmt.allocPrint(allocator, "archive/debug/{d}", .{timestamp}) catch return; defer allocator.free(archive_path); // Create archive/debug directory if needed - std.fs.cwd().makePath("archive/debug") catch return; + io.cwd().createDirPath(io.get(), "archive/debug") catch return; // Move debug/ to archive/debug// - std.fs.cwd().rename("debug", archive_path) catch |err| { + io.cwd().rename("debug", io.cwd(), archive_path, io.get()) catch |err| { std.debug.print("Warning: Failed to archive existing debug dir: {}\n", .{err}); return; }; @@ -484,12 +503,12 @@ fn writeDebugFile(allocator: std.mem.Allocator, header_path: []const u8, output: defer allocator.free(debug_filename); // Create debug directory if it doesn't exist - std.fs.cwd().makeDir("debug") catch |err| switch (err) { + io.cwd().createDir(io.get(), "debug", .default_dir) catch |err| switch (err) { error.PathAlreadyExists => {}, else => return err, }; - try std.fs.cwd().writeFile(.{ + try io.cwd().writeFile(io.get(), .{ .sub_path = debug_filename, .data = output, }); @@ -502,6 +521,15 @@ fn freeDeclDeep(allocator: std.mem.Allocator, decl: patterns.Declaration) void { } } -test "basic test" { - try std.testing.expect(true); +test { + // Pull in the tests of every module. + _ = patterns; + _ = codegen; + _ = dependency_resolver; + _ = json_serializer; + _ = header_cache; + _ = resolved_decl; + _ = @import("types.zig"); + _ = @import("naming.zig"); + _ = @import("mock_codegen_test.zig"); } diff --git a/src/patterns.zig b/src/patterns.zig index 381b827..402d8fc 100644 --- a/src/patterns.zig +++ b/src/patterns.zig @@ -316,7 +316,7 @@ pub const Scanner = struct { return false; } - const macro_name = define_name[0 .. std.mem.indexOfScalar(u8, define_name, '(').?]; + const macro_name = define_name[0..std.mem.indexOfScalar(u8, define_name, '(').?]; try self.recordSkippedDecl(macro_name, "function-like macro is not emitted"); if (self.pending_doc_comment) |comment| { @@ -357,7 +357,7 @@ pub const Scanner = struct { // Check they match and end with semicolon // Or accept mismatched names as long as we have a semicolon (e.g., typedef struct tagMSG MSG;) // But reject pointer typedefs (e.g., typedef struct X *Y;) - those should be handled by scanTypedef - const name2_clean = std.mem.trimRight(u8, name2, ";"); + const name2_clean = std.mem.trimEnd(u8, name2, ";"); // Check if it's a pointer typedef - if either name starts with *, reject it if (std.mem.startsWith(u8, name1, "*") or std.mem.startsWith(u8, name2_clean, "*")) { @@ -493,7 +493,7 @@ pub const Scanner = struct { // Parse: typedef Type Name; or typedef struct X *Name; const trimmed = std.mem.trim(u8, line, " \t\r\n"); - const no_semi = std.mem.trimRight(u8, trimmed, ";"); + const no_semi = std.mem.trimEnd(u8, trimmed, ";"); // Find the last token as the name var tokens = std.mem.tokenizeScalar(u8, no_semi, ' '); @@ -558,17 +558,6 @@ pub const Scanner = struct { }; } - fn countChar(need: u8, haystack: []const u8) u32 { - var i: u32 = 0; - for (haystack) |h| { - if (h == need) { - i += 1; - } - } - return i; - } - - // Pattern: typedef enum SDL_Foo { ... } SDL_Foo; fn scanEnum(self: *Scanner) !?EnumDecl { const start = self.pos; @@ -606,127 +595,205 @@ pub const Scanner = struct { const body = try self.readBracedBlock(); defer self.allocator.free(body); - // Parse enum values from body - var values = try std.ArrayList(EnumValue).initCapacity(self.allocator, 20); - var seen_names = std.StringHashMap(void).init(self.allocator); - defer { - var it = seen_names.keyIterator(); - while (it.next()) |key| { - self.allocator.free(key.*); - } - seen_names.deinit(); - } - - var lines = std.mem.splitScalar(u8, body, '\n'); - var in_multiline_comment = false; - - while (lines.next()) |line| { - var trimmed = std.mem.trim(u8, line, " \t\r"); - if (trimmed.len == 0) continue; - - if (in_multiline_comment) { - if (std.mem.indexOf(u8, trimmed, "*/")) |x| { - in_multiline_comment = false; - if (trimmed.len == 2) - continue; - trimmed = trimmed[x + 2 ..]; - } - } - - // Track multi-line comments (both /** and /* styles) - if (std.mem.indexOf(u8, trimmed, "/*")) |_| { - in_multiline_comment = true; - } - - if (in_multiline_comment) { - if (std.mem.indexOf(u8, trimmed, "*/")) |_| { - in_multiline_comment = false; - } - } - if (std.mem.indexOf(u8, trimmed, "/*")) |x| { - if (x == 0) { - continue; - } - } - - // special case for those weirder multiline comments - if (std.mem.indexOf(u8, trimmed, "/*") == null and std.mem.indexOf(u8, trimmed, "*/") == null) { - if (countChar(' ', trimmed) > 0) { - continue; - } - } - - // Skip various comment/bracket/preprocessor lines - if (std.mem.startsWith(u8, trimmed, "//")) continue; - if (std.mem.startsWith(u8, trimmed, "*")) continue; // Lines inside comments - if (std.mem.startsWith(u8, trimmed, "#")) continue; // Preprocessor directives - if (std.mem.startsWith(u8, trimmed, "{")) continue; - if (std.mem.startsWith(u8, trimmed, "}")) continue; - - if (try self.parseEnumValue(trimmed)) |value| { - // Check for duplicate names (from #if/#else branches) - if (!seen_names.contains(value.name)) { - const name_copy = try self.allocator.dupe(u8, value.name); - try seen_names.put(name_copy, {}); - try values.append(self.allocator, value); - } else { - // Skip duplicate, free the value - self.allocator.free(value.name); - if (value.value) |v| self.allocator.free(v); - if (value.comment) |c| self.allocator.free(c); - } - } - } - + const values = try self.parseEnumBody(body); const doc = self.consumePendingDocComment(); return EnumDecl{ .name = try self.allocator.dupe(u8, name), - .values = try values.toOwnedSlice(self.allocator), + .values = values, .doc_comment = doc, }; } - fn parseEnumValue(self: *Scanner, line: []const u8) !?EnumValue { - // Format: SDL_GPU_PRIMITIVETYPE_TRIANGLELIST, /**< comment */ - // or: SDL_GPU_PRIMITIVETYPE_TRIANGLELIST = 5, /**< comment */ - // or: SDL_GPU_PRIMITIVETYPE_POINTLIST /**< comment */ (last value, no comma) + /// Parses the enumerators of an enum body (`{ A, B = 2, ... } SDL_Name;`). + /// + /// Works on the token level rather than line by line so that enumerators + /// are found regardless of how comments and values are laid out: + /// - `/**< ... */` comments (possibly spanning lines) document the + /// enumerator they follow, all other comments are ignored + /// - enumerators are separated by commas outside of parentheses + /// - preprocessor conditionals keep every branch (duplicates are dropped), + /// except byte order checks where the little endian branch is used + fn parseEnumBody(self: *Scanner, body: []const u8) ![]EnumValue { + const open = std.mem.indexOfScalar(u8, body, '{') orelse return &.{}; + const close = std.mem.lastIndexOfScalar(u8, body, '}') orelse body.len; + const text = body[open + 1 .. close]; - var parts = std.mem.splitScalar(u8, line, ','); - const first = std.mem.trim(u8, parts.next() orelse return null, " \t"); - if (first.len == 0) return null; - - // Extract inline comment if present (check both before and after comma) - var comment: ?[]const u8 = null; - const comment_search = if (parts.rest().len > 0) parts.rest() else first; - if (std.mem.indexOf(u8, comment_search, "/**<")) |start| { - if (std.mem.indexOf(u8, comment_search[start..], "*/")) |end_offset| { - const comment_text = comment_search[start + 4 .. start + end_offset]; - comment = try self.allocator.dupe(u8, std.mem.trim(u8, comment_text, " \t")); + var values: std.ArrayList(EnumValue) = .empty; + errdefer { + for (values.items) |value| { + self.allocator.free(value.name); + if (value.value) |v| self.allocator.free(v); + if (value.comment) |c| self.allocator.free(c); } + values.deinit(self.allocator); + } + var seen_names = std.StringHashMap(void).init(self.allocator); + defer seen_names.deinit(); + + var current: std.ArrayList(u8) = .empty; + defer current.deinit(self.allocator); + + // Index into `values` of the enumerator a trailing comment belongs to. + var last_index: ?usize = null; + var pending_comment: ?[]const u8 = null; + defer if (pending_comment) |c| self.allocator.free(c); + + // Stack of preprocessor conditionals; `true` means "skip this branch". + const Conditional = struct { is_byte_order: bool, skipping: bool }; + var conditionals: std.ArrayList(Conditional) = .empty; + defer conditionals.deinit(self.allocator); + + var paren_depth: usize = 0; + var at_line_start = true; + var i: usize = 0; + while (i < text.len) { + const ch = text[i]; + const skipping = for (conditionals.items) |cond| { + if (cond.skipping) break true; + } else false; + + // Preprocessor directive + if (at_line_start and ch == '#') { + var end = i; + while (end < text.len and text[end] != '\n') : (end += 1) { + if (text[end] == '\\' and end + 1 < text.len and text[end + 1] == '\n') end += 1; + } + const directive = std.mem.trim(u8, text[i + 1 .. end], " \t\r"); + // A branch may end without a trailing comma. + if (!skipping) { + last_index = try self.finishEnumValue(&values, &seen_names, current.items, &pending_comment) orelse last_index; + } + current.clearRetainingCapacity(); + if (std.mem.startsWith(u8, directive, "if")) { + const big_endian = std.mem.indexOf(u8, directive, "SDL_BIG_ENDIAN") != null; + const little_endian = std.mem.indexOf(u8, directive, "SDL_LIL_ENDIAN") != null; + try conditionals.append(self.allocator, .{ .is_byte_order = big_endian or little_endian, .skipping = big_endian }); + } else if (std.mem.startsWith(u8, directive, "el")) { + if (conditionals.items.len > 0) { + const cond = &conditionals.items[conditionals.items.len - 1]; + if (cond.is_byte_order) cond.skipping = !cond.skipping; + } + } else if (std.mem.startsWith(u8, directive, "endif")) { + if (conditionals.items.len > 0) _ = conditionals.pop(); + } + i = end; + continue; + } + + // Comments + if (ch == '/' and i + 1 < text.len and text[i + 1] == '*') { + const end = if (std.mem.indexOfPos(u8, text, i + 2, "*/")) |e| e else text.len; + if (!skipping and std.mem.startsWith(u8, text[i..], "/**<")) { + const comment = try collapseComment(self.allocator, text[i + 4 .. end]); + const has_pending_entry = std.mem.trim(u8, current.items, " \t\r\n").len > 0; + if (has_pending_entry) { + if (pending_comment) |old| self.allocator.free(old); + pending_comment = comment; + } else if (last_index) |index| { + if (values.items[index].comment == null) { + values.items[index].comment = comment; + } else { + self.allocator.free(comment); + } + } else { + self.allocator.free(comment); + } + } + i = @min(end + 2, text.len); + continue; + } + if (ch == '/' and i + 1 < text.len and text[i + 1] == '/') { + while (i < text.len and text[i] != '\n') i += 1; + continue; + } + + if (ch == '\n') { + at_line_start = true; + } else if (ch != ' ' and ch != '\t' and ch != '\r') { + at_line_start = false; + } + + if (skipping) { + i += 1; + continue; + } + + if (ch == '(') paren_depth += 1; + if (ch == ')' and paren_depth > 0) paren_depth -= 1; + + if (ch == ',' and paren_depth == 0) { + last_index = try self.finishEnumValue(&values, &seen_names, current.items, &pending_comment) orelse last_index; + current.clearRetainingCapacity(); + } else { + try current.append(self.allocator, if (ch == '\n' or ch == '\r' or ch == '\t') ' ' else ch); + } + i += 1; + } + _ = try self.finishEnumValue(&values, &seen_names, current.items, &pending_comment); + + return try values.toOwnedSlice(self.allocator); + } + + /// Adds the enumerator described by `text` (`NAME` or `NAME = value`) to + /// `values` and returns its index, or null if there was nothing to add. + fn finishEnumValue( + self: *Scanner, + values: *std.ArrayList(EnumValue), + seen_names: *std.StringHashMap(void), + text: []const u8, + pending_comment: *?[]const u8, + ) !?usize { + const comment = pending_comment.*; + pending_comment.* = null; + errdefer if (comment) |c| self.allocator.free(c); + + const entry = std.mem.trim(u8, text, " \t\r\n"); + var name = entry; + var value_text: ?[]const u8 = null; + if (std.mem.indexOfScalar(u8, entry, '=')) |eq_pos| { + name = std.mem.trim(u8, entry[0..eq_pos], " \t"); + value_text = std.mem.trim(u8, entry[eq_pos + 1 ..], " \t"); } - // Extract name and optional value (strip comment if it was in first part) - var name_part = first; - if (std.mem.indexOf(u8, first, "/**<")) |comment_pos| { - name_part = std.mem.trim(u8, first[0..comment_pos], " \t"); + const valid_name = name.len > 0 and for (name) |c| { + if (!std.ascii.isAlphanumeric(c) and c != '_') break false; + } else true; + + // Duplicates come from #if/#else branches that are both kept. + if (!valid_name or seen_names.contains(name)) { + if (comment) |c| self.allocator.free(c); + return null; } - var name: []const u8 = undefined; - var value: ?[]const u8 = null; + const owned_name = fixupZigName(name); + errdefer self.allocator.free(owned_name); + const owned_value = if (value_text) |v| try self.allocator.dupe(u8, v) else null; + errdefer if (owned_value) |v| self.allocator.free(v); - if (std.mem.indexOf(u8, name_part, "=")) |eq_pos| { - name = std.mem.trim(u8, name_part[0..eq_pos], " \t"); - value = try self.allocator.dupe(u8, std.mem.trim(u8, name_part[eq_pos + 1 ..], " \t")); - } else { - name = name_part; - } - - return EnumValue{ - .name = fixupZigName(name), - .value = value, + try values.append(self.allocator, .{ + .name = owned_name, + .value = owned_value, .comment = comment, - }; + }); + try seen_names.put(owned_name, {}); + return values.items.len - 1; + } + + /// Turns the text of a (possibly multi-line) comment into a single line. + fn collapseComment(allocator: Allocator, text: []const u8) ![]const u8 { + var result: std.ArrayList(u8) = .empty; + errdefer result.deinit(allocator); + + var lines = std.mem.splitScalar(u8, text, '\n'); + while (lines.next()) |line| { + var part = std.mem.trim(u8, line, " \t\r"); + if (std.mem.startsWith(u8, part, "*")) part = std.mem.trim(u8, part[1..], " \t"); + if (part.len == 0) continue; + if (result.items.len > 0) try result.append(allocator, ' '); + try result.appendSlice(allocator, part); + } + return try result.toOwnedSlice(allocator); } // Pattern: typedef struct SDL_Foo { ... } SDL_Foo; @@ -781,6 +848,7 @@ pub const Scanner = struct { while (lines.next()) |line| { const trimmed = std.mem.trim(u8, line, " \t\r"); + var field_line = line; // Track multi-line comments (both /** and /*) // Only start tracking if /* appears without */ on the same line @@ -794,7 +862,10 @@ pub const Scanner = struct { } else { // Found /* without */ - start of multi-line comment in_multiline_comment = true; - continue; + if (start_pos == 0) continue; + // A field followed by a comment that continues on the + // next lines: still parse the field itself. + field_line = trimmed[0..start_pos]; } } } else { @@ -812,11 +883,11 @@ pub const Scanner = struct { if (std.mem.startsWith(u8, trimmed, "#")) continue; // First try single-field parsing - if (try self.parseStructField(line)) |field| { + if (try self.parseStructField(field_line)) |field| { try fields.append(self.allocator, field); } else { // If single-field fails, try multi-field parsing - const multi_fields = try self.parseMultiFieldLine(line); + const multi_fields = try self.parseMultiFieldLine(field_line); if (multi_fields.len > 0) { for (multi_fields) |field| { try fields.append(self.allocator, field); @@ -881,6 +952,7 @@ pub const Scanner = struct { while (lines.next()) |line| { const trimmed = std.mem.trim(u8, line, " \t\r"); + var field_line = line; // Track multi-line comments (both /** and /*) // Only start tracking if /* appears without */ on the same line @@ -894,7 +966,10 @@ pub const Scanner = struct { } else { // Found /* without */ - start of multi-line comment in_multiline_comment = true; - continue; + if (start_pos == 0) continue; + // A field followed by a comment that continues on the + // next lines: still parse the field itself. + field_line = trimmed[0..start_pos]; } } } else { @@ -912,10 +987,10 @@ pub const Scanner = struct { if (std.mem.startsWith(u8, trimmed, "#")) continue; // Reuse struct field parsing since unions have same field syntax - if (try self.parseStructField(line)) |field| { + if (try self.parseStructField(field_line)) |field| { try fields.append(self.allocator, field); } else { - const multi_fields = try self.parseMultiFieldLine(line); + const multi_fields = try self.parseMultiFieldLine(field_line); if (multi_fields.len > 0) { for (multi_fields) |field| { try fields.append(self.allocator, field); @@ -943,7 +1018,7 @@ pub const Scanner = struct { if (std.mem.startsWith(u8, trimmed, "}")) return null; // Skip closing brace and typedef name // Remove trailing semicolon - const no_semi = std.mem.trimRight(u8, trimmed, ";"); + const no_semi = std.mem.trimEnd(u8, trimmed, ";"); // Extract inline comment var comment: ?[]const u8 = null; @@ -951,7 +1026,7 @@ pub const Scanner = struct { var field_part = no_semi; if (std.mem.indexOf(u8, no_semi, "/**<")) |comment_start| { - field_part = std.mem.trimRight(u8, no_semi[0..comment_start], "; \t"); + field_part = std.mem.trimEnd(u8, no_semi[0..comment_start], "; \t"); if (std.mem.indexOf(u8, no_semi[comment_start..], "*/")) |end_offset| { const comment_text = no_semi[comment_start + 4 .. comment_start + end_offset]; comment = try self.allocator.dupe(u8, std.mem.trim(u8, comment_text, " \t")); @@ -1014,7 +1089,7 @@ pub const Scanner = struct { if (std.mem.indexOf(u8, field_trimmed, "[")) |bracket_pos| { // Extract array size and append to type // Pattern: "Uint8 padding[2]" -> parse as type="Uint8[2]" name="padding" - const before_bracket = std.mem.trimRight(u8, field_trimmed[0..bracket_pos], " \t"); + const before_bracket = std.mem.trimEnd(u8, field_trimmed[0..bracket_pos], " \t"); const bracket_part = field_trimmed[bracket_pos..]; // "[2]" // Split before_bracket into type and name @@ -1042,8 +1117,7 @@ pub const Scanner = struct { // Reconstruct type with array notation var type_buf: [256]u8 = undefined; - var fbs = std.io.fixedBufferStream(&type_buf); - const writer = fbs.writer(); + var writer: std.Io.Writer = .fixed(&type_buf); for (type_parts, 0..) |part, i| { if (i > 0) writer.writeByte(' ') catch { if (comment) |c| self.allocator.free(c); @@ -1060,7 +1134,7 @@ pub const Scanner = struct { return null; }; - const type_str = fbs.getWritten(); + const type_str = writer.buffered(); return FieldDecl{ .name = fixupZigName(name), @@ -1127,13 +1201,13 @@ pub const Scanner = struct { if (std.mem.startsWith(u8, trimmed, "}")) return &[_]FieldDecl{}; // Remove trailing semicolon - const no_semi = std.mem.trimRight(u8, trimmed, ";"); + const no_semi = std.mem.trimEnd(u8, trimmed, ";"); // Extract inline comment if present var comment: ?[]const u8 = null; var field_part = no_semi; if (std.mem.indexOf(u8, no_semi, "/**<")) |comment_start| { - field_part = std.mem.trimRight(u8, no_semi[0..comment_start], "; \t"); + field_part = std.mem.trimEnd(u8, no_semi[0..comment_start], "; \t"); if (std.mem.indexOf(u8, no_semi[comment_start..], "*/")) |end_offset| { const comment_text = no_semi[comment_start + 4 .. comment_start + end_offset]; comment = try self.allocator.dupe(u8, std.mem.trim(u8, comment_text, " \t")); @@ -1173,7 +1247,7 @@ pub const Scanner = struct { // Now parse the comma-separated field names const names_part = field_trimmed[type_end..]; - var field_list = std.ArrayList(FieldDecl){}; + var field_list = std.ArrayList(FieldDecl).empty; var name_iter = std.mem.splitScalar(u8, names_part, ','); while (name_iter.next()) |name_raw| { @@ -1212,23 +1286,23 @@ pub const Scanner = struct { return null; }; - const clean_name = std.mem.trimRight(u8, name, ";"); - + const clean_name = std.mem.trimEnd(u8, name, ";"); + // Skip any whitespace/newlines before looking for #define self.skipWhitespace(); - + // Look ahead to detect if this is a flag type by checking for #define patterns const lookahead_pos = self.pos; const is_bitshift_flag = try self.detectFlagPattern(clean_name); self.pos = lookahead_pos; // Restore position after detection - + // If bitshift detection failed, try suffix-based detection for types ending in "Flags" or "Format" var is_suffix_flag = false; if (!is_bitshift_flag and (std.mem.endsWith(u8, clean_name, "Flags") or std.mem.endsWith(u8, clean_name, "Format"))) { is_suffix_flag = try self.detectSuffixBasedFlags(clean_name); self.pos = lookahead_pos; // Restore position after detection } - + if (!is_bitshift_flag and !is_suffix_flag) { self.pos = start; return null; @@ -1269,32 +1343,32 @@ pub const Scanner = struct { .doc_comment = doc, }; } - + fn detectFlagPattern(self: *Scanner, typedef_name: []const u8) !bool { // Look ahead up to 15 lines for #define patterns that indicate this is a flag type // Criteria: // 1. Find #define statements with bit shift operators (<<) // 2. Check if they have a common prefix // 3. Check if the prefix relates to the typedef name - - var bitshift_defines = std.ArrayList([]const u8){}; + + var bitshift_defines = std.ArrayList([]const u8).empty; defer { for (bitshift_defines.items) |item| { self.allocator.free(item); } bitshift_defines.deinit(self.allocator); } - + var lines_checked: usize = 0; const max_lines = 15; - + while (lines_checked < max_lines and !self.isAtEnd()) { // Skip whitespace/comments self.skipWhitespace(); - + if (self.matchPrefix("#define ")) { const define_line = try self.readLine(); - + // Extract the define name (first token) var parts = std.mem.tokenizeScalar(u8, define_line, ' '); if (parts.next()) |define_name| { @@ -1304,70 +1378,70 @@ pub const Scanner = struct { lines_checked += 1; continue; } - + // Check if it contains bit shift operator if (std.mem.indexOf(u8, define_line, "<<") != null) { try bitshift_defines.append(self.allocator, try self.allocator.dupe(u8, define_name)); } } - + self.allocator.free(define_line); } else { // Not a #define, skip the line const line = try self.readLine(); self.allocator.free(line); } - + lines_checked += 1; - + // Keep collecting defines up to max_lines // (don't break early - we need to see all potential flags) } - + // Need at least 1 bit-shift define to consider it a bitshift flag type if (bitshift_defines.items.len < 1) { return false; } - + // For single define, just check if it relates to the typedef name if (bitshift_defines.items.len == 1) { // Skip prefix detection, just verify the define name relates to typedef return try self.matchesTypedefName(bitshift_defines.items[0], typedef_name); } - + // Check if defines have a common prefix const common_prefix = try naming.detectCommonPrefix(bitshift_defines.items, self.allocator); defer self.allocator.free(common_prefix); - + if (common_prefix.len == 0) { return false; } - + // Check if the prefix relates to the typedef name return self.matchesTypedefName(common_prefix, typedef_name); } - + fn detectSuffixBasedFlags(self: *Scanner, typedef_name: []const u8) !bool { // For types ending in "Flags", look for simple numeric defines // Example: SDL_MouseButtonFlags with SDL_BUTTON_LEFT = 1, SDL_BUTTON_MIDDLE = 2 - - var numeric_defines = std.ArrayList([]const u8){}; + + var numeric_defines = std.ArrayList([]const u8).empty; defer { for (numeric_defines.items) |item| { self.allocator.free(item); } numeric_defines.deinit(self.allocator); } - + var lines_checked: usize = 0; const max_lines = 15; - + while (lines_checked < max_lines and !self.isAtEnd()) { self.skipWhitespace(); - + if (self.matchPrefix("#define ")) { const define_line = try self.readLine(); - + var parts = std.mem.tokenizeScalar(u8, define_line, ' '); if (parts.next()) |define_name| { // Skip macro definitions like SDL_BUTTON_MASK(X) @@ -1376,17 +1450,18 @@ pub const Scanner = struct { lines_checked += 1; continue; } - + // Get the value part if (parts.next()) |value_part| { // Check if it's a macro wrapper like SDL_UINT64_C(0x...) const is_macro_wrapped_hex = blk: { - if (std.mem.startsWith(u8, value_part, "SDL_UINT64_C(") or - std.mem.startsWith(u8, value_part, "SDL_UINT32_C(")) { + if (std.mem.startsWith(u8, value_part, "SDL_UINT64_C(") or + std.mem.startsWith(u8, value_part, "SDL_UINT32_C(")) + { // Extract hex value from SDL_UINT64_C(0x0000000000000001) if (std.mem.indexOf(u8, value_part, "0x")) |hex_start| { if (std.mem.indexOf(u8, value_part[hex_start..], ")")) |paren_pos| { - const hex_str = value_part[hex_start..hex_start + paren_pos]; + const hex_str = value_part[hex_start .. hex_start + paren_pos]; _ = std.fmt.parseInt(u64, hex_str, 0) catch break :blk false; break :blk true; } @@ -1394,26 +1469,26 @@ pub const Scanner = struct { } break :blk false; }; - + // Check if it's a plain hex literal like 0x00000010u const is_plain_hex = blk: { if (std.mem.indexOf(u8, value_part, "<<") != null) break :blk false; if (std.mem.indexOf(u8, value_part, "|") != null) break :blk false; if (std.mem.indexOf(u8, value_part, "SDL_") != null) break :blk false; - + // Check if it starts with 0x if (std.mem.startsWith(u8, value_part, "0x") or std.mem.startsWith(u8, value_part, "0X")) { // Try to parse as hex (strip trailing 'u' if present) var hex_val = value_part; if (std.mem.endsWith(u8, value_part, "u") or std.mem.endsWith(u8, value_part, "U")) { - hex_val = value_part[0..value_part.len - 1]; + hex_val = value_part[0 .. value_part.len - 1]; } _ = std.fmt.parseInt(u64, hex_val, 0) catch break :blk false; break :blk true; } break :blk false; }; - + // Check if it's a simple numeric value (1, 2, 3, etc.) // Skip if it references other defines or has operators const is_simple_numeric = blk: { @@ -1421,89 +1496,89 @@ pub const Scanner = struct { if (std.mem.indexOf(u8, value_part, "|") != null) break :blk false; if (std.mem.indexOf(u8, value_part, "(") != null) break :blk false; if (std.mem.indexOf(u8, value_part, "SDL_") != null) break :blk false; - + // Try to parse as integer _ = std.fmt.parseInt(u32, value_part, 0) catch break :blk false; break :blk true; }; - + if (is_simple_numeric or is_macro_wrapped_hex or is_plain_hex) { try numeric_defines.append(self.allocator, try self.allocator.dupe(u8, define_name)); } } } - + self.allocator.free(define_line); } else { const line = try self.readLine(); self.allocator.free(line); } - + lines_checked += 1; - + // Keep collecting defines up to max_lines // (don't break early - we need to see all potential flags) } - + // Need at least 1 numeric define if (numeric_defines.items.len < 1) { return false; } - + // For single define, just check if it relates to the typedef name if (numeric_defines.items.len == 1) { return try self.matchesTypedefName(numeric_defines.items[0], typedef_name); } - + // Check if defines have a common prefix const common_prefix = try naming.detectCommonPrefix(numeric_defines.items, self.allocator); defer self.allocator.free(common_prefix); - + if (common_prefix.len == 0) { return false; } - + // Check if the prefix relates to the typedef name return self.matchesTypedefName(common_prefix, typedef_name); } - + fn matchesTypedefName(self: *Scanner, common_prefix: []const u8, typedef_name: []const u8) !bool { // Convert typedef name to uppercase and remove SDL_ prefix for comparison const typedef_upper = try std.ascii.allocUpperString(self.allocator, typedef_name); defer self.allocator.free(typedef_upper); - + const typedef_without_sdl = if (std.mem.startsWith(u8, typedef_upper, "SDL_")) typedef_upper[4..] else typedef_upper; - + // Remove common suffixes like FLAGS, FORMAT from typedef for comparison var typedef_core = typedef_without_sdl; if (std.mem.endsWith(u8, typedef_core, "FLAGS")) { - typedef_core = typedef_core[0..typedef_core.len - 5]; + typedef_core = typedef_core[0 .. typedef_core.len - 5]; } else if (std.mem.endsWith(u8, typedef_core, "FORMAT")) { - typedef_core = typedef_core[0..typedef_core.len - 6]; + typedef_core = typedef_core[0 .. typedef_core.len - 6]; } - + // Check if prefix contains the typedef core (ignoring underscores) // SDL_GPU_TEXTUREUSAGE should match GPUTEXTUREUSAGE const prefix_no_underscores = try std.mem.replaceOwned(u8, self.allocator, common_prefix, "_", ""); defer self.allocator.free(prefix_no_underscores); const typedef_no_underscores = try std.mem.replaceOwned(u8, self.allocator, typedef_core, "_", ""); defer self.allocator.free(typedef_no_underscores); - + // Remove SDL from prefix if present const prefix_without_sdl = if (std.mem.startsWith(u8, prefix_no_underscores, "SDL")) prefix_no_underscores[3..] else prefix_no_underscores; - + // Check if typedef starts with the prefix (GPU vs GPUTEXTUREUSAGE) const typedef_starts_with_prefix = std.mem.startsWith(u8, typedef_no_underscores, prefix_without_sdl); const prefix_starts_with_typedef = std.mem.startsWith(u8, prefix_without_sdl, typedef_no_underscores); - const significant_overlap = prefix_without_sdl.len >= 3 and typedef_no_underscores.len >= prefix_without_sdl.len and - std.mem.startsWith(u8, typedef_no_underscores, prefix_without_sdl); - + const significant_overlap = prefix_without_sdl.len >= 3 and typedef_no_underscores.len >= prefix_without_sdl.len and + std.mem.startsWith(u8, typedef_no_underscores, prefix_without_sdl); + return typedef_starts_with_prefix or prefix_starts_with_typedef or significant_overlap; } @@ -1542,7 +1617,7 @@ pub const Scanner = struct { } const value_str = value_parts.items; - + // If it already has << or |, it's a flag define if (std.mem.indexOf(u8, value_str, "<<") != null) { return FlagOrConstResult{ @@ -1554,17 +1629,18 @@ pub const Scanner = struct { .constant = null, }; } - + // Handle SDL_UINT64_C(0x...) or SDL_UINT32_C(0x...) macros - if (std.mem.startsWith(u8, value_str, "SDL_UINT64_C(") or - std.mem.startsWith(u8, value_str, "SDL_UINT32_C(")) { + if (std.mem.startsWith(u8, value_str, "SDL_UINT64_C(") or + std.mem.startsWith(u8, value_str, "SDL_UINT32_C(")) + { // Extract hex value if (std.mem.indexOf(u8, value_str, "0x")) |hex_start| { if (std.mem.indexOf(u8, value_str[hex_start..], ")")) |paren_pos| { - const hex_str = value_str[hex_start..hex_start + paren_pos]; + const hex_str = value_str[hex_start .. hex_start + paren_pos]; if (std.fmt.parseInt(u64, hex_str, 0)) |numeric_val| { if (numeric_val == 0) return FlagOrConstResult{ .flag = null, .constant = null }; - + // Power of 2: create a flag with bitshift if (isPowerOfTwo(@intCast(numeric_val))) { const bit_pos = @ctz(numeric_val); @@ -1594,18 +1670,18 @@ pub const Scanner = struct { // Couldn't parse, skip return FlagOrConstResult{ .flag = null, .constant = null }; } - + // Handle plain hex literals like 0x00000010u if (std.mem.startsWith(u8, value_str, "0x") or std.mem.startsWith(u8, value_str, "0X")) { // Strip trailing 'u' or 'U' if present var hex_val = value_str; if (std.mem.endsWith(u8, value_str, "u") or std.mem.endsWith(u8, value_str, "U")) { - hex_val = value_str[0..value_str.len - 1]; + hex_val = value_str[0 .. value_str.len - 1]; } - + if (std.fmt.parseInt(u64, hex_val, 0)) |numeric_val| { if (numeric_val == 0) return FlagOrConstResult{ .flag = null, .constant = null }; - + // Power of 2: create a flag with bitshift if (isPowerOfTwo(@intCast(numeric_val))) { const bit_pos = @ctz(numeric_val); @@ -1633,16 +1709,16 @@ pub const Scanner = struct { // Couldn't parse, skip return FlagOrConstResult{ .flag = null, .constant = null }; } - + // Skip complex expressions if (std.mem.indexOf(u8, value_str, "|") != null) return FlagOrConstResult{ .flag = null, .constant = null }; if (std.mem.indexOf(u8, value_str, "(") != null) return FlagOrConstResult{ .flag = null, .constant = null }; if (std.mem.indexOf(u8, value_str, "SDL_") != null) return FlagOrConstResult{ .flag = null, .constant = null }; - + // Try to parse as integer if (std.fmt.parseInt(u32, value_str, 0)) |numeric_val| { if (numeric_val == 0) return FlagOrConstResult{ .flag = null, .constant = null }; - + // Power of 2: create a flag with bitshift if (isPowerOfTwo(numeric_val)) { const bit_pos = @ctz(numeric_val); @@ -1667,11 +1743,11 @@ pub const Scanner = struct { }; } } else |_| {} - + // Can't parse, skip return FlagOrConstResult{ .flag = null, .constant = null }; } - + fn isPowerOfTwo(n: u32) bool { return n != 0 and (n & (n - 1)) == 0; } @@ -1824,7 +1900,7 @@ pub const Scanner = struct { // Find matching ] if (std.mem.indexOfScalar(u8, working_param[bracket_pos..], ']')) |_| { is_array = true; - working_param = std.mem.trimRight(u8, working_param[0..bracket_pos], " \t"); + working_param = std.mem.trimEnd(u8, working_param[0..bracket_pos], " \t"); } } @@ -1876,7 +1952,7 @@ pub const Scanner = struct { while (param_name.len > 0 and param_name[0] == '*') { const new_type = try std.fmt.bufPrint(&type_buf, "{s} *", .{param_type}); param_type = new_type; - param_name = std.mem.trimLeft(u8, param_name[1..], " \t"); + param_name = std.mem.trimStart(u8, param_name[1..], " \t"); } // If this was an array parameter, convert pointer level @@ -1887,7 +1963,7 @@ pub const Scanner = struct { // Output type should be: "[*c][*c]char" // But for simplicity in generated code, we can use the original type + pointer // Check if type already ends with * - const trimmed_type = std.mem.trimRight(u8, param_type, " \t"); + const trimmed_type = std.mem.trimEnd(u8, param_type, " \t"); if (std.mem.endsWith(u8, trimmed_type, "*")) { // Already has pointer, add another without space const type_copy = try std.fmt.bufPrint(&type_buf, "{s}*", .{trimmed_type}); @@ -2050,3 +2126,96 @@ pub const Scanner = struct { return comment; } }; + +test "enum values without comments, with plain comments and without trailing comma" { + const allocator = std.heap.smp_allocator; + const source = + \\typedef enum SDL_TouchDeviceType + \\{ + \\ SDL_TOUCH_DEVICE_INVALID = -1, + \\ SDL_TOUCH_DEVICE_DIRECT, /* touch screen with window-relative coordinates */ + \\ SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /**< trackpad with absolute + \\ device coordinates */ + \\ SDL_TOUCH_DEVICE_INDIRECT_RELATIVE /* trackpad with screen cursor-relative coordinates */ + \\} SDL_TouchDeviceType; + \\ + ; + var scanner = Scanner.init(allocator, source); + defer scanner.deinit(); + const decls = try scanner.scan(); + defer { + for (decls) |decl| switch (decl) { + inline else => |*d| d.deinit(allocator), + }; + allocator.free(decls); + } + + try std.testing.expectEqual(1, decls.len); + const values = decls[0].enum_decl.values; + try std.testing.expectEqual(4, values.len); + try std.testing.expectEqualStrings("SDL_TOUCH_DEVICE_INVALID", values[0].name); + try std.testing.expectEqualStrings("-1", values[0].value.?); + try std.testing.expectEqualStrings("SDL_TOUCH_DEVICE_DIRECT", values[1].name); + try std.testing.expect(values[1].comment == null); + try std.testing.expectEqualStrings("trackpad with absolute device coordinates", values[2].comment.?); + try std.testing.expectEqualStrings("SDL_TOUCH_DEVICE_INDIRECT_RELATIVE", values[3].name); +} + +test "enum byte order conditionals use the little endian branch" { + const allocator = std.heap.smp_allocator; + const source = + \\typedef enum SDL_AudioFormat + \\{ + \\ SDL_AUDIO_S16LE = 0x8010u, /**< Signed 16-bit samples */ + \\ /* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 16), */ + \\ SDL_AUDIO_S16BE = 0x9010u, /**< As above, but big-endian byte order */ + \\ #if SDL_BYTEORDER == SDL_LIL_ENDIAN + \\ SDL_AUDIO_S16 = SDL_AUDIO_S16LE + \\ #else + \\ SDL_AUDIO_S16 = SDL_AUDIO_S16BE + \\ #endif + \\} SDL_AudioFormat; + \\ + ; + var scanner = Scanner.init(allocator, source); + defer scanner.deinit(); + const decls = try scanner.scan(); + defer { + for (decls) |decl| switch (decl) { + inline else => |*d| d.deinit(allocator), + }; + allocator.free(decls); + } + + const values = decls[0].enum_decl.values; + try std.testing.expectEqual(3, values.len); + try std.testing.expectEqualStrings("SDL_AUDIO_S16", values[2].name); + try std.testing.expectEqualStrings("SDL_AUDIO_S16LE", values[2].value.?); +} + +test "struct fields followed by a multi-line comment are kept" { + const allocator = std.heap.smp_allocator; + const source = + \\typedef struct SDL_Example + \\{ + \\ Uint32 button_mask; /**< A mask of which buttons are valid + \\ e.g. (1 << SDL_GAMEPAD_BUTTON_SOUTH) */ + \\ const char *name; /**< the name */ + \\} SDL_Example; + \\ + ; + var scanner = Scanner.init(allocator, source); + defer scanner.deinit(); + const decls = try scanner.scan(); + defer { + for (decls) |decl| switch (decl) { + inline else => |*d| d.deinit(allocator), + }; + allocator.free(decls); + } + + const fields = decls[0].struct_decl.fields; + try std.testing.expectEqual(2, fields.len); + try std.testing.expectEqualStrings("button_mask", fields[0].name); + try std.testing.expectEqualStrings("name", fields[1].name); +} diff --git a/src/types.zig b/src/types.zig index e61450d..05a6eef 100644 --- a/src/types.zig +++ b/src/types.zig @@ -5,9 +5,16 @@ const Allocator = std.mem.Allocator; pub fn convertType(c_type: []const u8, allocator: Allocator) Allocator.Error![]const u8 { const trimmed = std.mem.trim(u8, c_type, " \t"); - // Handle opaque struct pointers: "struct X *" -> "*anyopaque" + // Normalize `*const` to `* const` so both spellings hit the same rules. + if (std.mem.indexOf(u8, trimmed, "*const") != null and std.mem.indexOfScalar(u8, trimmed, '(') == null) { + const normalized = try std.mem.replaceOwned(u8, allocator, trimmed, "*const", "* const"); + defer allocator.free(normalized); + return convertType(normalized, allocator); + } + + // Handle opaque struct pointers: "struct X *" -> "?*anyopaque" if (std.mem.startsWith(u8, trimmed, "struct ") and std.mem.endsWith(u8, trimmed, " *")) { - return try allocator.dupe(u8, "*anyopaque"); + return try allocator.dupe(u8, "?*anyopaque"); } // Handle function pointers used in callbacks and interface structs. @@ -236,7 +243,10 @@ pub fn convertStructFieldType(c_type: []const u8, allocator: Allocator) Allocato const base_type = std.mem.trim(u8, rest[0..first_star], " \t"); const star_count = std.mem.count(u8, rest[first_star..], "*"); - const zig_base = if (std.mem.eql(u8, base_type, "void")) + // `[*c]anyopaque` is not a valid Zig type (C pointers cannot point to opaque + // types), so the pointer directly to void becomes `?*anyopaque`. + const is_void = std.mem.eql(u8, base_type, "void"); + const zig_base = if (is_void) try allocator.dupe(u8, "anyopaque") else try convertType(base_type, allocator); @@ -245,8 +255,9 @@ pub fn convertStructFieldType(c_type: []const u8, allocator: Allocator) Allocato var result: std.ArrayList(u8) = .empty; defer result.deinit(allocator); - for (0..star_count) |_| { - try result.appendSlice(allocator, "[*c]"); + for (0..star_count) |i| { + const innermost = i + 1 == star_count; + try result.appendSlice(allocator, if (is_void and innermost) "?*" else "[*c]"); } if (pointee_const) { try result.appendSlice(allocator, "const "); @@ -256,83 +267,8 @@ pub fn convertStructFieldType(c_type: []const u8, allocator: Allocator) Allocato return try result.toOwnedSlice(allocator); } -fn isOpaquePointerLike(zig_type: []const u8) bool { - if (!(std.mem.startsWith(u8, zig_type, "?*") or std.mem.startsWith(u8, zig_type, "*"))) { - return false; - } - - if (std.mem.indexOf(u8, zig_type, "anyopaque") != null or - std.mem.startsWith(u8, zig_type, "[*c]") or - std.mem.startsWith(u8, zig_type, "?[*c]")) - { - return false; - } - - return true; -} - -fn isEnumLikeType(zig_type: []const u8) bool { - if (isPackedFlagsLikeType(zig_type)) return false; - - return std.mem.indexOf(u8, zig_type, "Type") != null or - std.mem.indexOf(u8, zig_type, "Size") != null or - std.mem.indexOf(u8, zig_type, "Mode") != null or - std.mem.indexOf(u8, zig_type, "Op") != null or - std.mem.endsWith(u8, zig_type, "Format"); -} - -fn isPackedFlagsLikeType(zig_type: []const u8) bool { - return std.mem.endsWith(u8, zig_type, "Flags") or - std.mem.eql(u8, zig_type, "GPUShaderFormat") or - std.mem.eql(u8, zig_type, "FlipMode"); -} - -/// Determine the appropriate cast for a Zig parameter passed into a C function. -pub fn getParamCastType(zig_type: []const u8) CastType { - // Bool needs @bitCast - if (std.mem.eql(u8, zig_type, "bool")) { - return .bit_cast; - } - - // Opaque pointers need @ptrCast (both ?*Type and *Type) - if (isOpaquePointerLike(zig_type)) { - return .ptr_cast; - } - - if (isEnumLikeType(zig_type)) { - return .int_from_enum; - } - - if (isPackedFlagsLikeType(zig_type)) { - return .bit_cast; - } - - return .none; -} - -/// Determine the appropriate cast for a C return value exposed as a Zig type. -pub fn getReturnCastType(zig_type: []const u8) CastType { - if (std.mem.eql(u8, zig_type, "bool")) { - return .bit_cast; - } - - if (isOpaquePointerLike(zig_type)) { - return .ptr_cast; - } - - if (isEnumLikeType(zig_type)) { - return .enum_from_int; - } - - if (isPackedFlagsLikeType(zig_type)) { - return .bit_cast; - } - - return .none; -} - /// Convert C function pointer type to Zig function pointer syntax -/// Example: Sint64 (SDLCALL *size)(void *userdata) -> *const fn (?*anyopaque) callconv(.C) i64 +/// Example: Sint64 (SDLCALL *size)(void *userdata) -> *const fn (?*anyopaque) callconv(.c) i64 fn convertFunctionPointerType(c_type: []const u8, allocator: Allocator) Allocator.Error![]const u8 { // Pattern: ReturnType (SDLCALL *name)(params) or ReturnType (*name)(params) @@ -391,7 +327,7 @@ fn convertFunctionPointerType(c_type: []const u8, allocator: Allocator) Allocato try result.appendSlice(allocator, param); } - try result.appendSlice(allocator, ") callconv(.C) "); + try result.appendSlice(allocator, ") callconv(.c) "); try result.appendSlice(allocator, zig_return); return try result.toOwnedSlice(allocator); @@ -413,20 +349,12 @@ fn stripParamName(param: []const u8) []const u8 { if (ident_start == param.len or ident_start == 0) return param; - const before_name = std.mem.trimRight(u8, param[0..ident_start], " \t"); + const before_name = std.mem.trimEnd(u8, param[0..ident_start], " \t"); if (before_name.len == 0) return param; return before_name; } -pub const CastType = enum { - none, - ptr_cast, - bit_cast, - int_from_enum, - enum_from_int, -}; - test "convert const SDL double pointer" { const allocator = std.testing.allocator; const zig_type = try convertType("const SDL_TrayEntry **", allocator); @@ -440,7 +368,7 @@ test "convert function pointer callback type" { const zig_type = try convertType("Sint64 (SDLCALL *size)(void *userdata)", allocator); defer allocator.free(zig_type); - try std.testing.expectEqualStrings("?*const fn(?*anyopaque) callconv(.C) i64", zig_type); + try std.testing.expectEqualStrings("?*const fn(?*anyopaque) callconv(.c) i64", zig_type); } test "convert SDL pointer arrays preserves const on outer sequence" { @@ -455,15 +383,11 @@ test "convert SDL pointer arrays preserves const on outer sequence" { try std.testing.expectEqualStrings("[*c]const ?*const GPUBuffer", const_zig_type); } -test "enum cast direction differs for params and returns" { - try std.testing.expectEqual(.int_from_enum, getParamCastType("GPUTextureFormat")); - try std.testing.expectEqual(.enum_from_int, getReturnCastType("GPUTextureFormat")); - try std.testing.expectEqual(.int_from_enum, getParamCastType("GPUIndexElementSize")); - try std.testing.expectEqual(.enum_from_int, getReturnCastType("GPUIndexElementSize")); - try std.testing.expectEqual(.bit_cast, getParamCastType("GPUShaderFormat")); - try std.testing.expectEqual(.bit_cast, getReturnCastType("GPUShaderFormat")); - try std.testing.expectEqual(.bit_cast, getParamCastType("FlipMode")); - try std.testing.expectEqual(.bit_cast, getReturnCastType("FlipMode")); +test "pointer const spelling without space" { + const allocator = std.testing.allocator; + const a = try convertType("const char *const *", allocator); + defer allocator.free(a); + try std.testing.expectEqualStrings("[*c]const [*c]const u8", a); } test "struct fields use C pointers" { @@ -475,5 +399,9 @@ test "struct fields use C pointers" { const generic = try convertStructFieldType("const void *", allocator); defer allocator.free(generic); - try std.testing.expectEqualStrings("[*c]const anyopaque", generic); + try std.testing.expectEqualStrings("?*const anyopaque", generic); + + const nested = try convertStructFieldType("void **", allocator); + defer allocator.free(nested); + try std.testing.expectEqualStrings("[*c]?*anyopaque", nested); }