Skip to content

Upgrade bevy to 0.14.2 - #22

Draft
girtonman wants to merge 4 commits into
bakcxoj:mainfrom
greymattergames:feature/bevy-upgrade
Draft

Upgrade bevy to 0.14.2#22
girtonman wants to merge 4 commits into
bakcxoj:mainfrom
greymattergames:feature/bevy-upgrade

Conversation

@girtonman

@girtonman girtonman commented Nov 14, 2024

Copy link
Copy Markdown

This is my first time working with bevy, rust, and wasm, so I'm all ears for any suggestions or changes to these commits. This is the product of my own attempt at resolving bevy_wasm#20 to get this updated so that it can be used in a game that I'm working on.

Some caveats

  • I was only able to get it working for native by targeting wasi and using some helpful code found in TurboSnailGit's fork.
  • I have not had any success in using mods build for for wasm32-unknown-unknown or getting them to work in a web browser. I wanted to have that fixed before making this PR, but it was out of reach for me.

Some unrelated changes that are also in this PR

  • bevy_wasm_sys has been split into bevy_wasm_sys and bevy_wasm_sys_core. I wasn't sure if this was necessary, but it was code that I picked up along the way from TurboSnailGit's fork. I can push new commits without the split if needed.
  • There is now a makefile with tasks for running the examples rather than running the build.rs file in each of the examples' folders. This was another nice feature that TurboSnailGit had added that I also liked and pulled into my fork.
  • Restructuring the dependencies into workspace dependencies was yet another change that felt nice from TurboSnailGit's fork.

Ironically, the migrations that were part of the bevy upgrade were the most straight forward and easy part of this process. I spent several days repeatedly getting hung up on issues that stemmed from supporting getrandom's needs. I'll make a few branches in my fork that show some of the walls I ran into. There are probably solutions or workarounds I'm unaware of that might be obvious to people with more experience in this stack.

I'm not strongly attached to the change to wasi, and would be okay with switching it back to wasm32-unknown-unknown for native. I would need some help getting this PR to that point though.

Largely based off of work on @TurboSnailGit's fork (with some minor alterations) that I found while troubleshooting some getrandom issues when upgrading

This commit accomplishes a few things that were hard to separate into smaller commits:
 - Moves build commands and parameters out of code and into config
 - Adds the ability to call `cargo make some-task-here` from the project root instead of naviating to each example's folder to run `cargo run -p some_module`
 - Split bevy_wasm_sys into bevy_wasm_sys and bevy_wasm_sys_core. Quoting @TurboSnailGit: bevy_wasm_sys_core does not contain any reference to Bevy. This is for sample cube_without_bevy. Features are additive in Rust and cannot be used to toggle a feature on and off, they need to be in separate crate if you need them off.
These are the relevant migration changes from 0.10 to 0.14
 - Bevy no longer re-exports TypeUuid and are moving towards TypePath in places where TypeUuid was previously used. To keep things simple, this commit just switches over to using the uuid and type-uuid crates
 - Messages for EventReader must have the Event trait now
 - .add_system has been removed. Now we must use .add_systems and provide a first argument specifying the Schedule(s). The old default was Update, so that is what is used here.
 - .add_asset has been changed to .init_asset
 - Asset loading no longer requires BoxedFutures and has been simplified
 - Assets must have type paths now. Simple fix is to derive TypePath
 - EventReader::iter is now EventReader.read
 - App runners must now return an AppExit
 - .add_startup_system has been removed. We need to use add_systems with a Schedule of Startup
 - Creating a plane mesh has changed slightly
 - Defining colors has changed slightly
 - Creating a cube mesh has changed slightly
 - .add_plugin has been deprecated in favor of allowing tuples and single plugins in .add_plugins
The combination of wasm-bindgen and getrandom (which is unavoidable due to bevy relying on ahash which relies on getrandom) was causing linking function issues that I wasn't able work around. Admittedly, I'm very green when it comes to rust and to wasm, but I was able to bypass the issues by implementing changes that @TurboSnailGit had made in their fork.

The magic sauce was:
    let mut linker: Linker<WasiModState> = Linker::new(engine);
    wasi_common::sync::add_to_linker(&mut linker, |s| &mut s.wasi_ctx)?;

which solved my import woes with wasm-bindgen and getrandom since it would handle all of the importing of definitions
@girtonman
girtonman force-pushed the feature/bevy-upgrade branch from dc9a0fb to fcdfa0a Compare November 20, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant