Add wasm package
This commit is contained in:
parent
1e1934b492
commit
e1ba3d44c7
5 changed files with 71 additions and 0 deletions
27
backend/sync_wasm/Cargo.toml
Normal file
27
backend/sync_wasm/Cargo.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[package]
|
||||
name = "sync-wasm"
|
||||
version = "0.1.0"
|
||||
authors = ["Andras Schmelczer <andras@schmelczer.dev>"]
|
||||
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"
|
||||
19
backend/sync_wasm/src/lib.rs
Normal file
19
backend/sync_wasm/src/lib.rs
Normal file
|
|
@ -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()
|
||||
}
|
||||
10
backend/sync_wasm/src/utils.rs
Normal file
10
backend/sync_wasm/src/utils.rs
Normal file
|
|
@ -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();
|
||||
}
|
||||
13
backend/sync_wasm/tests/web.rs
Normal file
13
backend/sync_wasm/tests/web.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue