bevyengine / bevyengine/bevy

WebGPU Compilation Steps

Open
#9,618 0 comments 7 reactions 0 assignees View on GitHub
C-Docs O-WebGPU
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

Hi all,

I think it would be helpful to have a page somewhere in the docs that explains how to compile a bevy app with either (or both) the WebGL2 + WebGPU backends.

After some discussion with people on Discord, I was able to get up-and-running, but the process seems a bit awkward and difficult for new users to figure out on their own. For reference, here are the steps I followed. Maybe this is not the "best" way, but it seems to work OK for my purposes.

First, I added the following to my Cargo.toml file:

```
[dependencies.bevy]
version = "0.11.1"
default-features = false # This bit is important
features = [
"animation",
"bevy_asset",
"bevy_audio",
# ... the rest of the bevy features you need EXCEPT webgl2
]

[features]
webgl2 = ["bevy/webgl2"]
```

I am then able to build for either WebGL2 or WebGPU.

For WebGL2:
```
cargo build --features webgl2 --target wasm32-unknown-unknown
```

For WebGPU:
```
cargo build --target wasm32-unknown-unknown
```

Additionally, when targeting WebGPU, you must have the following environment variable set:
```
RUSTFLAGS=--cfg=web_sys_unstable_apis
```

From here, you can run `wasm-bindgen` on the resulting .wasm file and load it on a webpage as usual.

Perhaps there is a simpler way to convey this information, but I just wanted to get the discussion started and help out anyone else who might be struggling with the same thing.

Contributor guide

Open the contributing guide

Research direction

Start with the Cargo.toml feature example and the WebGL2/WebGPU cargo build commands described in the issue, then check how the resulting .wasm file is passed to wasm-bindgen. Document the setup, the RUSTFLAGS requirement for WebGPU, and the commands for both backends; done means a new user can follow the page to build either target.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
build-system, documentation, web-dev
Issue type
Documentation
Difficulty
2/5
Estimated time
Half a day
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.