Skip to content

Commit

Permalink
sokol-zig: work around a breaking naming convention change in the Zig…
Browse files Browse the repository at this point in the history
… stdlib
  • Loading branch information
floooh committed Aug 31, 2024
1 parent e85b58a commit faf7593
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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()`):
Expand Down
47 changes: 33 additions & 14 deletions bindgen/gen_zig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down

0 comments on commit faf7593

Please sign in to comment.