summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornatrixaeria <janng@gmx.de>2019-05-22 22:00:23 +0200
committernatrixaeria <janng@gmx.de>2019-05-22 22:00:23 +0200
commit28c16ac6e6955b98f6485564d2c15f639bef5802 (patch)
treedf9d59be376d7d482c95b5be4bc01d010a8d00e4
parent9cc2841cf49a6180dc9426892d11e957142e88ea (diff)
Load wasm into the browser and execute it
-rw-r--r--WebInterface/wasm/asm-paint/Cargo.toml27
-rw-r--r--WebInterface/wasm/asm-paint/deploy.py4
-rw-r--r--WebInterface/wasm/asm-paint/index.html2
-rw-r--r--WebInterface/wasm/asm-paint/loader.js18
-rw-r--r--WebInterface/wasm/asm-paint/src/lib.rs19
-rw-r--r--WebInterface/wasm/asm-paint/src/main.rs3
-rw-r--r--WebInterface/wasm/asm-paint/src/utils.rs10
-rw-r--r--WebInterface/wasm/asm-paint/tests/web.rs13
8 files changed, 6 insertions, 90 deletions
diff --git a/WebInterface/wasm/asm-paint/Cargo.toml b/WebInterface/wasm/asm-paint/Cargo.toml
index 619630b..8a4cc92 100644
--- a/WebInterface/wasm/asm-paint/Cargo.toml
+++ b/WebInterface/wasm/asm-paint/Cargo.toml
@@ -4,31 +4,4 @@ version = "0.1.0"
authors = ["Dennis Kobert <d-kobert@web.de>"]
edition = "2018"
-[lib]
-crate-type = ["cdylib", "rlib"]
-
-[features]
-default = ["console_error_panic_hook"]
-
[dependencies]
-wasm-bindgen = "0.2"
-
-# The `console_error_panic_hook` crate provides better debugging of panics by
-# logging them with `console.error`. This is great for development, but requires
-# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
-# code size when deploying.
-console_error_panic_hook = { version = "0.1.1", optional = true }
-
-# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
-# compared to the default allocator's ~10K. It is slower than the default
-# allocator, however.
-#
-# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
-wee_alloc = { version = "0.4.2", optional = true }
-
-[dev-dependencies]
-wasm-bindgen-test = "0.2"
-
-[profile.release]
-# Tell `rustc` to optimize for small code size.
-opt-level = "s"
diff --git a/WebInterface/wasm/asm-paint/deploy.py b/WebInterface/wasm/asm-paint/deploy.py
index f81ebb8..ed4e0dd 100644
--- a/WebInterface/wasm/asm-paint/deploy.py
+++ b/WebInterface/wasm/asm-paint/deploy.py
@@ -9,8 +9,8 @@ HTML_MIME = 'text/html'
REQUESTS = {
'/': ('index.html', HTML_MIME),
- '/loader.js': ('loader.js', JS_MIME),
- '/asm_paint_bg.wasm': ('pkg/asm_paint_bg.wasm', WASM_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),
}
PAGE_404 = '''<!doctype html><html><head></head>
diff --git a/WebInterface/wasm/asm-paint/index.html b/WebInterface/wasm/asm-paint/index.html
index a0264cf..b03a295 100644
--- a/WebInterface/wasm/asm-paint/index.html
+++ b/WebInterface/wasm/asm-paint/index.html
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title> Scribblio </title>
- <script src='loader.js'></script>
+ <script src='asm-paint.js'></script>
</head>
<body>
</body>
diff --git a/WebInterface/wasm/asm-paint/loader.js b/WebInterface/wasm/asm-paint/loader.js
deleted file mode 100644
index 7313fa0..0000000
--- a/WebInterface/wasm/asm-paint/loader.js
+++ /dev/null
@@ -1,18 +0,0 @@
-console.log('js> create import object');
-let importObject = { imports: { my_alert: arg => alert(arg) } };
-//let importObject = {};
-
-console.log('js> create fetch object');
-
-let asm_paint_bg = fetch('asm_paint_bg.wasm');
-
-console.log('js> instantiate streaming');
-
-function and_then(obj) {
- console.log('js> reached instantiate streaming\'s then');
- return obj.instance.exports.greet();
-}
-
-WebAssembly.instantiateStreaming(asm_paint_bg, importObject)
- .then(and_then);
-
diff --git a/WebInterface/wasm/asm-paint/src/lib.rs b/WebInterface/wasm/asm-paint/src/lib.rs
deleted file mode 100644
index a4f4f54..0000000
--- a/WebInterface/wasm/asm-paint/src/lib.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-mod utils;
-
-use wasm_bindgen::prelude::*;
-
-// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
-// allocator.
-#[cfg(feature = "wee_alloc")]
-#[global_allocator]
-static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
-
-#[wasm_bindgen]
-extern {
- fn my_alert(s: &str);
-}
-
-#[wasm_bindgen]
-pub fn greet() {
- my_alert("Hello, asm-paint!");
-}
diff --git a/WebInterface/wasm/asm-paint/src/main.rs b/WebInterface/wasm/asm-paint/src/main.rs
new file mode 100644
index 0000000..0d01b18
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("hello wasm world!");
+}
diff --git a/WebInterface/wasm/asm-paint/src/utils.rs b/WebInterface/wasm/asm-paint/src/utils.rs
deleted file mode 100644
index b1d7929..0000000
--- a/WebInterface/wasm/asm-paint/src/utils.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-pub fn set_panic_hook() {
- // When the `console_error_panic_hook` feature is enabled, we can call the
- // `set_panic_hook` function at least once during initialization, and then
- // we will get better error messages if our code ever panics.
- //
- // For more details see
- // https://github.com/rustwasm/console_error_panic_hook#readme
- #[cfg(feature = "console_error_panic_hook")]
- console_error_panic_hook::set_once();
-}
diff --git a/WebInterface/wasm/asm-paint/tests/web.rs b/WebInterface/wasm/asm-paint/tests/web.rs
deleted file mode 100644
index de5c1da..0000000
--- a/WebInterface/wasm/asm-paint/tests/web.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-//! Test suite for the Web and headless browsers.
-
-#![cfg(target_arch = "wasm32")]
-
-extern crate wasm_bindgen_test;
-use wasm_bindgen_test::*;
-
-wasm_bindgen_test_configure!(run_in_browser);
-
-#[wasm_bindgen_test]
-fn pass() {
- assert_eq!(1 + 1, 2);
-}