diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..e2ec9e5 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[alias] +run_wasm = "run --release --package run_wasm --" +# Other crates use the alias run-wasm, even though crate names should use `_`s not `-`s +# Allow this to be used +run-wasm = "run_wasm" diff --git a/.gitignore b/.gitignore index 2c96eb1..96ef6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -target/ +/target Cargo.lock diff --git a/README.md b/README.md index 26de51c..c70f34a 100644 --- a/README.md +++ b/README.md @@ -51,13 +51,16 @@ cargo run -p with_bevy Because Vello relies heavily on compute shaders, we rely on the emerging WebGPU standard to run on the web. Until browser support becomes widespread, it will probably be necessary to use development browser versions (e.g. Chrome Canary) and explicitly enable WebGPU. -The following command builds and runs a web version of the [winit demo](#winit). +Note: Other examples use the `-p` shorthand, but `cargo-run-wasm` requires the full `--package` to be specified + +The following command builds and runs a web version of the [winit demo](#winit). +This uses [`cargo-run-wasm`](https://github.com/rukai/cargo-run-wasm) to build the example for web, and host a local server for it: ```shell -cargo run --release -p run-wasm -- --package with_winit +cargo run_wasm --package with_winit ``` -Additionally, the web is not currently a primary target, so other issues are likely to arise. +The web is not currently a primary target for vello, and WebGPU implementations are incomplete, so you might run into issues running this example. ## Community diff --git a/examples/run_wasm/Cargo.toml b/examples/run_wasm/Cargo.toml index a6f1bbf..6e6f5eb 100644 --- a/examples/run_wasm/Cargo.toml +++ b/examples/run_wasm/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "run-wasm" +name = "run_wasm" version.workspace = true edition.workspace = true publish = false @@ -7,4 +7,5 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cargo-run-wasm = "0.2.0" +# We use cargo-run-wasm main because of our workspace layout +cargo-run-wasm = { git = "https://github.com/rukai/cargo-run-wasm", rev = "d14f73de77eaae44714b4817d660026a31f5f5a9" } diff --git a/examples/run_wasm/src/main.rs b/examples/run_wasm/src/main.rs index 6961358..9666918 100644 --- a/examples/run_wasm/src/main.rs +++ b/examples/run_wasm/src/main.rs @@ -1,3 +1,21 @@ +/// Use [cargo-run-wasm](https://github.com/rukai/cargo-run-wasm) to build an example for web +/// +/// Usage: +/// ``` +/// cargo run_wasm --package [example_name] +/// ``` +/// Generally: +/// ``` +/// cargo run_wasm --package with_winit +/// ``` + fn main() { + // HACK: We rely heavily on compute shaders; which means we need WebGPU to be supported + // However, that requires unstable APIs to be enabled, which are not exposed through a feature + let current_value = std::env::var("RUSTFLAGS").unwrap_or("".to_owned()); + std::env::set_var( + "RUSTFLAGS", + format!("{current_value} --cfg=web_sys_unstable_apis",), + ); cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }"); } diff --git a/examples/with_winit/src/main.rs b/examples/with_winit/src/main.rs index d3daf97..53bcfa2 100644 --- a/examples/with_winit/src/main.rs +++ b/examples/with_winit/src/main.rs @@ -18,7 +18,7 @@ mod pico_svg; mod simple_text; mod test_scene; -use std::{borrow::Cow, path::PathBuf, time::Instant}; +use std::{borrow::Cow, time::Instant}; use clap::Parser; use vello::{ @@ -41,7 +41,7 @@ struct Args { /// Path to the svg file to render. If not set, the GhostScript Tiger will be rendered #[arg(long)] #[cfg(not(target_arch = "wasm32"))] - svg: Option, + svg: Option, /// When rendering an svg, what scale to use #[arg(long)] scale: Option, diff --git a/examples/with_winit/src/test_scene.rs b/examples/with_winit/src/test_scene.rs index 96fe0c2..0dd0cba 100644 --- a/examples/with_winit/src/test_scene.rs +++ b/examples/with_winit/src/test_scene.rs @@ -1,5 +1,3 @@ -use std::time::Instant; - use crate::pico_svg::PicoSvg; use crate::simple_text::SimpleText; use vello::kurbo::{Affine, BezPath, Ellipse, PathEl, Point, Rect}; @@ -83,7 +81,7 @@ pub fn render_svg_scene( let scene_frag = scene.get_or_insert_with(|| { use super::pico_svg::*; #[cfg(not(target_arch = "wasm32"))] - let start = Instant::now(); + let start = std::time::Instant::now(); eprintln!("Starting to parse svg"); let svg = PicoSvg::load(svg, scale).unwrap(); #[cfg(not(target_arch = "wasm32"))]