Add wasm package

This commit is contained in:
Andras Schmelczer 2024-12-08 17:17:47 +00:00
parent 1e1934b492
commit e1ba3d44c7
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
5 changed files with 71 additions and 0 deletions

2
backend/Cargo.lock generated
View file

@ -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",

View 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"

View 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()
}

View 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();
}

View 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);
}