floooh / sokol-rust

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

Build fails when targeting WebGL2 #10

Closed terrybrash closed 1 year ago

terrybrash commented 1 year ago

Running cargo build --target wasm32-unknown-emscripten --example texcube

...snip
  cargo:warning=In file included from src/sokol/c/sokol_gfx.c:5:
  cargo:warning=src/sokol/c/sokol_gfx.h:3377:2: error: "Please select a backend with SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND"
  cargo:warning=#error "Please select a backend with SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND"
  cargo:warning= ^
  cargo:warning=In file included from src/sokol/c/sokol_gl.c:6:
  cargo:warning=src/sokol/c/sokol_gl.h:2273:2: error: "Please define one of SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!"
  cargo:warning=#error "Please define one of SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!"
  cargo:warning= ^
  cargo:warning=src/sokol/c/sokol_gfx.h:4747:5: error: unknown type name '_sg_buffer_t'; did you mean 'sg_buffer'?
  cargo:warning=    _sg_buffer_t* buffers;
...snip

So it looks like gles2 was removed and gles3 is the backend you're supposed to use when targeting WebGL2.

After changing this line to Gles3, I get new errors:

...snip
  = note: wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glClearBufferfv
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glClearBufferfi
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glClearBufferfv
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glClearBufferiv
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glReadBuffer
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glBlitFramebuffer
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glInvalidateFramebuffer
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glGetStringi
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glRenderbufferStorageMultisample
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glCompressedTexImage3D
          wasm-ld: error: C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\deps\libsokol-983639c8465cc14c.rlib(sokol_gfx.o): undefined symbol: glTexImage3D
          emcc: error: 'C:/Users/Terry/AppData/Local/emsdk/upstream/bin\wasm-ld.exe -o C:\Users\Terry\sokol-rust\target\wasm32-unknown-emscripten\debug\examples\texcube.wasm C:\Users\Terry\sokol-rust\target                                   
...snip
floooh commented 1 year ago

This looks like there's a -sUSE_WEBGL2=1 missing in the Emscripten linker options.

I guess this must be added here somehow:

https://github.com/floooh/sokol-rust/blob/0c9cd9338ad268fc0aa21656032db085d048cde6/build.rs#L256

(e.g. here's the equivalent in one of my C example projects: https://github.com/floooh/pacman.c/blob/ecc4d2fadf16400320c97917ccdb5c833193f151/CMakeLists.txt#L47)

TBH I wasn't actually aware that the build.rs file supports building for Emscripten :)

If you can figure out the solution and provide a PR that would be nice.

terrybrash commented 1 year ago

https://github.com/floooh/sokol-rust/pull/11