Skip to content

Commit ae0cb54

Browse files
committed
helper tool to build examples in wasm (#4776)
# Objective - add an helper to build examples in wasm (from #4700) ## Solution - `cargo run -p build-wasm-example -- lighting`
1 parent e36bfa2 commit ae0cb54

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repository = "https://github.com/bevyengine/bevy"
1313

1414
[workspace]
1515
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests"]
16-
members = ["crates/*", "examples/ios", "tools/ci", "tools/spancmp", "errors"]
16+
members = ["crates/*", "examples/ios", "tools/ci", "tools/spancmp", "tools/build-wasm-example", "errors"]
1717

1818
[features]
1919
default = [

examples/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,13 @@ cargo install wasm-bindgen-cli
422422
### Build & Run
423423

424424
Following is an example for `lighting`. For other examples, change the `lighting` in the
425-
following commands.
425+
following command.
426+
427+
```sh
428+
cargo run -p build-wasm-example -- lighting
429+
```
430+
431+
This is the same as running
426432

427433
```sh
428434
cargo build --release --example lighting --target wasm32-unknown-unknown

tools/build-wasm-example/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "build-wasm-example"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Build an example for wasm"
6+
publish = false
7+
license = "MIT OR Apache-2.0"
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]
11+
xshell = "0.2"

tools/build-wasm-example/src/main.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use xshell::{cmd, Shell};
2+
3+
fn main() {
4+
let example = std::env::args().nth(1).expect("abbb");
5+
let sh = Shell::new().unwrap();
6+
cmd!(
7+
sh,
8+
"cargo build --release --target wasm32-unknown-unknown --example {example}"
9+
)
10+
.run()
11+
.expect("Error building example");
12+
cmd!(
13+
sh,
14+
"wasm-bindgen --out-dir examples/wasm/target --out-name wasm_example --target web target/wasm32-unknown-unknown/release/examples/{example}.wasm"
15+
)
16+
.run()
17+
.expect("Error creating wasm binding");
18+
}

0 commit comments

Comments
 (0)