Skip to content

Commit

Permalink
chore(example): allow running triangle example on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz committed Sep 28, 2023
1 parent 7e12395 commit d35bfa6
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
run-wasm = ["run", "--release", "--package", "run-wasm", "--"]
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"fast3d-glium-renderer",
"fast3d-wgpu-renderer",
"examples/*",
"run-wasm",
]
default-members = [
"examples/*",
Expand Down Expand Up @@ -56,4 +57,13 @@ async-executor = "1"
pigment64 = "0.3.0"
nohash-hasher = "0.2.0"

# wasm32 dependencies
console_error_panic_hook = "0.1.7"
console_log = "1"
js-sys = "0.3.64"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4.34"
wasm-bindgen-test = "0.3"
web-sys = "0.3.64"

[patch.crates-io]
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ Check out the examples folder for some examples of how to use the library.

_Looking for a solution that includes this, windowing, audio and controller input? Check out [Helix](https://github.com/retrofoundry/helix)!._

## Examples

### Triangle
```bash
cargo run --bin triangle
```

To run on web (requires browser with WebGPU support) you can use:
```bash
RUSTFLAGS=--cfg=web_sys_unstable_apis cargo run-wasm --bin triangle
```

## Community

[![](https://dcbadge.vercel.app/api/server/nGckYNTp4w)](https://discord.gg/nGckYNTp4w)
21 changes: 21 additions & 0 deletions examples/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,25 @@ wgpu.workspace = true
env_logger.workspace = true
winit.workspace = true
pollster.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-executor.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook.workspace = true
console_log.workspace = true
js-sys.workspace = true
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
#hal = { workspace = true, optional = true }
# We need these features in the framework examples and tests
web-sys = { workspace = true, features = [
"Location",
"Blob",
"RequestInit",
"RequestMode",
"Request",
"Response",
"WebGl2RenderingContext",
"CanvasRenderingContext2d"
] }
Loading

0 comments on commit d35bfa6

Please sign in to comment.