diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 9e17ef01..21b79952 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1959,6 +1959,7 @@ dependencies = [ "console_error_panic_hook", "getrandom", "reconcile", + "sync_lib", "wasm-bindgen", "wasm-bindgen-test", ] @@ -1980,6 +1981,7 @@ dependencies = [ "axum", "chrono", "log", + "rand", "reconcile", "schemars", "serde", diff --git a/backend/sync_wasm/Cargo.toml b/backend/sync_wasm/Cargo.toml new file mode 100644 index 00000000..39670df4 --- /dev/null +++ b/backend/sync_wasm/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "sync-wasm" +version = "0.1.0" +authors = ["Andras Schmelczer "] +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +default = ["console_error_panic_hook"] + +[dependencies] +wasm-bindgen = "0.2.84" +sync_lib = { path = "../sync_lib" } +reconcile = { path = "../reconcile" } +getrandom = { version = "0.2.3", features = ["js"] } + + +# 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.7", optional = true } + +[dev-dependencies] +wasm-bindgen-test = "0.3.34" diff --git a/backend/sync_wasm/src/lib.rs b/backend/sync_wasm/src/lib.rs new file mode 100644 index 00000000..af5477fa --- /dev/null +++ b/backend/sync_wasm/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 "C" { +// fn alert(s: &str); +// } + +#[wasm_bindgen] +pub fn greet() -> String { + "hi".to_string() +} diff --git a/backend/sync_wasm/src/utils.rs b/backend/sync_wasm/src/utils.rs new file mode 100644 index 00000000..b1d7929d --- /dev/null +++ b/backend/sync_wasm/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/backend/sync_wasm/tests/web.rs b/backend/sync_wasm/tests/web.rs new file mode 100644 index 00000000..de5c1daf --- /dev/null +++ b/backend/sync_wasm/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); +}