Skip to content

Commit

Permalink
Remove wasm specific examples (#3705)
Browse files Browse the repository at this point in the history
# Objective

- There are wasm specific examples, which is misleading as now it works by default
- I saw a few people on discord trying to work through those examples that are very limited

## Solution

- Remove them and update the instructions
  • Loading branch information
mockersf committed Jan 17, 2022
1 parent 836ffed commit e88e394
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 237 deletions.
21 changes: 0 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -498,27 +498,6 @@ path = "examples/window/transparent_window.rs"
name = "window_settings"
path = "examples/window/window_settings.rs"

# WASM
[[example]]
name = "hello_wasm"
path = "examples/wasm/hello_wasm.rs"
required-features = []

[[example]]
name = "assets_wasm"
path = "examples/wasm/assets_wasm.rs"
required-features = ["bevy_winit"]

[[example]]
name = "headless_wasm"
path = "examples/wasm/headless_wasm.rs"
required-features = []

[[example]]
name = "winit_wasm"
path = "examples/wasm/winit_wasm.rs"
required-features = ["bevy_winit"]

# Android
[[example]]
crate-type = ["cdylib"]
Expand Down
34 changes: 22 additions & 12 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,24 +366,34 @@ cargo install wasm-bindgen-cli

### Build & Run

Following is an example for `headless_wasm`. For other examples in wasm/ directory,
change the `headless_wasm` in the following commands **and edit** `examples/wasm/index.html`
to point to the correct `.js` file.
Following is an example for `lighting`. For other examples, change the `lighting` in the
following commands.

```sh
cargo build --example headless_wasm --target wasm32-unknown-unknown --no-default-features
wasm-bindgen --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/debug/examples/headless_wasm.wasm
cargo build --release --example lighting --target wasm32-unknown-unknown
wasm-bindgen --out-name wasm_example --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/release/examples/lighting.wasm
```

Then serve `examples/wasm` dir to browser. i.e.
The first command will build the example for the wasm target, creating a binary. Then,
[wasm-bindgen-cli](https://rustwasm.github.io/wasm-bindgen/reference/cli.html) is used to create
javascript bindings to this wasm file, which can be loaded using this
[example HTML file](./wasm/index.html).

Then serve `examples/wasm` directory to browser. i.e.

```sh
# cargo install basic-http-server
basic-http-server examples/wasm

# with python
python3 -m http.server --directory examples/wasm

# with ruby
ruby -run -ehttpd examples/wasm
```

Example | File | Description
--- | --- | ---
`hello_wasm` | [`wasm/hello_wasm.rs`](./wasm/hello_wasm.rs) | Runs a minimal example that logs "hello world" to the browser's console
`assets_wasm` | [`wasm/assets_wasm.rs`](./wasm/assets_wasm.rs) | Demonstrates how to load assets from wasm
`headless_wasm` | [`wasm/headless_wasm.rs`](./wasm/headless_wasm.rs) | Sets up a schedule runner and continually logs a counter to the browser's console
`winit_wasm` | [`wasm/winit_wasm.rs`](./wasm/winit_wasm.rs) | Logs user input to the browser's console. Requires the `bevy_winit` features
### Loading Assets

To load assets, they need to be available in the folder examples/wasm/assets. Cloning this
repository will set it up as a symlink on Linux and macOS, but you will need to manually move
the assets on Windows.
1 change: 1 addition & 0 deletions examples/wasm/assets
68 changes: 0 additions & 68 deletions examples/wasm/assets_wasm.rs

This file was deleted.

34 changes: 0 additions & 34 deletions examples/wasm/headless_wasm.rs

This file was deleted.

12 changes: 0 additions & 12 deletions examples/wasm/hello_wasm.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</style>
</head>
<script type="module">
import init from './target/headless_wasm.js'
import init from './target/wasm_example.js'
init()
</script>
</html>
89 changes: 0 additions & 89 deletions examples/wasm/winit_wasm.rs

This file was deleted.

0 comments on commit e88e394

Please sign in to comment.