Skip to content
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

wasm support #18

Open
extrawurst opened this issue Jun 26, 2023 · 4 comments
Open

wasm support #18

extrawurst opened this issue Jun 26, 2023 · 4 comments

Comments

@extrawurst
Copy link

if I try to build my project for wasm using bevy_tokio_tasks it generates an error:

compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.");

is it possible to use the plain rt instead of the multithreaded runtime?

@EkardNT
Copy link
Owner

EkardNT commented Jul 13, 2023

I have attempted to add wasm32-unknown-unknown target support to version 0.11.0 of this crate which was just published. The rt feature will be used instead of the rt-multi-thread feature on wasm32 architecture and a current_thread Runtime will be configured instead of a multi-thread Runtime. However, I don't have a project currently set up to fully test out the wasm32 support. Can you please upgrade to version 0.11.0 of this crate in your project and let me know whether it works for you?

@extrawurst
Copy link
Author

extrawurst commented Jul 14, 2023

it gets me further but a blocker is now that we expect futures to be Send which they do not have to be when target is wasm as everything is single threaded then. see similar issue here: ramsayleung/rspotify#292

this might be a blocker because bevy requires this aswell right now for Plugin and Resource :(

@tekacs
Copy link

tekacs commented Aug 31, 2023

Thanks for attempting to support WASM, @EkardNT!

CleanShot 2023-08-31 at 00 41 52

Since I have a WASM project set up I'm able to test things and... I've found that attempting to add the plugin on wasm32-unknown-unknown in the browser fails, I think because of:

self.0.runtime.block_on(async {

which is called from:

runtime.execute_main_thread_work(world, current_tick);

... since you can't really block on WASM. In particular the stack tops out with:

CleanShot 2023-08-31 at 00 44 07

So all of that being said I'm not certain whether there's a sensible way to run the behavior that this plugin is looking for in this WASM environment, but I'll try to take a look myself soon for one thing.

@tekacs
Copy link

tekacs commented Aug 31, 2023

I threw together a quick version based on wasm_bindgen_futures that supports !Send futures but doesn't return a JoinHandle<Output> at https://github.com/tekacs/bevy-wasm-tasks / https://crates.io/crates/bevy-wasm-tasks

I might take a stab at an async_executors version to see if that is any more straightforward/consistent at all.

Update: It looks async_executors would prove fairly fiddly as object-safe spawners require the Spawn<T> type to name the output types of every JoinHandle<T>, so I've just gone with the wasm_bindgen_futures version for now.

Happy to re-integrate if there's a straightforward path here. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants