From 90be5f8d63e77ee51256270dec018e2c7448e115 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sat, 25 May 2019 02:06:41 +0200 Subject: Resetup webassembly on the cool way --- WebInterface/wasm/asm-paint/Cargo.toml | 6 +++++- WebInterface/wasm/asm-paint/build.sh | 3 ++- WebInterface/wasm/asm-paint/deploy | 4 ++++ WebInterface/wasm/asm-paint/deploy.py | 6 ++++-- WebInterface/wasm/asm-paint/index.html | 3 +-- WebInterface/wasm/asm-paint/loader.js | 3 ++- WebInterface/wasm/asm-paint/src/lib.rs | 16 ++++++++++++++++ WebInterface/wasm/asm-paint/src/main.rs | 14 -------------- 8 files changed, 34 insertions(+), 21 deletions(-) create mode 100755 WebInterface/wasm/asm-paint/deploy mode change 100644 => 100755 WebInterface/wasm/asm-paint/deploy.py create mode 100644 WebInterface/wasm/asm-paint/src/lib.rs delete mode 100644 WebInterface/wasm/asm-paint/src/main.rs (limited to 'WebInterface/wasm') diff --git a/WebInterface/wasm/asm-paint/Cargo.toml b/WebInterface/wasm/asm-paint/Cargo.toml index 8a4cc92..c0a7c68 100644 --- a/WebInterface/wasm/asm-paint/Cargo.toml +++ b/WebInterface/wasm/asm-paint/Cargo.toml @@ -1,7 +1,11 @@ [package] -name = "asm-paint" +name = "asm-paint-rs" version = "0.1.0" authors = ["Dennis Kobert "] edition = "2018" +[lib] +crate-type = ["cdylib"] + [dependencies] +wasm-bindgen = "0.2" diff --git a/WebInterface/wasm/asm-paint/build.sh b/WebInterface/wasm/asm-paint/build.sh index 457d1d8..61c1997 100755 --- a/WebInterface/wasm/asm-paint/build.sh +++ b/WebInterface/wasm/asm-paint/build.sh @@ -1,2 +1,3 @@ #!/bin/sh -cargo build --target=wasm32-unknown-emscripten --release + +wasm-pack build --target web diff --git a/WebInterface/wasm/asm-paint/deploy b/WebInterface/wasm/asm-paint/deploy new file mode 100755 index 0000000..9f7f823 --- /dev/null +++ b/WebInterface/wasm/asm-paint/deploy @@ -0,0 +1,4 @@ +#!/bin/sh + +./build.sh +./deploy.py diff --git a/WebInterface/wasm/asm-paint/deploy.py b/WebInterface/wasm/asm-paint/deploy.py old mode 100644 new mode 100755 index fce7a02..b64c322 --- a/WebInterface/wasm/asm-paint/deploy.py +++ b/WebInterface/wasm/asm-paint/deploy.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from socket import (socket, AF_INET, SOCK_STREAM, IPPROTO_TCP, SOL_SOCKET, SO_REUSEADDR) from threading import Thread @@ -10,8 +12,8 @@ HTML_MIME = 'text/html' REQUESTS = { '/': ('index.html', HTML_MIME), '/loader.js': ('loader.js', JS_MIME), - '/asm-paint.js': ('target/wasm32-unknown-emscripten/release/asm-paint.js', JS_MIME), - '/asm_paint.wasm': ('target/wasm32-unknown-emscripten/release/asm_paint.wasm', WASM_MIME), + '/asm_paint_rs.js': ('pkg/asm_paint_rs.js', JS_MIME), + '/asm_paint_rs_bg.wasm': ('pkg/asm_paint_rs_bg.wasm', WASM_MIME), } PAGE_404 = ''' diff --git a/WebInterface/wasm/asm-paint/index.html b/WebInterface/wasm/asm-paint/index.html index c47d89d..46be213 100644 --- a/WebInterface/wasm/asm-paint/index.html +++ b/WebInterface/wasm/asm-paint/index.html @@ -3,8 +3,7 @@ Scribblio - - + diff --git a/WebInterface/wasm/asm-paint/loader.js b/WebInterface/wasm/asm-paint/loader.js index 3e25291..f1d15ef 100644 --- a/WebInterface/wasm/asm-paint/loader.js +++ b/WebInterface/wasm/asm-paint/loader.js @@ -1 +1,2 @@ -//Module. +import {default as init} from './asm_paint_rs.js' +init('asm_paint_rs_bg.wasm'); diff --git a/WebInterface/wasm/asm-paint/src/lib.rs b/WebInterface/wasm/asm-paint/src/lib.rs new file mode 100644 index 0000000..52ddc8f --- /dev/null +++ b/WebInterface/wasm/asm-paint/src/lib.rs @@ -0,0 +1,16 @@ +use wasm_bindgen::prelude::*; + +macro_rules! console_log { + ($($t:tt)*) => (log(&format_args!($($t)*).to_string())) +} + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_namespace = console)] + fn log(s: &str); +} + +#[wasm_bindgen(start)] +pub fn entry() { + console_log!("hello {} wasm", 42); +} diff --git a/WebInterface/wasm/asm-paint/src/main.rs b/WebInterface/wasm/asm-paint/src/main.rs deleted file mode 100644 index f8949ee..0000000 --- a/WebInterface/wasm/asm-paint/src/main.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::os::raw::c_int; - -#[no_mangle] -pub extern fn run_infinite() { - std::thread::spawn(move || { - loop { - println!("iterating infititely"); - } - }); -} - -fn main() { - println!("haha from wasm lol"); -} -- cgit v1.2.3-54-g00ecf