[WASM-Export] Unable to use multiple rust GDExtensions at the same time
- Dominant language
- Rust
- Stars
- 5.2k
- Forks
- 312
- Avg merge
- 12h 59m
- Merged PRs (30d)
- 9
Description
Hi,
Lately I've been working on a bigger game, and completed the refactor from C# to C++ and then I found this amazing library so I switched one more time to Rust.
Now, what I've had in mind was that I'd create a Shared, Client and Server project in Rust. Shared would have the Nodes that both projects need and Client and Server would be implementing the multiplayer features.
I created the following setup:
- godot (Godot Project)
- rust (Rust workspace)
- client (Rust project)
- server (Rust project)
- shared (Rust project)
Note: The `client` nor `server` projects do not depend on `shared` in `Cargo.toml`.
This setup is working terrific! I'm able to implement client specific features, and server specific features which will be connected using the shared nodes.
I can run this on my Linux machine, and confirm that it is working. However, I also target `wasm` so I tried getting that to work. Now, this isn't really working out.
I compile the workspace with `cargo +nightly build -Zbuild-std --target wasm32-unknown-emscripten` to WebAssembly, and this is going really well. But when I run the project, on Firefox I get an `out of memory` emscripten error (which it also does with a single Rust project, but only on Debug builds). When I run it on Chromium however, I get a big list of errors:
```
RuntimeError: Aborted(undefined). Build with -sASSERTIONS for more info.
at abort (tmp_js_export.js:9:8604)
at ___cxa_throw (tmp_js_export.js:9:425328)
at shared.wasm.panic_unwind::imp::panic::h7a89a72211144e04 (shared.wasm-10a1508e:0x42b504)
at shared.wasm.__rust_start_panic (shared.wasm-10a1508e:0x42b367)
at shared.wasm.rust_panic (shared.wasm-10a1508e:0x41d2e3)
at shared.wasm.std::panicking::rust_panic_with_hook::hc3a8cd21f77927d3 (shared.wasm-10a1508e:0x41d1d9)
at shared.wasm.std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::hb19be6fa9857ee61 (shared.wasm-10a1508e:0x41a5f5)
at shared.wasm.std::sys::backtrace::__rust_end_short_backtrace::h585b6ab617e4600a (shared.wasm-10a1508e:0x41a4bd)
at shared.wasm.rust_begin_unwind (shared.wasm-10a1508e:0x41c2a1)
at shared.wasm.core::panicking::panic_fmt::he773db1f33281f18 (shared.wasm-10a1508e:0x49a208)
| onPrintError | @ | tmp_js_export.js:477
-- | -- | -- | --
| abort | @ | tmp_js_export.js:9
| ___cxa_throw | @ | tmp_js_export.js:9
| $panic_unwind::imp::panic::h7a89a72211144e04 | @ | shared.wasm-10a1508e:0x42b504
| $__rust_start_panic | @ | shared.wasm-10a1508e:0x42b367
| $rust_panic | @ | shared.wasm-10a1508e:0x41d2e3
| $std::panicking::rust_panic_with_hook::hc3a8cd21f77927d3 | @ | shared.wasm-10a1508e:0x41d1d9
| $std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::hb19be6fa9857ee61 | @ | shared.wasm-10a1508e:0x41a5f5
| $std::sys::backtrace::__rust_end_short_backtrace::h585b6ab617e4600a | @ | shared.wasm-10a1508e:0x41a4bd
| $rust_begin_unwind | @ | shared.wasm-10a1508e:0x41c2a1
| $core::panicking::panic_fmt::he773db1f33281f18 | @ | shared.wasm-10a1508e:0x49a208
| $godot_ffi::binding::single_threaded::BindingStorage::set_initialized::haf88d1160aa08dd6 | @ | shared.wasm-10a1508e:0x3a7ebd
| $godot_ffi::binding::single_threaded::BindingStorage::initialize::h06c546cc4398088b | @ | shared.wasm-10a1508e:0x3a7f1e
| $godot_ffi::binding::initialize_binding::hec449e30c65edce2 | @ | shared.wasm-10a1508e:0x3b4174
| $godot_ffi::initialize::hd3864843f056cfd2 | @ | shared.wasm-10a1508e:0x3b53dc
| $godot_core::init::__gdext_load_library::_$u7b$$u7b$closure$u7d$$u7d$::h80e68cd7c7203dc9 | @ | shared.wasm-10a1508e:0x66696
| $core::ops::function::FnOnce::call_once::h50d84be8fa3c9798 | @ | shared.wasm-10a1508e:0x70136
| $std::panicking::try::do_call::h64bb311ea799ec2a | @ | shared.wasm-10a1508e:0x741fb
| $__rust_try | @ | shared.wasm-10a1508e:0x734d8
| $std::panicking::try::hcbde3b6f2bb9e296 | @ | shared.wasm-10a1508e:0x74088
| $std::panic::catch_unwind::h4d4f243b6b7cf82f | @ | shared.wasm-10a1508e:0x72b00
| $godot_core::private::handle_panic_with_print::h28362aa50547f00d | @ | shared.wasm-10a1508e:0x596e6
| $godot_core::private::handle_panic::h7e38a629003b6b68 | @ | shared.wasm-10a1508e:0x59400
| $godot_core::init::__gdext_load_library::h65f7301edd9aa8a6 | @ | shared.wasm-10a1508e:0x66521
| $gdext_rust_init | @ | shared.wasm-10a1508e:0x5616f
| $func58011 | @ | 0aaeb74a:0x2599747
| $func58034 | @ | 0aaeb74a:0x259dff6
| $func51263 | @ | 0aaeb74a:0x2466843
| $func51313 | @ | 0aaeb74a:0x246c885
| $func34708 | @ | 0aaeb74a:0x19938e1
| $func1310 | @ | 0aaeb74a:0x4c7148
| $func1212 | @ | 0aaeb74a:0x431bc4
| $_Z14godot_web_mainiPPc | @ | 0aaeb74a:0x2cfd7e
| __Z14godot_web_mainiPPc | @ | tmp_js_export.js:9
| $__main_argc_argv | @ | 006438ee:0xa5975
| callMain | @ | tmp_js_export.js:9
| (anonymous) | @ | tmp_js_export.js:804
| (anonymous) | @ | tmp_js_export.js:799
| Promise.then | |
| start | @ | tmp_js_export.js:778
| (anonymous) | @ | tmp_js_export.js:837
| Promise.then | |
| startGame | @ | tmp_js_export.js:836
| (anonymous) | @ | tmp_js_export.html:181
| (anonymous)
```
I've tried using different entry point names using
```
struct SharedExtension;
#[gdextension(entry_symbol = gdext_shared_rust_init)]
unsafe impl ExtensionLibrary for SharedExtension {}
```
Which doesn't work. As soon as I remove the other extensions (so I leave `shared.gdextension`) it starts working again.
I use these Emscripten compile flags:
```
[target.wasm32-unknown-emscripten]
rustflags = [
"-C", "link-args=-sSIDE_MODULE=2",
"-C", "link-args=-pthread", # was -sUSE_PTHREADS=1 in earlier emscripten versions
"-C", "target-feature=+atomics,+bulk-memory,+mutable-globals",
"-Zlink-native-libraries=no",
"-Cllvm-args=-enable-emscripten-cxx-exceptions=0",
]
```
I also created two projects to recreate the issue:
[single-rust-project.zip](https://github.com/user-attachments/files/18115972/single-rust-project.zip)
[multiple-rust-project.zip](https://github.com/user-attachments/files/18115974/multiple-rust-project.zip)
I'm really eager to help this project move forward, and I would say I'm quite well-versed in WebAssembly, however I have no idea where to get started. I tried enabling `-sASSERTIONS` and `-sASSERTIONS=2` but this gives me a `resolved is not a function error` so no dice...
Any tips are very welcome, and if you need more information please let me know!
Thank you for the amazing work on this library, it's awesome!
Kind regards,
Contributor guide
Assessment
This issue has not been assessed yet.