From a4597a9c143c678446d9cd4c634a2d08ad60bb36 Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Sun, 12 May 2024 16:53:59 -0400 Subject: [PATCH] bevy_asset: Add missing web-sys feature and cleanup unused ones (#13281) # Objective - **Describe the objective or issue this PR addresses.** `bevy_asset` includes code [here](https://github.com/bevyengine/bevy/blob/4350ad0bd184dc94bc7f2d0d076a3482950dfe8c/crates/bevy_asset/src/io/wasm.rs#L61) that references `web_sys::WorkerGlobalScope`. However, `bevy_asset` does not enable this feature, see [here](https://github.com/bevyengine/bevy/blob/4350ad0bd184dc94bc7f2d0d076a3482950dfe8c/crates/bevy_asset/Cargo.toml#L50). Running examples does not catch this problem because the feature is implicitly included by `wgpu` when `bevy_render` is also a dependency, see [bevy_render](https://github.com/bevyengine/bevy/blob/4350ad0bd184dc94bc7f2d0d076a3482950dfe8c/crates/bevy_render/Cargo.toml#L73-L80) and [wgpu](https://github.com/gfx-rs/wgpu/blob/3b6112d45de8da75e47270fe3b0329e5d5166585/wgpu/Cargo.toml#L201). This results in compile errors for environments that are not using `bevy_render`. To reproduce the problem, try to build the crate individually for wasm targets by running `cargo build -p bevy_asset --target wasm32-unknown-unknown`. Running `cargo tree -e features --target wasm32-unknown-unknown` helped diagnose the issue. ## Solution - **Describe the solution used to achieve the objective above.** This PR adds the `WorkerGlobalScope` feature to the `web-sys` portion of `bevy_asset`'s `Cargo.toml`. It also seems to be the case that `bevy_asset` no longer needs the `Request` feature, since no code for `Request` is present anymore. I confirmed that building the crate individually for wasm succeeds without the feature, so that change is also included here. This is a little off-topic, but the repository would probably benefit from some automation around these types of changes, but I'm not sure what would work there. For example, building each crate individually for some key targets would work, but is...well, a lot. Happy to follow up if there is agreement on a good direction. ## Testing - **Did you test these changes? If so, how?** - **How can other people (reviewers) test your changes? Is there anything specific they need to know?** Building the crate individually for wasm by running `cargo build -p bevy_asset --target wasm32-unknown-unknown`. - **Are there any parts that need more testing?** I don't believe so. --- crates/bevy_asset/Cargo.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_asset/Cargo.toml b/crates/bevy_asset/Cargo.toml index c0ce99bacd9af..e380be18b287a 100644 --- a/crates/bevy_asset/Cargo.toml +++ b/crates/bevy_asset/Cargo.toml @@ -47,7 +47,11 @@ bevy_winit = { path = "../bevy_winit", version = "0.14.0-dev" } [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = { version = "0.2" } -web-sys = { version = "0.3", features = ["Request", "Window", "Response"] } +web-sys = { version = "0.3", features = [ + "Window", + "Response", + "WorkerGlobalScope", +] } wasm-bindgen-futures = "0.4" js-sys = "0.3"