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

Add WebAssembly support #611

Merged
merged 4 commits into from
Jan 28, 2022
Merged

Add WebAssembly support #611

merged 4 commits into from
Jan 28, 2022

Conversation

flupke
Copy link
Contributor

@flupke flupke commented Jan 27, 2022

What changed

  • add support for the wasm32-unknown-emscripten target
  • add an example to run it

Note it's the very first time I write Rust code, please don't hesitate to educate me in this review :)

Why?

To fix #39 and because we needed this for https://jitter.video/ (rebuilding our rendering engine in Rust).

How to test

Follow the instructions I added in the top-level README and in wasm-example/ (not sure this is the right location).

README.md Show resolved Hide resolved
@ctrlcctrlv
Copy link
Contributor

Fantastic news. Sorry to bother but do you think it can compile https://github.com/MFEK/glif/? That's also a way to test the target. Emscripten has SDL2 native support, why I chose it.

@flupke
Copy link
Contributor Author

flupke commented Jan 27, 2022

Fantastic news. Sorry to bother but do you think it can compile https://github.com/MFEK/glif/? That's also a way to test the target. Emscripten has SDL2 native support, why I chose it.

It seems to use skia-safe so... maybe? Though it seems to come with other C dependencies like imgui, so they will need to support wasm32-unknown-emscripten too.

@flupke
Copy link
Contributor Author

flupke commented Jan 27, 2022

Fixed a typo in 70ab149. This is a fixup commit, if this PR is approved, please give me some time to cleanup the branch before merging it 🙏

@pragmatrix
Copy link
Member

Excellent. I got the example running on both ubuntu and macOS. Some notes:

  • In wasm-example/ make build I get the following repetitive warnings on macOS and Ubuntu:
warning: em++: warning: linker setting ignored during compilation: 'EXPORTED_RUNTIME_METHODS' [-Wunused-command-line-argument]
warning: em++: warning: linker setting ignored during compilation: 'ERROR_ON_UNDEFINED_SYMBOLS' [-Wunused-command-line-argument]
warning: em++: warning: linker setting ignored during compilation: 'MAX_WEBGL_VERSION' [-Wunused-command-line-argument]
warning: em++: warning: linker setting ignored during compilation: 'MODULARIZE' [-Wunused-command-line-argument]

Should we be concerned or are these just relevant for emscripten < 3.1.1?

  • When I started the example locally with Chrome on the MacBook, the circle showed a very slow framerate (around 10 fps) when moving the mouse, but that did not happen when I used port forwarding and ran it on Windows.

@flupke If you'd like to, add yourself to the "Notable Contributions" section in the README.md and also add the webassembly example to the "Examples" section with a link to wasm-example/README.md.

README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
skia-safe/examples/gl-window/main.rs Show resolved Hide resolved
@flupke
Copy link
Contributor Author

flupke commented Jan 27, 2022

  • In wasm-example/ make build I get the following repetitive warnings on macOS and Ubuntu:
warning: em++: warning: linker setting ignored during compilation: 'EXPORTED_RUNTIME_METHODS' [-Wunused-command-line-argument]
warning: em++: warning: linker setting ignored during compilation: 'ERROR_ON_UNDEFINED_SYMBOLS' [-Wunused-command-line-argument]
warning: em++: warning: linker setting ignored during compilation: 'MAX_WEBGL_VERSION' [-Wunused-command-line-argument]
warning: em++: warning: linker setting ignored during compilation: 'MODULARIZE' [-Wunused-command-line-argument]

Should we be concerned or are these just relevant for emscripten < 3.1.1?

Yes EMCC_FLAGS is used for both link and compilation, and I don't see more specialized env vars here: https://emscripten.org/docs/tools_reference/emcc.html#environment-variables

I don't think putting these flags in the rust build script is a good idea, since e.g. ERROR_ON_UNDEFINED_SYMBOLS is a workaround for specific emscripten versions.

So I guess we're stuck with these warnings, unfortunately.

  • When I started the example locally with Chrome on the MacBook, the circle showed a very slow framerate (around 10 fps) when moving the mouse, but that did not happen when I used port forwarding and ran it on Windows.

Interesting, which browser / version were you using? (someone told me Safari doesn't support WebGL 2, maybe that's related?)

@etiennealbert could you run some tests please?

@flupke If you'd like to, add yourself to the "Notable Contributions" section in the README.md and also add the webassembly example to the "Examples" section with a link to wasm-example/README.md.

Thanks! done in c618382

@pragmatrix
Copy link
Member

Interesting, which browser / version were you using?

Latest Chrome Version 97.0.4692.99 (Official Build) (x86_64)

Build is working with emscripten 3.1.1, but requires setting some
environment variables:

    EMCC_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" EMSDK=~/.asdf/installs/emsdk/3.1.1 cargo build --target wasm32-unknown-emscripten

ERROR_ON_UNDEFINED_SYMBOLS is a workaround for:

    warning: ___gxx_personality_v0 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library

This error appeared with emscripten 2.0.10 and has yet to be fixed in
rust: rust-lang/rust#85821 (comment)

EMSDK is for building skia-bindings against emscripten's platform
includes.

This is adapted from https://github.com/tuxmark5/rust-skia.
The cargo run option is --features, not --feature
@pragmatrix
Copy link
Member

This looks ready. Thank you a lot for your contribution @flupke. I'll add web-assembly CI builds later. Merging.

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.

Support WebAssembly
3 participants