Skip to content

Commit

Permalink
feat: bootstrap wasm library
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallios committed Jul 2, 2024
1 parent 4936add commit 79fcb84
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 42 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"
members = [
"manager-app",
"manager-wasm",
"soundcore-lib",
"test_data"
]
Expand Down
35 changes: 0 additions & 35 deletions lefthook.yml

This file was deleted.

8 changes: 8 additions & 0 deletions manager-wasm/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
time: "08:00"
open-pull-requests-limit: 10
6 changes: 6 additions & 0 deletions manager-wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
28 changes: 28 additions & 0 deletions manager-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "manager-wasm"
version = "0.1.0"
authors = ["Grigoris Mallios <gregmallios@gmail.com>"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.84"
soundcore-lib={ workspace = true, default-features = false}

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

[profile.release]
opt-level = "s"
13 changes: 13 additions & 0 deletions manager-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mod utils;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet() {
alert("Hello, manager-wasm!");
}
10 changes: 10 additions & 0 deletions manager-wasm/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions manager-wasm/tests/web.rs
Original file line number Diff line number Diff line change
@@ -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);
}
16 changes: 9 additions & 7 deletions soundcore-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@ log = { workspace = true }
env_logger = { workspace = true }
thiserror = { workspace = true }
serde = { workspace = true, features = ["derive", "rc"] }
tokio = { workspace = true, features = [
"time",
"macros",
"rt-multi-thread",
"sync",
] }
async-trait = { workspace = true }
futures = { workspace = true }
strum = { version = "0.26", features = ["derive"] }
nom = "7"
enumflags2 = { version = "0.7.7", features = ["serde"] }
phf = { version = "0.11", default-features = false, features = ["macros"] }
derive_more = { version = "0.99", features = ["from"] }
uuid = { version = "1.6.1", features = ["v4", "serde"] }
uuid = { version = "1.6.1", features = ["v4", "serde", "js"] }
btleplug = { version = "0.11", features = ["serde"], optional = true }

[dev-dependencies]
Expand All @@ -51,3 +45,11 @@ windows = { version = "0.52", features = [
"Devices_Bluetooth_GenericAttributeProfile",
"Devices_Bluetooth_Advertisement",
], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { workspace = true, features = [
"time",
"macros",
"rt-multi-thread",
"sync",
] }

0 comments on commit 79fcb84

Please sign in to comment.