diff --git a/.gitignore b/.gitignore index bf5cea56..7cd4f7f9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,9 @@ Cargo.lock target/ rls/ .vscode/ +util/ *~ +*.wasm +*.ts +*.js #*# diff --git a/Cargo.toml b/Cargo.toml index 8dde53a2..e23c1d06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ log = "0.4" serde = { version = "1", optional = true, features = ["serde_derive"] } [features] -web-sys-support = ["web-sys", "wasm-bindgen"] +web_sys = ["web-sys", "wasm-bindgen"] [dev-dependencies] image = "0.21" @@ -81,6 +81,7 @@ version = "0.8" version = "0.3.22" optional = true features = [ + 'console', 'Document', 'DomRect', 'Element', @@ -108,3 +109,7 @@ optional = true [target.'cfg(target_arch = "wasm32")'.dependencies] stdweb = { path = "../stdweb", optional = true } instant = { version = "0.1", features = ["stdweb"] } + +[[example]] +name = "window" +crate-type = ["cdylib"] diff --git a/examples/window.rs b/examples/window.rs index 6c3b9148..797dbf41 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -5,22 +5,28 @@ extern crate stdweb; #[cfg(feature = "wasm-bindgen")] #[macro_use] extern crate wasm_bindgen; +#[cfg(feature = "wasm-bindgen")] +extern crate web_sys; use winit::window::WindowBuilder; use winit::event::{Event, WindowEvent}; use winit::event_loop::{EventLoop, ControlFlow}; +use wasm_bindgen::{prelude::*, JsValue}; +use web_sys::console; -fn main() { +#[wasm_bindgen(start)] +pub fn main() { + console::log_1(&JsValue::from_str("main")); let event_loop = EventLoop::new(); let _window = WindowBuilder::new() .with_title("A fantastic window!") .build(&event_loop) .unwrap(); - //console!(log, "Built window!"); + console::log_1(&JsValue::from_str("Created window")); event_loop.run(|event, _, control_flow| { - //console!(log, format!("{:?}", event)); + console::log_1(&JsValue::from_str(&format!("{:?}", event))); match event { Event::WindowEvent { @@ -30,4 +36,4 @@ fn main() { _ => *control_flow = ControlFlow::Wait, } }); -} +} \ No newline at end of file diff --git a/test.html b/test.html new file mode 100644 index 00000000..ee88fd5b --- /dev/null +++ b/test.html @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file diff --git a/test.ps1 b/test.ps1 new file mode 100644 index 00000000..81924470 --- /dev/null +++ b/test.ps1 @@ -0,0 +1,2 @@ +cargo build --target wasm32-unknown-unknown --features web_sys --example window +wasm-bindgen .\target\wasm32-unknown-unknown\debug\examples\window.wasm --out-dir . --target web \ No newline at end of file