Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit db6ab34

Browse files
committed
Combine wasm_main/main and add console_log
1 parent a2c24c7 commit db6ab34

File tree

6 files changed

+25
-46
lines changed

6 files changed

+25
-46
lines changed

examples/capture/main.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,16 @@ async fn run() {
114114
}
115115
}
116116

117-
#[cfg(target_arch = "wasm32")]
118-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))]
119-
pub fn wasm_main() {
120-
console_log::init().expect("could not initialize log");
121-
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
122-
wasm_bindgen_futures::spawn_local(run());
123-
}
124-
125-
#[cfg(target_arch = "wasm32")]
126-
fn main() {}
127-
128-
#[cfg(not(target_arch = "wasm32"))]
129117
fn main() {
130-
env_logger::init();
131-
futures::executor::block_on(run());
118+
#[cfg(not(target_arch = "wasm32"))]
119+
{
120+
env_logger::init();
121+
futures::executor::block_on(run());
122+
}
123+
#[cfg(target_arch = "wasm32")]
124+
{
125+
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
126+
console_log::init().expect("could not initialize logger");
127+
wasm_bindgen_futures::spawn_local(run());
128+
}
132129
}

examples/describe/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ fn main() {
2323
#[cfg(target_arch = "wasm32")]
2424
{
2525
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
26+
console_log::init().expect("could not initialize logger");
2627
wasm_bindgen_futures::spawn_local(run());
2728
}
2829
}
29-
30-
#[cfg(target_arch = "wasm32")]
31-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))]
32-
pub fn wasm_main() {
33-
main();
34-
}

examples/framework.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub fn run<E: Example>(title: &str) {
159159
#[cfg(target_arch = "wasm32")]
160160
{
161161
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
162+
console_log::init().expect("could not initialize logger");
162163
use winit::platform::web::WindowExtWebSys;
163164
// On wasm, append the canvas to the document body
164165
web_sys::window()

examples/hello-compute/main.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,18 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
124124
}
125125
}
126126

127-
#[cfg(target_arch = "wasm32")]
128-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))]
129-
pub fn wasm_main() {
130-
console_log::init().expect("could not initialize log");
131-
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
132-
wasm_bindgen_futures::spawn_local(run());
133-
}
134-
135-
#[cfg(target_arch = "wasm32")]
136-
fn main() {}
137-
138-
#[cfg(not(target_arch = "wasm32"))]
139127
fn main() {
140-
env_logger::init();
141-
futures::executor::block_on(run());
128+
#[cfg(not(target_arch = "wasm32"))]
129+
{
130+
env_logger::init();
131+
futures::executor::block_on(run());
132+
}
133+
#[cfg(target_arch = "wasm32")]
134+
{
135+
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
136+
console_log::init().expect("could not initialize logger");
137+
wasm_bindgen_futures::spawn_local(run());
138+
}
142139
}
143140

144141
#[cfg(test)]

examples/hello-triangle/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
137137
});
138138
}
139139

140-
#[cfg(target_arch = "wasm32")]
141-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))]
142-
pub fn wasm_main() {
143-
main();
144-
}
145-
146140
fn main() {
147141
let event_loop = EventLoop::new();
148142
let window = winit::window::Window::new(&event_loop).unwrap();
@@ -154,6 +148,7 @@ fn main() {
154148
#[cfg(target_arch = "wasm32")]
155149
{
156150
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
151+
console_log::init().expect("could not initialize logger");
157152
use winit::platform::web::WindowExtWebSys;
158153
// On wasm, append the canvas to the document body
159154
web_sys::window()

examples/msaa-line/main.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,6 @@ impl framework::Example for Example {
268268
}
269269
}
270270

271-
#[cfg(target_arch = "wasm32")]
272-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))]
273-
pub fn wasm_main() {
274-
main();
275-
}
276-
277271
fn main() {
278272
framework::run::<Example>("msaa-line");
279273
}

0 commit comments

Comments
 (0)