From a9c8bf650f6db34affe7dabe9b273e36b3039b48 Mon Sep 17 00:00:00 2001 From: Ben Hansen Date: Sat, 19 Feb 2022 12:43:56 -0700 Subject: [PATCH] more-testing --- .cargo/config | 2 + Cargo.lock | 291 +++++++++++++++++- Cargo.toml | 2 + code/beginner/tutorial2-surface/src/lib.rs | 2 +- .../tutorial10-lighting/src/lib.rs | 7 +- run-wasm/Cargo.toml | 7 + run-wasm/src/main.rs | 3 + 7 files changed, 299 insertions(+), 15 deletions(-) create mode 100644 .cargo/config create mode 100644 run-wasm/Cargo.toml create mode 100644 run-wasm/src/main.rs diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 00000000..8ddc0654 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,2 @@ +[alias] +run-wasm = "run --release --package run-wasm --" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 1831caf5..e6a35e2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,6 +144,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "base64" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" +dependencies = [ + "byteorder", + "safemem", +] + [[package]] name = "base64" version = "0.13.0" @@ -254,6 +264,17 @@ dependencies = [ "nix 0.22.0", ] +[[package]] +name = "cargo-run-wasm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601e6c8c774ca4cba5d01a44d3844a04a56189eb6c1f4c49b06999be890c8ab4" +dependencies = [ + "devserver_lib", + "pico-args", + "wasm-bindgen-cli-support", +] + [[package]] name = "cc" version = "1.0.72" @@ -738,6 +759,12 @@ dependencies = [ "syn", ] +[[package]] +name = "devserver_lib" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb4b71acc1405be2431a93892a79a0d82ed5ba6885649ddbdfc62caa4d67b1c" + [[package]] name = "dispatch" version = "0.2.0" @@ -1087,6 +1114,15 @@ dependencies = [ "ahash", ] +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1185,6 +1221,12 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "ident_case" version = "1.0.1" @@ -1359,6 +1401,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + [[package]] name = "libc" version = "0.2.112" @@ -2015,6 +2063,12 @@ dependencies = [ "indexmap", ] +[[package]] +name = "pico-args" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" + [[package]] name = "pin-project-lite" version = "0.2.7" @@ -2302,7 +2356,7 @@ version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f242f1488a539a79bac6dbe7c8609ae43b7914b7736210f239a37cccb32525" dependencies = [ - "base64", + "base64 0.13.0", "bytes", "encoding_rs", "futures-core", @@ -2348,11 +2402,24 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b861ecaade43ac97886a512b360d01d66be9f41f3c61088b42cedf92e03d678" dependencies = [ - "base64", + "base64 0.13.0", "bitflags", "serde", ] +[[package]] +name = "run-wasm" +version = "0.1.0" +dependencies = [ + "cargo-run-wasm", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -2365,6 +2432,12 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + [[package]] name = "same-file" version = "1.0.6" @@ -3155,6 +3228,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" + [[package]] name = "unicode-width" version = "0.1.9" @@ -3202,6 +3281,32 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "walrus" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb08e48cde54c05f363d984bb54ce374f49e242def9468d2e1b6c2372d291f8" +dependencies = [ + "anyhow", + "id-arena", + "leb128", + "log", + "walrus-macro", + "wasmparser 0.77.0", +] + +[[package]] +name = "walrus-macro" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e5bd22c71e77d60140b0bd5be56155a37e5bd14e24f5f87298040d0cc40d7" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "want" version = "0.3.0" @@ -3220,9 +3325,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.78" +version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -3230,9 +3335,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.78" +version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" dependencies = [ "bumpalo", "lazy_static", @@ -3243,6 +3348,40 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-cli-support" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b59c1dbd2614ad95f113ed80d7d79680c96b10e8e62c16e07278c24d0c1d73" +dependencies = [ + "anyhow", + "base64 0.9.3", + "log", + "rustc-demangle", + "serde_json", + "tempfile", + "walrus", + "wasm-bindgen-externref-xform", + "wasm-bindgen-multi-value-xform", + "wasm-bindgen-shared", + "wasm-bindgen-threads-xform", + "wasm-bindgen-wasm-conventions", + "wasm-bindgen-wasm-interpreter", + "wit-text", + "wit-validator", + "wit-walrus", +] + +[[package]] +name = "wasm-bindgen-externref-xform" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41448820aaad979ecea552c069621457576fe3b64d515bf91e8e8ee047163cc9" +dependencies = [ + "anyhow", + "walrus", +] + [[package]] name = "wasm-bindgen-futures" version = "0.4.28" @@ -3257,9 +3396,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.78" +version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3267,9 +3406,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.78" +version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" dependencies = [ "proc-macro2", "quote", @@ -3278,11 +3417,75 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-multi-value-xform" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f0301bc4e9b356cf0b49c395bfc14051e3421b32e5383f05f82bcf646224b8b" +dependencies = [ + "anyhow", + "walrus", +] + [[package]] name = "wasm-bindgen-shared" -version = "0.2.78" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" + +[[package]] +name = "wasm-bindgen-threads-xform" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ea535bae81cedb45a132e5991ddde05319c884b7f046e0139d77a0a7855552a" +dependencies = [ + "anyhow", + "walrus", + "wasm-bindgen-wasm-conventions", +] + +[[package]] +name = "wasm-bindgen-wasm-conventions" +version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" +checksum = "6fbcb51a08cdbbb0a64aaf47ce275e8470e7e4070e95bcb53b963838ea4be770" +dependencies = [ + "anyhow", + "walrus", +] + +[[package]] +name = "wasm-bindgen-wasm-interpreter" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e7067c008334fce029580d1d2cbaff40f97bba864d4d4e99b4c2a0c34e477a7" +dependencies = [ + "anyhow", + "log", + "walrus", + "wasm-bindgen-wasm-conventions", +] + +[[package]] +name = "wasmparser" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a950e6a618f62147fd514ff445b2a0b53120d382751960797f85f058c7eda9b9" + +[[package]] +name = "wasmparser" +version = "0.77.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35c86d22e720a07d954ebbed772d01180501afe7d03d464f413bb5f8914a8d6" + +[[package]] +name = "wast" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b1844f66a2bc8526d71690104c0e78a8e59ffa1597b7245769d174ebb91deb5" +dependencies = [ + "leb128", +] [[package]] name = "wayland-client" @@ -3581,6 +3784,70 @@ dependencies = [ "winapi", ] +[[package]] +name = "wit-parser" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f5fd97866f4b9c8e1ed57bcf9446f3d0d8ba37e2dd01c3c612c046c053b06f7" +dependencies = [ + "anyhow", + "leb128", + "wit-schema-version", +] + +[[package]] +name = "wit-schema-version" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfee4a6a4716eefa0682e7a3b836152e894a3e4f34a9d6c2c3e1c94429bfe36a" + +[[package]] +name = "wit-text" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33358e95c77d660f1c7c07f4a93c2bd89768965e844e3c50730bb4b42658df5f" +dependencies = [ + "anyhow", + "wast", + "wit-writer", +] + +[[package]] +name = "wit-validator" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c11d93d925420e7872b226c4161849c32be38385ccab026b88df99d8ddc6ba6" +dependencies = [ + "anyhow", + "wasmparser 0.59.0", + "wit-parser", + "wit-schema-version", +] + +[[package]] +name = "wit-walrus" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad559e3e4c6404b2a6a675d44129d62a3836e3b951b90112fa1c5feb852757cd" +dependencies = [ + "anyhow", + "id-arena", + "walrus", + "wit-parser", + "wit-schema-version", + "wit-writer", +] + +[[package]] +name = "wit-writer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2ad01ba5e9cbcff799a0689e56a153776ea694cec777f605938cb9880d41a09" +dependencies = [ + "leb128", + "wit-schema-version", +] + [[package]] name = "x11-dl" version = "2.19.1" diff --git a/Cargo.toml b/Cargo.toml index 3ad6d7e8..35b22c0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ members = [ # showcase "code/showcase/*", + + "run-wasm", ] exclude = [ "code/showcase/imgui-demo", diff --git a/code/beginner/tutorial2-surface/src/lib.rs b/code/beginner/tutorial2-surface/src/lib.rs index fb890a39..f6e92b3b 100644 --- a/code/beginner/tutorial2-surface/src/lib.rs +++ b/code/beginner/tutorial2-surface/src/lib.rs @@ -23,7 +23,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::Backends::GL); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { diff --git a/code/intermediate/tutorial10-lighting/src/lib.rs b/code/intermediate/tutorial10-lighting/src/lib.rs index 2ca90d57..d75c0aa6 100644 --- a/code/intermediate/tutorial10-lighting/src/lib.rs +++ b/code/intermediate/tutorial10-lighting/src/lib.rs @@ -725,9 +725,12 @@ pub async fn run() { web_sys::window() .and_then(|win| win.document()) .and_then(|doc| { - let dst = doc.get_element_by_id("wasm-example")?; let canvas = web_sys::Element::from(window.canvas()); - dst.append_child(&canvas).ok()?; + if let Some(dst) = doc.get_element_by_id("wasm-example") { + dst.append_child(&canvas).ok()?; + } else { + doc.body()?.append_child(&canvas).ok()?; + } Some(()) }) .expect("Couldn't append canvas to document body."); diff --git a/run-wasm/Cargo.toml b/run-wasm/Cargo.toml new file mode 100644 index 00000000..714f730a --- /dev/null +++ b/run-wasm/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "run-wasm" +version = "0.1.0" +edition = "2021" + +[dependencies] +cargo-run-wasm = "0.1.0" diff --git a/run-wasm/src/main.rs b/run-wasm/src/main.rs new file mode 100644 index 00000000..86e6dccd --- /dev/null +++ b/run-wasm/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + cargo_run_wasm::run_wasm(); +}