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

Compile error with wasm #495

Open
kripken opened this issue Feb 2, 2022 · 3 comments
Open

Compile error with wasm #495

kripken opened this issue Feb 2, 2022 · 3 comments

Comments

@kripken
Copy link

kripken commented Feb 2, 2022

I am trying to build the minimal example from the readme to wasm. By default it tries to build glfw using cmake, and that doesn't seem to work properly in terms of cross-compiling:

$ cargo build --target wasm32-unknown-unknown
[..]
    The C compiler

      "/usr/bin/clang"

    is not able to compile a simple test program.
[..]
      Linking C executable cmTC_77bbe
      /usr/bin/clang  -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown  CMakeFiles/cmTC_77bbe.dir/testCCompiler.c.o -o cmTC_77bbe 
      wasm-ld: error: cannot open crt1.o: No such file or directory
      wasm-ld: error: unable to find library -lc
      wasm-ld: error: unable to find library -lgcc
      clang: error: linker command failed with exit code 1 (use -v to see invocation)

Next I tried with default-features = false in Cargo.toml, and I get this error:

$ cargo build --target wasm32-unknown-unknown
   Compiling glfw v0.43.0 (https://github.com/bjz/glfw-rs.git#5298cfc6)
error[E0308]: mismatched types
    --> /home/azakai/.cargo/git/checkouts/glfw-rs-9212cdc098378853/5298cfc/src/lib.rs:2903:50
     |
2903 | fn raw_window_handle<C: Context>(context: &C) -> RawWindowHandle {
     |    -----------------                             ^^^^^^^^^^^^^^^ expected enum `RawWindowHandle`, found `()`
     |    |
     |    implicitly returns `()` as its body has no tail or `return` expression

For more information about this error, try `rustc --explain E0308`.
error: could not compile `glfw` due to previous error
@torcoste
Copy link

torcoste commented Jun 3, 2022

As far as I know GLFW is an OpenGL library, but you can only use WebGL with WebAssembly.
So I'm not sure you can do that.

For WebGL wasm example, please see this: https://rustwasm.github.io/wasm-bindgen/examples/webgl.html

@coderedart
Copy link
Contributor

I don't think you can compile rust + C bindings to wasm. there's an ABI issue and fixing it breaks backwards compatibility apparently. more info rustwasm/wasm-bindgen#2209

@coderedart
Copy link
Contributor

glfw + wasm-emscripten works with a small patch.

deployed version -> https://coderedart.github.io/egui_glow_glfw_emscripten/
code -> https://github.com/coderedart/egui_glow_glfw_emscripten/

the patch to make glfw-rs compile on emscripten target -> #531
you can then compile it to emscripten by using default-features = false to avoid glfw-sys. instead glfw symbols are provided by emscripten itself.

emscripten is using glfw 3.2, so we will obviously miss some methods like content scale or window hint string from glfw 3.3, but atleast the rest work fine.

once the patch is merged, i think this issue can be closed.

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

No branches or pull requests

3 participants