Upgrade bevy to 0.14.2 - #22
Draft
girtonman wants to merge 4 commits into
Draft
Conversation
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
force-pushed
the
feature/bevy-upgrade
branch
from
November 20, 2024 15:29
dc9a0fb to
fcdfa0a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Some unrelated changes that are also in this PR
bevy_wasm_syshas been split intobevy_wasm_sysandbevy_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.build.rsfile in each of the examples' folders. This was another nice feature that TurboSnailGit had added that I also liked and pulled into my 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.