floooh / sokol-zig

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

Compilation Fails zig 0.8.0-dev.1141+68e772647 on Windows 10 #7

Closed paulevans closed 3 years ago

paulevans commented 3 years ago

Hello, I saw in the one other issue currently open that you are sticking with zig 7.1 right now... but thought it would be worthwhile giving you a heads up anyway. The line it is complaining about seems okay to me?


PS F:\github\paulevans\sokol-zig> zig version
0.8.0-dev.1141+68e772647
PS F:\github\paulevans\sokol-zig> zig build
Semantic Analysis... .\src\sokol\gfx.zig:718:5: error: expected function or variable declaration after pub
pub inline fn setup(desc: Desc) void {
    ^
clear...The following command exited with error code 1:
C:\Apps\zig-windows-x86_64-0.8.0-dev.1141+68e772647\zig.exe build-exe F:\github\paulevans\sokol-zig\src\examples\clear.zig F:\github\paulevans\sokol-zig\zig-cache\o\127299955b41b17a241a44ab60483b30\sokol.lib -lc --cache-dir F:\github\paulevans\sokol-zig\zig-cache --global-cache-dir C:\Users\pevans\AppData\Local\zig --name clear --pkg-begin sokol F:\github\paulevans\sokol-zig\src\sokol\sokol.zig --pkg-end --enable-cache
error: the following build command failed with exit code 1:
F:\github\paulevans\sokol-zig\zig-cache\o\bb6c8c71e8d64ef9dad598f452b0d922\build.exe C:\Apps\zig-windows-x86_64-0.8.0-dev.1141+68e772647\zig.exe F:\github\paulevans\sokol-zig F:\github\paulevans\sokol-zig\zig-cache C:\Users\pevans\AppData\Local\zig
paulevans commented 3 years ago

So I guess the language changed how you declare inline?

pub fn setup(desc: Desc) callconv(.Inline) void {
    sg_setup(&desc);
}

compiles - it then fails on shutdown.

So this is more of a TODO for 8.0 than a bug!

andrewrk commented 3 years ago

fwiw zig fmt will automatically upgrade that particular thing to the new syntax.

paulevans commented 3 years ago

Thanks, you are correct. That almost worked. Had to change one extra line in debugtext-print.zig to read "Hello '{s}'!" - adding that s. Here's the diff: https://github.com/floooh/sokol-zig/compare/master...paulevans:zig8.0?expand=1

floooh commented 3 years ago

FWIW I'll try to return to the Zig bindings soon-ish after I've taken care of a couple of pending issues and PRs for the sokol headers. That specific inline thing can be changed here in the generator-script:

https://github.com/floooh/sokol/blob/master/bindgen/gen_zig.py#L436

However, the underlying C-APIs of the sokol-headers have changed a bit (regarding signed vs unsigned parameters) which would also break the current example code. I'll need to do some type-mapping in the bindings-generator, because in Zig I want to change some function parameters to unsigned where the C-API has signed numbers (reason being that it's "safer" to use unsigned parameters in Zig because of Zigs robust overflow checking, while in C it's easy to accidentally produce an underflow, so for C, using "almost always signed" makes more sense).

paulevans commented 3 years ago

I have been looking at patching the generator actually already. Although I didn't realize I needed clang installed to run it. So I have been on-and-off prodding that clang build on my windows machine - been a while since I last did that and on a different machine. Ended up fixing something tiny in fips as well. Just something windows specific to do with windows store installed python. Anything I think is useful enough to share I'll fire off some pull requests. I have been seeing if I could get the sokol-imgui bindings generated for zig. Though thanks for the heads up, sounds like that probably won't work out with recent changes. So were you planning on just having a shim that cast between signed and unsigned in the bindings layer then? I've just started to poke around in zig and I know it can compile c - though not tried that myself yet - just via other people's projects. The idea of the extra bindings is to take better advantage of zig's safety features and make things seem more zig-gy?

On Fri, 19 Feb 2021 at 04:16, Andre Weissflog notifications@github.com wrote:

FWIW I'll try to return to the Zig bindings soon-ish after I've taken care of a couple of pending issues and PRs for the sokol headers. That specific inline thing can be changed here in the generator-script:

https://github.com/floooh/sokol/blob/master/bindgen/gen_zig.py#L436

However, the underlying C-APIs of the sokol-headers have changed a bit (regarding signed vs unsigned parameters) which would also break the current example code. I'll need to do some type-mapping in the bindings-generator, because in Zig I want to change some function parameters to unsigned where the C-API has signed numbers (reason being that it's "safer" to use unsigned parameters in Zig because of Zigs robust overflow checking, while in C it's easy to accidentally produce an underflow, so for C, using "almost always signed" makes more sense).

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/floooh/sokol-zig/issues/7#issuecomment-781978573, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFPRSFFMZPCOYBNH45R3JLS7Y26ZANCNFSM4X3NNLBA .

floooh commented 3 years ago

I needed clang...

I found the easiest way to install clang on Windows is scoop install llvm (also python, cmake, even zig). I haven't tested the code generator on Windows though, mostly used macOS and Linux for this stuff. If clang is in the path it should work on Windows too though.

is to take better advantage of zig's safety features and make things seem more zig-gy

Yep, mostly to make the sokol C-APIs more "zig-gy", but Zig was also an easy first target because it binds really well to C-APIs. The long-term goal is though to support more language bindings with minimal work. Next up is nim support for instance.

I wrote a blog post about this here: https://floooh.github.io/2020/08/23/sokol-bindgen.html