floooh / sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
341 stars 46 forks source link

incompatible with latest zig? #28

Closed meshula closed 1 year ago

meshula commented 1 year ago

Things were working a month ago, but now I'm on 0.10.0-dev.3978+4fd4c733d, and getting new mystery errors ~ I was wondering if this looks like something I might be able to patch quickly, or if something more fundamental is going on here?

/Users/nporcino/dev/time_hierarchies/third-party/sokol-zig/src/sokol/app.zig:221:5: error: extern structs cannot contain fields of type '?fn() callconv(.C) void'
    init_cb: ?fn() callconv(.C) void = null,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/nporcino/dev/time_hierarchies/third-party/sokol-zig/src/sokol/app.zig:221:5: note: only pointer like optionals are extern compatible
/Users/nporcino/dev/time_hierarchies/third-party/sokol-zig/src/sokol/gfx.zig:658:5: error: extern structs cannot contain fields of type '?fn(usize, ?*anyopaque) callconv(.C) ?*anyopaque'
    alloc: ?fn(usize, ?*anyopaque) callconv(.C) ?*anyopaque = null,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/nporcino/dev/time_hierarchies/third-party/sokol-zig/src/sokol/gfx.zig:658:5: note: only pointer like optionals are extern compatible
floooh commented 1 year ago

Yes, that's because the self-hosted compiler is now the default, which has a different syntax for function pointers.

There's a PR here: https://github.com/floooh/sokol-zig/pull/26, but I need to figure out how to deal with the automatic binding generation during the time where both the 0.9.x and the latest 0.10.x Zig versions need to be supported (e.g. the main branch of the sokol-zig bindings should remain compatible with 0.9.x until 0.10.x is officially released, and until then, the 0.10.x bindings should go into a branch, which probably needs to be updated manually).

floooh commented 1 year ago

PS: the zig compiler has an option -fstage1 which you could try as workaround for now:

zig build -fstage1

meshula commented 1 year ago

Thanks very much! I can run with those hints.

floooh commented 1 year ago

@meshula just FYI, I just merged a PR into the branch zig-0.10.0 which updates the bindings and examples for the latest Zig dev version.

The examples required some changes (most importantly, the way asRange() is had to change (arrays now need to be passed by pointer), there seems to be a change how Zig passes arrays. But other then that it should mostly 'just work' (apart from any other changes in the self hosted compiler of course).

PS: this is the commit with the example fixes: https://github.com/floooh/sokol-zig/commit/9e22cf662623e4aefd3cb89b7fe982e30ad6d71b, and there's also some info here: https://github.com/floooh/sokol-zig/pull/26

meshula commented 1 year ago

Thanks! Much appreciated.