dlom / bevy-async-ecs

Bevy Async ECS
https://docs.rs/bevy-async-ecs
MIT License
18 stars 3 forks source link

wasm support #6

Open databasedav opened 4 months ago

databasedav commented 4 months ago

just wanted to add some tracking for this

However, when the task executor is running on a single thread (on wasm, for example), the async world will probably deadlock. If this is a pain-point for you, please open a GitHub issue.

i believe this is blocked on this PR https://github.com/smol-rs/async-io/pull/153, however, when i update the async-io dependency to

async-io = { git = "https://github.com/smol-rs/async-io", branch = "notgull/web" }

and try to run the basic example following these instructions https://bevy-cheatbook.github.io/platforms/wasm.html, i get the following on when navigating to the served url

on firefox

ERROR app: panicked at /home/avi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.19.1/src/lib.rs:1809:13:
No wgpu backend feature that is implemented for the target platform was enabled. See `wgpu::Instance::any_backend_feature_enabled()` for more information.

Stack:

__wbg_get_imports/imports.wbg.__wbg_new_abda76e883ba8a5f@http://127.0.0.1:1334/api/wasm.js:408:13
__wbg_new_abda76e883ba8a5f externref shim@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[233694]:0x4057f7c
console_error_panic_hook::Error::new::h63df324f7c858bae@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[166912]:0x3cf73a3
console_error_panic_hook::hook_impl::hf766909e468ef70e@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[32286]:0x26e69d3
console_error_panic_hook::hook::hfde64c16164fad88@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[203252]:0x3f23855
core::ops::function::Fn::call::ha1f82010650f515b@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[180579]:0x3de57b9
std::panicking::rust_panic_with_hook::h1e6ac5d404b8e31b@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[67732]:0x30cc5e0
std::panicking::begin_panic_handler::{{closure}}::h24b0f4622f2766a5@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[88845]:0x34a8105
std::sys_common::backtrace::__rust_end_short_backtrace::h19f35d272c126e7c@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[235506]:0x405deda
rust_begin_unwind@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[180984]:0x3dec01c
core::panicking::panic_fmt::h87755523850ece9e@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[195922]:0x3ec4dd7
wgpu::Instance::new::hcdd38eeb57f95ec1@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[73947]:0x320a7d2
<bevy_render::RenderPlugin as bevy_app::plugin::Plugin>::build::{{closure}}::h21bdd6de059d8d5f@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[473]:0x66f133
bevy_tasks::single_threaded_task_pool::TaskPool::spawn::{{closure}}::hac47b39232b39b8a@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[24864]:0x23c1a02
wasm_bindgen_futures::task::singlethread::Task::run::hd49527446ce517a3@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[23592]:0x231d706
wasm_bindgen_futures::queue::QueueState::run_all::h3ad72d2a6d6c3f02@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[15692]:0x1e637e4
wasm_bindgen_futures::queue::Queue::new::{{closure}}::hd683b5a3dbdbb7b9@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[110933]:0x37c4317
<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hd548e900a55de4b4@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[69241]:0x311cd0d
closure40191 externref shim@http://127.0.0.1:1334/api/wasm.wasm:wasm-function[233271]:0x4055a5b
__wbg_adapter_57@http://127.0.0.1:1334/api/wasm.js:222:6
real@http://127.0.0.1:1334/api/wasm.js:171:32

on chrome

ERROR app: panicked at /home/avi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.19.1/src/lib.rs:1809:13:
No wgpu backend feature that is implemented for the target platform was enabled. See `wgpu::Instance::any_backend_feature_enabled()` for more information.

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (http://127.0.0.1:1334/api/wasm.js:408:13)
    at __wbg_new_abda76e883ba8a5f externref shim (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[233694]:0x4057f7c)
    at console_error_panic_hook::Error::new::h63df324f7c858bae (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[166912]:0x3cf73a3)
    at console_error_panic_hook::hook_impl::hf766909e468ef70e (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[32286]:0x26e69d3)
    at console_error_panic_hook::hook::hfde64c16164fad88 (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[203252]:0x3f23855)
    at core::ops::function::Fn::call::ha1f82010650f515b (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[180579]:0x3de57b9)
    at std::panicking::rust_panic_with_hook::h1e6ac5d404b8e31b (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[67732]:0x30cc5e0)
    at std::panicking::begin_panic_handler::{{closure}}::h24b0f4622f2766a5 (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[88845]:0x34a8105)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h19f35d272c126e7c (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[235506]:0x405deda)
    at rust_begin_unwind (http://127.0.0.1:1334/api/wasm.wasm:wasm-function[180984]:0x3dec01c)

i'm not sure if this is actually relevant to this crate, or i'm just doing something wrong, also wasn't able to find anything about the wgpu backend feature stuff

dlom commented 3 months ago

Thank you for your experiments. I will attempt to enable WASM support likely after bevy 0.14 releases in the near future.

databasedav commented 1 month ago

after some investigation, i've discovered that the CommandQueueSender contained by the AsyncWorld is closed within the body of the this future https://github.com/dlom/bevy-async-ecs/blob/a8a7d3c34bb6654cf710c5be2e5d1452777480ce/examples/basic.rs#L16-L25 on wasm, but not on linux

databasedav commented 1 month ago

should be reproducible on this branch https://github.com/databasedav/bevy-async-ecs/tree/wasm_experimenting

run with these

rustup target install wasm32-unknown-unknown
cargo install wasm-server-runner
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-server-runner cargo run --target wasm32-unknown-unknown --example basic

and navigate to the served url

note i also disabled a bunch of bevy features in the dev dependencies here https://github.com/databasedav/bevy-async-ecs/blob/2db817e65142800347897f9783ccef7bbfb75cf9/Cargo.toml#L23-L36, i think winit might have been causing a separate issue

dlom commented 1 month ago

Thanks for your effort, I will try to reproduce myself soon :+1: