From faf759354e2bd71a73738b7c54e95786aa17d5e5 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 31 Aug 2024 13:10:42 +0200 Subject: sokol-zig: work around a breaking naming convention change in the Zig stdlib --- CHANGELOG.md | 12 ++++++++++++ bindgen/gen_zig.py | 47 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de74557..0d7626bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ ## Updates +### 31-Aug-2024 + +A fix in the sokol-zig bindings generator for a breaking naming convention +change in the Zig stdlib. The fix supports both the old and new naming +convention so that sokol-zig continues to be compatible with zig 0.13.0. + +To update the sokol-zig depenency in your project, just run: + +``` +zig fetch --save=sokol git+https://github.com/floooh/sokol-zig.git +``` + ### 26-Aug-2024 A small behaviour update for sokol_gl.h (may be breaking if you call `sgl_error()`): diff --git a/bindgen/gen_zig.py b/bindgen/gen_zig.py index 4b63eebe..7b537586 100644 --- a/bindgen/gen_zig.py +++ b/bindgen/gen_zig.py @@ -466,20 +466,39 @@ def gen_helpers(inp): l('// helper function to convert "anything" to a Range struct') l('pub fn asRange(val: anytype) Range {') l(' const type_info = @typeInfo(@TypeOf(val));') - l(' switch (type_info) {') - l(' .Pointer => {') - l(' switch (type_info.Pointer.size) {') - l(' .One => return .{ .ptr = val, .size = @sizeOf(type_info.Pointer.child) },') - l(' .Slice => return .{ .ptr = val.ptr, .size = @sizeOf(type_info.Pointer.child) * val.len },') - l(' else => @compileError("FIXME: Pointer type!"),') - l(' }') - l(' },') - l(' .Struct, .Array => {') - l(' @compileError("Structs and arrays must be passed as pointers to asRange");') - l(' },') - l(' else => {') - l(' @compileError("Cannot convert to range!");') - l(' },') + l(' // FIXME: naming convention change between 0.13 and 0.14-dev') + l(' if (@hasField(@TypeOf(type_info), "Pointer")) {') + l(' switch (type_info) {') + l(' .Pointer => {') + l(' switch (type_info.Pointer.size) {') + l(' .One => return .{ .ptr = val, .size = @sizeOf(type_info.Pointer.child) },') + l(' .Slice => return .{ .ptr = val.ptr, .size = @sizeOf(type_info.Pointer.child) * val.len },') + l(' else => @compileError("FIXME: Pointer type!"),') + l(' }') + l(' },') + l(' .Struct, .Array => {') + l(' @compileError("Structs and arrays must be passed as pointers to asRange");') + l(' },') + l(' else => {') + l(' @compileError("Cannot convert to range!");') + l(' },') + l(' }') + l(' } else {') + l(' switch (type_info) {') + l(' .pointer => {') + l(' switch (type_info.pointer.size) {') + l(' .One => return .{ .ptr = val, .size = @sizeOf(type_info.pointer.child) },') + l(' .Slice => return .{ .ptr = val.ptr, .size = @sizeOf(type_info.pointer.child) * val.len },') + l(' else => @compileError("FIXME: Pointer type!"),') + l(' }') + l(' },') + l(' .@"struct", .array => {') + l(' @compileError("Structs and arrays must be passed as pointers to asRange");') + l(' },') + l(' else => {') + l(' @compileError("Cannot convert to range!");') + l(' },') + l(' }') l(' }') l('}') l('') -- cgit v1.2.3 From eba2681843c1aa7af66680067ee28c333cc3dd51 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 31 Aug 2024 13:13:20 +0200 Subject: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7626bd..8b243805 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ To update the sokol-zig depenency in your project, just run: zig fetch --save=sokol git+https://github.com/floooh/sokol-zig.git ``` +Details in PR https://github.com/floooh/sokol/pull/1100 + ### 26-Aug-2024 A small behaviour update for sokol_gl.h (may be breaking if you call `sgl_error()`): -- cgit v1.2.3