From 95c69a192c0ca9f4cd6a4399a0d86a0f879aff91 Mon Sep 17 00:00:00 2001 From: Joshua Groves Date: Sun, 12 Apr 2020 14:42:07 -0230 Subject: [PATCH] Allow describe example to run on the web --- examples/describe/main.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/examples/describe/main.rs b/examples/describe/main.rs index d035df44aa..c2b573960c 100644 --- a/examples/describe/main.rs +++ b/examples/describe/main.rs @@ -1,11 +1,4 @@ /// This example shows how to describe the adapter in use. -#[cfg(not(target_arch = "wasm32"))] -fn main() { - env_logger::init(); - futures::executor::block_on(run()); -} - -#[cfg(not(target_arch = "wasm32"))] async fn run() { let adapter = wgpu::Adapter::request( &wgpu::RequestAdapterOptions { @@ -17,5 +10,25 @@ async fn run() { .await .unwrap(); + #[cfg(not(target_arch = "wasm32"))] println!("{:?}", adapter.get_info()) } + +fn main() { + #[cfg(not(target_arch = "wasm32"))] + { + env_logger::init(); + futures::executor::block_on(run()); + } + #[cfg(target_arch = "wasm32")] + { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + wasm_bindgen_futures::spawn_local(run()); + } +} + +#[cfg(target_arch = "wasm32")] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))] +pub fn wasm_main() { + main(); +}