Is it possible to use Rapier compiled to WASM outside the context of a Browser/ a JS runtime?
I'm experimenting with a homegrown game engine and I'd like to make it modular, where each individual module is compiled to WASM and then loaded at runtime, and as the physics engine module I'd love to use Rapier, but I haven't been able to make it work. I honestly haven't even been able to successfully compile Rapier to WASM, this is what I've done:
cargo build --target wasm32-unknown-unknown --release --features "wasm-bindgen" --package "rapier3d"
Then in target/wasm32-unknown-unknown/release there's a rapier3d.wasm, but inspecting that with wasm2wat shows that the WASM file is basically nothing, this is it in it's entirety:
(module
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
(global $__stack_pointer (mut i32) (i32.const 1048576))
(global (;1;) i32 (i32.const 1048576))
(global (;2;) i32 (i32.const 1048576))
(export "memory" (memory 0))
(export "__data_end" (global 1))
(export "__heap_base" (global 2)))
I also tried this with the WASM file provided in the NPM module, that results in a huge WAT file and lots of exports and imports.
So, what's the command to build Rapier (preferably only 3D) to WASM and is it even possible to use Rapier outside of a Browser/ JS runtime context?
Hi! I never tried targeting WASM directly without wasm-pack. You may try to add crate-type = ["cdylib"] to the [lib] section of crates/rapier3d/Cargo.toml, and then run your build command again. It generates a ~1.5MB WASM file on my machine.
Oops, forgot to mention I already added the crate-type = [ "cdylib" ] to the lib section, otherwise the compilation doesn't work or doesn't generate a *.wasm file (can't remember, it's been a few days)
Are you actually exporting any functions with wasm-bindgen macros?