Commit a66cedd
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
535 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
536 | 539 | | |
537 | 540 | | |
538 | 541 | | |
| |||
554 | 557 | | |
555 | 558 | | |
556 | 559 | | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
557 | 564 | | |
558 | 565 | | |
559 | 566 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
| |||
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | | - | |
41 | 46 | | |
42 | 47 | | |
43 | | - | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| 53 | + | |
49 | 54 | | |
| 55 | + | |
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| |||
0 commit comments