Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for non-browser wasm #17499

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bushrat011899
Copy link
Contributor

@bushrat011899 bushrat011899 commented Jan 22, 2025

Objective

Solution

  • Added a new browser feature to bevy_platform_support, bevy_tasks, and bevy_app.
  • Enabled new browser feature automatically within crates without no_std support.

Testing

  • Ran compile-check-no-std with new wasm32v1-none target and wasm32-wasip1 successfully.

Migration Guide

When using Bevy crates which don't automatically enable the browser feature, please enable it when building for the browser.

Notes

  • I added cfg_if to help manage some of the feature gate gore that this extra feature introduces. It's still pretty ugly, but I think much easier to read.
  • Certain wasm targets (e.g., wasm32-wasip1) provide an incomplete implementation for std. I have not tested these platforms, but I suspect Bevy's liberal use of usually unsupported features (e.g., threading) will cause these targets to fail. As such, consider wasm32-unknown-unknown as the only wasm platform with support from Bevy for std. All others likely will need to be treated as no_std platforms.

@bushrat011899 bushrat011899 added C-Feature A new feature, making something new possible O-Web Specific to web (WASM) builds A-Cross-Cutting Impacts the entire engine X-Contentious There are nontrivial implications that should be thought through D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward O-Embedded Weird hardware and no_std platforms labels Jan 22, 2025
@bushrat011899 bushrat011899 changed the title Initial Commit Support for non-browser wasm Jan 22, 2025
@TimJentzsch
Copy link
Contributor

I'd like to test this with the Bevy CLI prototype before we merge this if possible.

Right now, bevy run web works out-of-the box just like native for most projects and I think it's desirable to maintain that if feasible.
Maybe enabling this feature by default is sufficient for that, but I'd like to do some testing

@BenjaminBrienen BenjaminBrienen added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Needs-Testing Testing must be done before this is safe to merge and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 23, 2025
@bushrat011899
Copy link
Contributor Author

Totally reasonable! I personally haven't done much tearing at all with this branch beyond checking compilation works and that CI passes.

Copy link
Contributor

@TimJentzsch TimJentzsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on your branch bevy run --example=breakout web --open and in one of my mini test repos bevy run web --open.
It both still works out of the box! (well, except for porting to Bevy 0.16)

The code looks sensible as well.

crates/bevy_app/Cargo.toml Outdated Show resolved Hide resolved
@TimJentzsch TimJentzsch added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Needs-Testing Testing must be done before this is safe to merge labels Jan 23, 2025
@elliotsayes
Copy link

Beautiful! Looking forward to this getting merged 🚀

github-merge-queue bot pushed a commit that referenced this pull request Feb 5, 2025
# Objective

- Fixes CI failure due to `uuid` 1.13 using the new version of
`getrandom` which requires using a new API to work on Wasm.

## Solution

- Based on [`uuid` 1.13 release
notes](https://github.com/uuid-rs/uuid/releases/tag/1.13.0) I've enabled
the `js` feature on `wasm32`. This will need to be revisited once #17499
is up for review
- Updated minimum `uuid` version to 1.13.1, which fixes a separate issue
with `target_feature = atomics` on `wasm`.

## Testing

- `cargo check --target wasm32-unknown-unknown`
joshua-holmes pushed a commit to joshua-holmes/bevy that referenced this pull request Feb 5, 2025
…7689)

# Objective

- Fixes CI failure due to `uuid` 1.13 using the new version of
`getrandom` which requires using a new API to work on Wasm.

## Solution

- Based on [`uuid` 1.13 release
notes](https://github.com/uuid-rs/uuid/releases/tag/1.13.0) I've enabled
the `js` feature on `wasm32`. This will need to be revisited once bevyengine#17499
is up for review
- Updated minimum `uuid` version to 1.13.1, which fixes a separate issue
with `target_feature = atomics` on `wasm`.

## Testing

- `cargo check --target wasm32-unknown-unknown`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes O-Embedded Weird hardware and no_std platforms O-Web Specific to web (WASM) builds S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WASM cannot build for wasm32-wasi
4 participants