Skip to content

Added basic support for wasm32-emscripten target #17210

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

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

permutationlock
Copy link
Contributor

@permutationlock permutationlock commented Sep 20, 2023

Inspired by #10836, these additions allow Zig objects and libraries built with the wasm32-emscripten target to link libc and use the std.os interface. These files may then be linked into an Emscripten web app with emcc.

I realize that #10836 is not approved, but I thought that I would at least put this out there. I have used Zig with Emscripten successfully via this patch in a few personal projects (e.g. a work-in-progress websocket/tcp game server or a toy test of threads).

I also realize that Emscripten has a lot of idiosyncracies, and I have only accounted for what I've encountered (e.g. Emscripten libc exports getentropy but not getrandom).

@jedisct1
Copy link
Contributor

This is nice!

But from a practical perspective, how can the output be used without the relevant Javascript bits?

@permutationlock
Copy link
Contributor Author

But from a practical perspective, how can the output be used without the relevant Javascript bits?

Yes, this target is only useful when using emcc as a linker which generates the corresponding JavaScript bindings. Unless I misunderstood the question?

@jedisct1
Copy link
Contributor

Got it, so the emscripten toolchain is still required.

But being able to write code in Zig that can run in browsers (beyond wasm32-freestanding which is very limited) is very cool.

@permutationlock
Copy link
Contributor Author

permutationlock commented Sep 20, 2023

It would be nice to have a wasm browser option that doesn't depend on Emscripten, but as far as I know there aren't any great alternatives other than binding everything yourself. There was some interesting discussion in the recent WASIX issue #17115.

@permutationlock
Copy link
Contributor Author

permutationlock commented Sep 20, 2023

I see that a check is failing, but the error says that the Ninja build system is not found. Is this an issue that I need to fix with my PR or is something else going on?

Also @jedisct1 I just noticed who you are, I use libsodium a lot and it's awesome!

@jedisct1
Copy link
Contributor

Don't worry, the ninja error is not related to your changes.

@andrewrk
Copy link
Member

Thanks!

@andrewrk andrewrk merged commit 6c54ed7 into ziglang:master Sep 22, 2023
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.

3 participants