Conditionalize wasm_bindgen to fix compile error on wasm32-wasi

From investigation for #115, now three targets:

- wasm32-unknown-unknown: build with `wasm-pack build`, uses
the #[wasm_bindgen] directive on main()

- wasm32-wasi: build with `cargo +nightly build --target wasm32-wasi`,
requires normal main()

- native targets: same as wasm32-wasi
This commit is contained in:
ice_iix 2019-05-22 18:12:10 -07:00
parent 51aa361bbc
commit 1125c3883d
1 changed files with 13 additions and 3 deletions

View File

@ -44,7 +44,6 @@ pub mod model;
pub mod entity;
use cfg_if::cfg_if;
use wasm_bindgen::prelude::*;
use std::sync::{Arc, RwLock, Mutex};
use std::rc::Rc;
use std::marker::PhantomData;
@ -190,8 +189,19 @@ cfg_if! {
}
}
#[wasm_bindgen]
pub fn main() {
cfg_if! {
if #[cfg(target_os = "unknown")] {
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn main() { main2(); }
} else {
#[inline]
pub fn main() { main2(); }
}
}
fn main2() {
let opt = Opt::from_args();
set_panic_hook();