Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically include Emscripten headers #173

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

DanielKMach
Copy link
Contributor

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant