-
Notifications
You must be signed in to change notification settings - Fork 235
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
Using trunk with wasm_thread #680
Comments
Trunk is "just" a build tool for Rust based WebAssembly applications (for the browser). In general, I think that should work with Maybe people can easier help if there would be a reproducer for this. |
Thank you for you reply. To compile wasm_thread, you need to enable some experimental flags and recompile the standard library with atomics enable. Example from the wasm_thread example:
The problem is, I think the Is it possible to recompile the standard library when building using trunk (passing the P.S.: This repo contains my latest attempts at a minimal example (note: I am also trying to build this using nix crane) |
I don't think that's possible … yet! It might make sense to add that using a |
So according to the cargo documentation, you can already do this with cargo alone: https://doc.rust-lang.org/cargo/reference/unstable.html
So, I am not sure there's anything for trunk to do TBH. |
Ok, I think I know what the problem is. Trunk creates the bootstrapper for the wasm initialization. And wasm_thread requires a specific entry point to be called:
That's currently not happening. But I am sure we could add this. |
I have updated my minimal example test repo.
I think I tried this before and it didn't work, so I tried it again... and it now works! 😵💫 (Or rather it compiles) When I run the test application (using
The error seems to me to be exactly the issue you are describing.
That would be great. I think being able to run multi-threaded code using "native |
However, the result will not be that. |
Ok, digging a bit more into this: It looks like it creates a new worker, and then tries to send over the "memory" of the original WASM module. Which feels kind of weird. And it looks like the browser actually prevents that. Things can be sent to other web workers, but not everything: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm Sending the memory handle might work, but only when the WebAssembly memory was initialized as "shared": https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format#shared_memories There's another crate with a similar approach: https://github.com/RReverser/wasm-bindgen-rayon … however, it also requires a nightly compiler from 2022. It seems to be around the flag of |
For me, the main benefit of
I'll try fiddling with it a bit more, if I get anywhere, I'll share my progress here. |
I would like to use the wasm_thread library inside of a trunk project, but I was unable to create a functioning test application using the two.
I tried to splice together the trunk cdylib example with and example from the wasm_thread repo, but couldn't get it to work.
My latest attempt built successfully, when run, panics
called Result::unwrap() on an Err value: JsValue(DataCloneError: WebAssembly. Memory object could not be cloned
.I am not very knowledgeable with trunk, but I have successfully used wasm_thread with wasm-pack in the past.
Are there any examples on how to use trunk with the wasm_thread library?
The text was updated successfully, but these errors were encountered: