فهرست منبع

Merge pull request #1100 from floooh/fix/sokol-zig/issue78

sokol-zig: work around a breaking Zig stdlib naming change
Andre Weissflog 1 سال پیش
والد
کامیت
9b2bf20a21
2فایلهای تغییر یافته به همراه47 افزوده شده و 14 حذف شده
  1. 14 0
      CHANGELOG.md
  2. 33 14
      bindgen/gen_zig.py

+ 14 - 0
CHANGELOG.md

@@ -1,5 +1,19 @@
 ## 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
+```
+
+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()`):

+ 33 - 14
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('')