Skip to content

Commit

Permalink
bevy_asset: Add missing web-sys feature and cleanup unused ones (#13281)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
snendev committed May 12, 2024
1 parent 2a799ef commit a4597a9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit a4597a9

Please sign in to comment.