Skip to content

Commit a66cedd

Browse files
authored
Fix bevy_remote not compiling on wasm (#23367)
# Objective - Make it possible to enable `bevy_remote` feature on wasm target without the `bevy_remote/http` feature (which doesn't compile on wasm), thus allowing to use the transport-agnostic `RemotePlugin`. - Retain behavior of `bevy_remote` having the `bevy_remote/http` feature by default on non-wasm targets, so no breaking changes for users. ## Solution - Disable default features (so no `http`) in `bevy_internal/bevy_remote`. - Enable default features (including `http`) on non-wasm builds in `bevy_internal/bevy_remote`. - Fix `bevy_remote` having some dependencies only used by the HTTP transport (and not wasm-compatible) not under the `http` feature flag. ## Testing Tested locally with a temporary example not included in this PR that enabled `bevy_remote`, added `RemotePlugin` but not `RemoteHttpPlugin`, and verified that it compiled for both native and wasm targets, as well as building the other bevy_remote examples on native. --- Try yourself by creating a new crate with the following dependencies on `Cargo.toml`: ```toml [dependencies] bevy = { git = "https://github.com/splo/bevy.git", branch = "fix-bevy_remote-wasm", features = [ "bevy_remote", ] } ``` Add the following to `main.rs`: ```rust use bevy::{prelude::*, remote::RemotePlugin}; fn main() { App::new().add_plugins(DefaultPlugins).add_plugins(RemotePlugin::default()).run(); } ``` And build both for native and wasm targets to verify it compiles successfully. ```shell cargo build --target wasm32-unknown-unknown # Fails on main branch. cargo build ```
1 parent 535cf40 commit a66cedd

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

crates/bevy_internal/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,10 @@ bevy_input_focus = { path = "../bevy_input_focus", optional = true, version = "0
532532
bevy_pbr = { path = "../bevy_pbr", optional = true, version = "0.19.0-dev" }
533533
bevy_picking = { path = "../bevy_picking", optional = true, version = "0.19.0-dev" }
534534
bevy_settings = { path = "../bevy_settings", optional = true, version = "0.19.0-dev" }
535-
bevy_remote = { path = "../bevy_remote", optional = true, version = "0.19.0-dev" }
535+
bevy_remote = { path = "../bevy_remote", optional = true, version = "0.19.0-dev", default-features = false, features = [
536+
"bevy_asset",
537+
"bevy_render",
538+
] }
536539
bevy_render = { path = "../bevy_render", optional = true, version = "0.19.0-dev" }
537540
bevy_world_serialization = { path = "../bevy_world_serialization", optional = true, version = "0.19.0-dev" }
538541
bevy_scene2 = { path = "../bevy_scene2", optional = true, version = "0.19.0-dev" }
@@ -554,6 +557,10 @@ bevy_winit = { path = "../bevy_winit", optional = true, version = "0.19.0-dev",
554557
[target.'cfg(target_os = "android")'.dependencies]
555558
bevy_android = { path = "../bevy_android", version = "0.19.0-dev", default-features = false }
556559

560+
# Only enable bevy_remote/http (default features) on non-WASM targets.
561+
[target.'cfg(not(target_family = "wasm"))'.dependencies]
562+
bevy_remote = { path = "../bevy_remote", version = "0.19.0-dev", default-features = true, optional = true }
563+
557564
[lints]
558565
workspace = true
559566

crates/bevy_remote/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ keywords = ["bevy"]
1010

1111
[features]
1212
default = ["http", "bevy_asset", "bevy_render"]
13-
http = ["dep:async-io", "dep:smol-hyper", "bevy_tasks/async-io"]
13+
http = [
14+
"dep:async-io",
15+
"dep:hyper",
16+
"dep:smol-hyper",
17+
"dep:http-body-util",
18+
"bevy_tasks/async-io",
19+
]
1420
bevy_asset = ["dep:bevy_asset"]
1521
bevy_render = ["dep:bevy_render"]
1622

@@ -37,16 +43,16 @@ bevy_log = { path = "../bevy_log", version = "0.19.0-dev" }
3743

3844
# other
3945
anyhow = "1"
40-
hyper = { version = "1", features = ["server", "http1"] }
4146
serde = { version = "1", features = ["derive"] }
4247
serde_json = "1.0.140"
43-
http-body-util = "0.1"
4448
async-channel = "2"
4549

4650
# dependencies that will not compile on wasm
4751
[target.'cfg(not(target_family = "wasm"))'.dependencies]
4852
async-io = { version = "2", optional = true }
53+
hyper = { version = "1", optional = true, features = ["server", "http1"] }
4954
smol-hyper = { version = "0.1", optional = true }
55+
http-body-util = { version = "0.1", optional = true }
5056

5157
[lints]
5258
workspace = true

0 commit comments

Comments
 (0)