summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-05-22 16:21:46 +0200
committerDennis Kobert <d-kobert@web.de>2019-05-22 16:21:46 +0200
commit59b185a10091c80259e49e3e16d8903e8cd68add (patch)
tree7ca8371d455ccf696717b8e3372f3a61c24d5372
parent24ea877322054db328069126fbd540bc1ce2d7eb (diff)
Execute wasm-pack
-rw-r--r--WebInterface/wasm/asm-paint/.gitignore6
-rw-r--r--WebInterface/wasm/asm-paint/Cargo.toml34
-rw-r--r--WebInterface/wasm/asm-paint/README.md53
-rw-r--r--WebInterface/wasm/asm-paint/src/lib.rs19
-rw-r--r--WebInterface/wasm/asm-paint/src/utils.rs10
-rw-r--r--WebInterface/wasm/asm-paint/tests/web.rs13
6 files changed, 135 insertions, 0 deletions
diff --git a/WebInterface/wasm/asm-paint/.gitignore b/WebInterface/wasm/asm-paint/.gitignore
new file mode 100644
index 0000000..4e30131
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/.gitignore
@@ -0,0 +1,6 @@
+/target
+**/*.rs.bk
+Cargo.lock
+bin/
+pkg/
+wasm-pack.log
diff --git a/WebInterface/wasm/asm-paint/Cargo.toml b/WebInterface/wasm/asm-paint/Cargo.toml
new file mode 100644
index 0000000..619630b
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/Cargo.toml
@@ -0,0 +1,34 @@
+[package]
+name = "asm-paint"
+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/README.md b/WebInterface/wasm/asm-paint/README.md
new file mode 100644
index 0000000..5fcb76f
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/README.md
@@ -0,0 +1,53 @@
+# πŸ¦€πŸ•ΈοΈ `wasm-pack-template`
+
+A template for kick starting a Rust and WebAssembly project using
+[`wasm-pack`](https://github.com/rustwasm/wasm-pack).
+
+[**πŸ“š Read this template tutorial! πŸ“š**][template-docs]
+
+This template is designed for compiling Rust libraries into WebAssembly and
+publishing the resulting package to NPM.
+
+Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
+templates and usages of `wasm-pack`.
+
+[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
+[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
+
+## 🚴 Usage
+
+### πŸ‘ Use `cargo generate` to Clone this Template
+
+[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
+
+```
+cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
+cd my-project
+```
+
+### πŸ› οΈ Build with `wasm-pack build`
+
+```
+wasm-pack build
+```
+
+### πŸ”¬ Test in Headless Browsers with `wasm-pack test`
+
+```
+wasm-pack test --headless --firefox
+```
+
+### 🎁 Publish to NPM with `wasm-pack publish`
+
+```
+wasm-pack publish
+```
+
+## πŸ”‹ Batteries Included
+
+* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
+ between WebAssembly and JavaScript.
+* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
+ for logging panic messages to the developer console.
+* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
+ for small code size.
diff --git a/WebInterface/wasm/asm-paint/src/lib.rs b/WebInterface/wasm/asm-paint/src/lib.rs
new file mode 100644
index 0000000..908b857
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/src/lib.rs
@@ -0,0 +1,19 @@
+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 log(s: &str);
+}
+
+#[wasm_bindgen]
+pub fn greet() {
+ log("Hello, asm-paint!");
+}
diff --git a/WebInterface/wasm/asm-paint/src/utils.rs b/WebInterface/wasm/asm-paint/src/utils.rs
new file mode 100644
index 0000000..b1d7929
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/src/utils.rs
@@ -0,0 +1,10 @@
+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
new file mode 100644
index 0000000..de5c1da
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/tests/web.rs
@@ -0,0 +1,13 @@
+//! 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);
+}