Not-Nik / raylib-zig

Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib
MIT License
703 stars 123 forks source link

Automatically include Emscripten headers #173

Closed DanielKMach closed 22 hours ago

DanielKMach commented 1 week ago

When building for the web, Emscripten automatically links a library that allows the program to communicate with the browser, but the headers need to be manually added through the build.zig. This PR updates the emcc.zig compile function to automatically add the necessary headers for Emscripten before returning the step.

The Emscripten functions can then be imported using the following snippet:

const emscripten = if (builtin.os.tag == .emscripten) @cImport(@cInclude("emscripten.h")) else undefined;

Unfortunately, I had to update the compile function to return an error because I couldn't think of a way to assemble the path without allocation.

Examples weren't affected. Tested on Windows 11.

DanielKMach commented 1 week ago

I found a way of getting the path without allocation.

const emcc_path = b.sysroot orelse return lib;
const emscripten_headers = b.pathJoin(&.{ emcc_path, "cache", "sysroot", "include" });

I can revert the last change and apply this solution if you want.