-
Notifications
You must be signed in to change notification settings - Fork 953
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
feature: emscripten #2422
feature: emscripten #2422
Conversation
286f4ac
to
1beff75
Compare
4d47ad6
to
ad6d5d9
Compare
Mark it as draft until fully test it on vaners + librusty_vangers |
ad6d5d9
to
f6db1a6
Compare
f6db1a6
to
1d1606e
Compare
Tested, works fine |
We'll probably need a separate section in README about all the ways this can be compiled for the Web |
@kvark Regarding to emscripten, I think it's will be very handy for projects that use wgpu-native. Since this projects are on C++ and use Rust to render, they can't be ported to web until this PR. Because you can't merge 2 Modules into one (from emscripten, and from wasm32-unknown-unknown). But now, it's super simple: compile both with emscripten and link wgpu-native statically or dynamically and it will work. So for emscripten, I think we can try to compile examples from wgpu-native. Or I think it's better we can create simple SDL1/2+wgpu-native project and write tutorial how to compile it. Because I think SDL1/2 is widely used and have first class support from emscripten. |
Also I can do announcement in emscripten channels about this template (SDL+wgpu) |
Yes, I'm totally with you on this. C-based projects would be able to target WebGL via webgpu-headers, it's a very cool feature. The example code should live in https://github.com/gfx-rs/wgpu-native/ for this. |
This is reimplementation of #2233
--
Added new feature "emscripten", this feature can be used in combination with --target wasm32-unknown-emscripten to build wgpu for emscripten.
raw-gles.rs example now works also with emscripten, to run it:
This PR also adds a workflow to check emscripten build. I think that raw-gles example is only needed example for emscripten integration it also can be a test, but it hard to do it automatically because need to install emcc. I think not worth to doing it.
Typical usage of wgpu and emscripten will be through external gles integration like in raw-gles.rs. Because windows management (like winit) crate not exists for emscripten, so it will be used with some native library like SDL/2+wgpu. SDL will initialize context and controls window/events and wgpu will be used as renderer library.
--
There is 2 identical comments in 2233 that I can't solve:
Ideally we can remove this
#[cfg
because lastelse
is what we actually need. But I can't find good way to jump into last else branch when feature emscripten is set. And egl::EGL1_5 is not defined when feature is emscripten.raw-gles.rs in browser (tested in Chrome an FF):