floooh / sokol-zig

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

Finding OpenGL/gl.h on mac #11

Closed meshula closed 3 years ago

meshula commented 3 years ago

https://github.com/floooh/sokol-zig/blob/5f56bd406d1cdc76964bff577e25f0ae1f03e605/build.zig#L9

I guess, but am not sure, that this include of /usr/include was meant to pick up <OpenGL/gl.h> $SDK_ROOT/usr/include still exists, but there's nothing at $SDK_ROOT/usr/include/OpenGL in Catalina or Big Sur. I was able to get past the issue I ran into of zig not finding OpenGL/gl.h by invoking ln -s $SDK_ROOT/Frameworks/OpenGL/Headers OpenGL where zig can see it, making <OpenGL/gl.h> a legitimate path.

If I misunderstand why you have /usr/include specified, please disregard :)

floooh commented 3 years ago

Hi :)

The /usr/include path was needed for other headers which are not in frameworks, I don't remember which exactly though. The OpenGL headers are definitely expected to be loaded from the Frameworks header path (that's why this line exists:

https://github.com/floooh/sokol-zig/blob/5f56bd406d1cdc76964bff577e25f0ae1f03e605/build.zig#L8

Some framework headers seem to include headers from /usr/include though (for instance AudioToolbox.h includes a header called workgroup.h which lives in usr/include, and this led to a confusion with headers bundled with Zig (see this issue: https://github.com/ziglang/zig/issues/8360). I've solved this through other means in the meantime (by not including any macOS headers in sokol_audio.h but instead embed the required declarations). Other framework headers (like the Metal stuff) don't seem to suffer from this problem.

Oh, and important: if you are experimenting with the current Zig head branch (anything newer than 0.7.1), please use this branch instead:

https://github.com/floooh/sokol-zig/tree/zig-0.8.0

This removes most build.zig header path hacks that were necessary for 0.7.1, and also doesn't require setting an environment variable in the terminal session (e.g. it should work out of the box):

https://github.com/floooh/sokol-zig/blob/zig-0.8.0/build.zig

Cheers!

floooh commented 3 years ago

PS: Can you post the error messages, Zig and Xcode version you are using? Maybe things have changed again in newer Zig HEAD versions which I haven't noticed yet. I'm currently using a Zig version installed with brew install zig --HEAD on 2021-03-31 (which builds directly from the zig repository), and Xcode 12.4.

...and for this config I need to switch to the zig-0.8.0 branch in sokol-zig for the compilation to work.

floooh commented 3 years ago

Both zig 0.8.0 and the current 0.9.0 dev version are now working on macOS (there have been numerous fixes both in Zig, and also in the brew recipe for zig).

meshula commented 3 years ago

Thanks for the update ~ my apologies for not getting back to you ~ I had to shift focus and time flew by... I look forward to trying this again.