floooh / sokol-zig

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

Add Zig 8.0 support #9

Closed darltrash closed 3 years ago

darltrash commented 3 years ago

Hello! I was trying to compile Sokol with the latest Zig and it gave me an error caused by the change from pub inline fn to fn XXX() callconv(.Inline), so i decided to fix it. here is my attempt.

I just changed line 436 from the gen_zig.py bindgen to:

l(f"pub fn {zig_func_name}({funcdecl_args_zig(decl, prefix)}) callconv(.Inline) {funcdecl_res_zig(decl, prefix)} {{")

It seems to be working just fine, but some examples break (the instancing one, for example (no pun intended)).

The example error was this:

./src/examples/instancing.zig:136:25: error: expected type 'i32', found 'u32'
    sg.draw(0, 24, state.cur_num_particles);
                        ^
./src/examples/instancing.zig:136:25: note: signed 32-bit int cannot represent all possible unsigned 32-bit values
    sg.draw(0, 24, state.cur_num_particles);
                        ^
instancing...The following command exited with error code 1:
/usr/bin/zig build-exe /home/darltrash/Projects/sokol/bindgen/sokol-zig/src/examples/instancing.zig /home/darltrash/Projects/sokol/bindgen/sokol-zig/zig-cache/o/5e25f44492e48a144bd0f39181fc832c/libsokol.a -lc -lX11 -lXi -lXcursor -lGL -lasound --cache-dir /home/darltrash/Projects/sokol/bindgen/sokol-zig/zig-cache --global-cache-dir /home/darltrash/.cache/zig --name instancing --pkg-begin sokol /home/darltrash/Projects/sokol/bindgen/sokol-zig/src/sokol/sokol.zig --pkg-end --enable-cache 
error: the following build command failed with exit code 1:
/home/darltrash/Projects/sokol/bindgen/sokol-zig/zig-cache/o/3f62bb538e9d96b9e2c16e827bcef4b7/build /usr/bin/zig /home/darltrash/Projects/sokol/bindgen/sokol-zig /home/darltrash/Projects/sokol/bindgen/sokol-zig/zig-cache /home/darltrash/.cache/zig run-instancing
floooh commented 3 years ago

Nice, thanks. I'm planning to return to the Zig bindings soon (exactly because of those signed-vs-unsigned things, while the C-API will keep signed integers for almost everything, I'd like to change some things in the Zig API to unsigned).

I also need to fix the build.zig script for 8.0 on macOS (I guess you're not on macOS, otherwise you'd run into trouble building with 8.0, that's the other thing I need to look into).

Cheers!

floooh commented 3 years ago

Ok, I've updated to the latest sokol headers, and fixed the signed/unsigned confusion.

For the 'inline' keyword, I decided to simply remove this. It's not needed, and we can add it back when the language has more stabilized.

floooh commented 3 years ago

PS: please check the new branch zig-0.8.0 which should work across Wndows, Linux and macOS with the current zig dev version (0.8.0)