Skip to content

Commit

Permalink
helper tool to build examples in wasm (bevyengine#4776)
Browse files Browse the repository at this point in the history
# Objective

- add an helper to build examples in wasm (from bevyengine#4700)

## Solution

- `cargo run -p build-wasm-example -- lighting`
  • Loading branch information
mockersf authored and ItsDoot committed Feb 1, 2023
1 parent ce375f5 commit 960ddbd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository = "https://github.com/bevyengine/bevy"

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

[features]
default = [
Expand Down
8 changes: 7 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,13 @@ cargo install wasm-bindgen-cli
### Build & Run

Following is an example for `lighting`. For other examples, change the `lighting` in the
following commands.
following command.

```sh
cargo run -p build-wasm-example -- lighting
```

This is the same as running

```sh
cargo build --release --example lighting --target wasm32-unknown-unknown
Expand Down
11 changes: 11 additions & 0 deletions tools/build-wasm-example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "build-wasm-example"
version = "0.1.0"
edition = "2021"
description = "Build an example for wasm"
publish = false
license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
xshell = "0.2"
18 changes: 18 additions & 0 deletions tools/build-wasm-example/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use xshell::{cmd, Shell};

fn main() {
let example = std::env::args().nth(1).expect("abbb");
let sh = Shell::new().unwrap();
cmd!(
sh,
"cargo build --release --target wasm32-unknown-unknown --example {example}"
)
.run()
.expect("Error building example");
cmd!(
sh,
"wasm-bindgen --out-dir examples/wasm/target --out-name wasm_example --target web target/wasm32-unknown-unknown/release/examples/{example}.wasm"
)
.run()
.expect("Error creating wasm binding");
}

0 comments on commit 960ddbd

Please sign in to comment.