floooh / sokol-rust

Rust bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
62 stars 7 forks source link

`wasm-ld` error when using sokol-rust as a library #14

Open terrybrash opened 1 year ago

terrybrash commented 1 year ago

I'm using sokol-rust as a dependency in an application. I have the latest commit to master, as shown in my cargo.lock:

[[package]]
name = "sokol"
version = "0.1.0"
source = "git+https://github.com/floooh/sokol-rust.git#0c3ee4d0aa851f9d7a50e3bd5426d9fd95fda72d"
dependencies = [
 "cc",
]

The project compiles fine when targeting native (Windows and Mac). However, when running cargo build --target wasm32-unknown-emscripten, I get wasm-ld errors:

  = note: wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glClearBufferfv
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glClearBufferfi
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glClearBufferfv
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glClearBufferiv
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glReadBuffer
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glBlitFramebuffer
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glInvalidateFramebuffer
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glGetStringi
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glDeleteSamplers
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glBindSampler
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glBindSampler
          wasm-ld: error: C:\Users\Terry\tsrs\target\wasm32-unknown-emscripten\debug\deps\libsokol-c2aa81c2fa949025.rlib(sokol_gfx.o): undefined symbol: glBindSampler

Creating a build.rs in my project with the following fixes the the errors:

fn main() {
    println!("cargo:rustc-link-arg=-sUSE_WEBGL2");
}

But this was already added to sokol-rust, so I don't understand why it's required in my project as well.

floooh commented 1 year ago

Don't know to be honest, I know next to nothing about cargo or the cc package unfortunately.

terrybrash commented 1 year ago

Same... I'll update this issue if I find out what the problem is.