Skip to content

Commit d7cab93

Browse files
oracle58rparrett
andauthored
Add debug build option to build-wasm-example (#19312)
## Objective - Add a `--debug` flag to `build-wasm-example` to support debug builds for WebGL2/WebGPU targets. - Fixes #18464 ## Solution - Added `--debug` flag to build Wasm examples in debug mode. - Default remains release mode if `--debug` is not specified. - Updated documentation to describe the new flag and usage. ## Testing - Verified debug and release builds for WebGL2 and WebGPU respectively. - Confirmed wasm artifacts are placed in the correct target dir for each build profile: - Debug: `target/wasm32-unknown-unknown/debug/examples/` - Release: `target/wasm32-unknown-unknown/release/examples/` - Confirmed wasm-bindgen output is written to: `examples/wasm/target/debug` , `examples/wasm/target/release` - Haven't actually tested running the example | Backend | Profile | Artifacts written | Build success | |---------|---------|-------------------|------------------| | webgl2 | debug | ✓ | ✓ | | webgl2 | release | ✓ | ✓ | | webpgu | debug | ✓ | ✓ | | webpgu | release | ✓ | ✓ | ### Examples **Debug** ``` $ cargo run -p build-wasm-example -- --api webgl2 --debug load_gltf ``` ``` Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 02s wasm-bindgen --out-dir examples/wasm/target/debug --out-name wasm_example --target web target/wasm32-unknown-unknown/debug/examples/load_gltf.wasm ``` **Release** ``` $ cargo run -p build-wasm-example -- --api webgl2 load_gltf` ``` ``` Finished `release` profile [optimized] target(s) in 1m 08s wasm-bindgen --out-dir examples/wasm/target/release --out-name wasm_example --target web target/wasm32-unknown-unknown/release/examples/load_gltf.wasm ``` --------- Co-authored-by: Rob Parrett <robparrett@gmail.com>
1 parent cf3f26f commit d7cab93

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

docs-template/EXAMPLE_README.md.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ Bevy has a helper to build its examples:
269269

270270
- Build for WebGL2: `cargo run -p build-wasm-example -- --api webgl2 load_gltf`
271271
- Build for WebGPU: `cargo run -p build-wasm-example -- --api webgpu load_gltf`
272+
- Debug: `cargo run -p build-wasm-example -- --debug --api webgl2 load_gltf`
272273

273274
This helper will log the command used to build the examples.
274275

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ Bevy has a helper to build its examples:
782782

783783
- Build for WebGL2: `cargo run -p build-wasm-example -- --api webgl2 load_gltf`
784784
- Build for WebGPU: `cargo run -p build-wasm-example -- --api webgpu load_gltf`
785+
- Debug: `cargo run -p build-wasm-example -- --debug --api webgl2 load_gltf`
785786

786787
This helper will log the command used to build the examples.
787788

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ struct Args {
3939
#[arg(long)]
4040
/// Additional features to enable
4141
features: Vec<String>,
42+
43+
#[arg(long)]
44+
/// Build the example in debug mode instead of release
45+
debug: bool,
4246
}
4347

4448
fn main() {
@@ -73,15 +77,23 @@ fn main() {
7377
parameters.push("--features");
7478
parameters.push(&features_string);
7579
}
80+
81+
let profile = if cli.debug {
82+
"debug"
83+
} else {
84+
parameters.push("--release");
85+
"release"
86+
};
87+
7688
let cmd = cmd!(
7789
sh,
78-
"cargo build {parameters...} --profile release --target wasm32-unknown-unknown --example {example}"
90+
"cargo build {parameters...} --target wasm32-unknown-unknown --example {example}"
7991
);
8092
cmd.run().expect("Error building example");
8193

8294
cmd!(
8395
sh,
84-
"wasm-bindgen --out-dir examples/wasm/target --out-name wasm_example --target web target/wasm32-unknown-unknown/release/examples/{example}.wasm"
96+
"wasm-bindgen --out-dir examples/wasm/target --out-name wasm_example --target web target/wasm32-unknown-unknown/{profile}/examples/{example}.wasm"
8597
)
8698
.run()
8799
.expect("Error creating wasm binding");

0 commit comments

Comments
 (0)