From 54236a7e512cf8c27f21d0ef491d39c35eae681c Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Wed, 2 Sep 2020 17:46:01 +0200 Subject: [PATCH] Basic wasm library --- .gitignore | 2 ++ Cargo.toml | 12 ++++++++++++ Makefile | 28 ++++++++++++++++++++++++++++ src/lib.rs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 Makefile create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c8ae0b0 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "audioview" +version = "0.1.0" +authors = ["Rob Watson "] +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +yew = "0.17" +wasm-bindgen = "0.2" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fb16d85 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +# Based on https://raw.githubusercontent.com/saschagrunert/webapp.rs/master/Makefile + +GENERAL_ARGS = --release +FRONTEND_ARGS = $(GENERAL_ARGS) + +.PHONY: \ + build \ + run + +all: build + +build: + wasm-pack build --target web --out-name wasm --out-dir ./static + +build-doc: + cargo doc --all --no-deps + +run: + simple-http-server -i ./static/ -p 3000 --nocache --try-file ./static/index.html + +lint: lint-rustfmt lint-clippy + +lint-clippy: + cargo clippy --all -- -D warnings + +lint-rustfmt: + cargo fmt + git diff --exit-code diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..74df7c0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,30 @@ +use wasm_bindgen::prelude::*; +use yew::prelude::*; + +struct Home {} + +impl Component for Home { + type Message = (); + type Properties = (); + + fn create(_: Self::Properties, _: ComponentLink) -> Self { + Self {} + } + + fn update(&mut self, _: Self::Message) -> ShouldRender { + true + } + + fn change(&mut self, _: Self::Properties) -> ShouldRender { + true + } + + fn view(&self) -> Html { + html! { {"Hello World!"} } + } +} + +#[wasm_bindgen(start)] +pub fn run_app() { + App::::new().mount_to_body(); +}