Skip to content

Commit cf246d5

Browse files
committed
Add wasm flag
1 parent f6d03d9 commit cf246d5

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ server-local = ["storage-sqlite"]
3434
storage = ["storage-sqlite"]
3535
# Support for SQLite task storage
3636
storage-sqlite = ["dep:rusqlite", "dep:tokio-rusqlite"]
37+
# Support for the in-memory storage backend (WASM-compatible)
38+
storage-inmemory = []
3739
# (private) Support for sync protocol encryption
3840
encryption = ["dep:ring"]
3941
# (private) Generic support for cloud sync
@@ -42,6 +44,8 @@ cloud = []
4244
bundled = ["rusqlite/bundled", "tokio-rusqlite/bundled"]
4345
# use native CA roots, instead of bundled
4446
tls-native-roots = ["ureq/native-certs"]
47+
# Feature for wasm builds. This enables wasm-compatible storage.
48+
wasm = ["storage-inmemory"]
4549

4650
[package.metadata.docs.rs]
4751
all-features = true
@@ -62,16 +66,26 @@ serde_json = "^1.0"
6266
serde = { version = "^1.0.147", features = ["derive"] }
6367
strum = "0.27"
6468
strum_macros = "0.27"
65-
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
6669
thiserror = "2.0"
6770
ureq = { version = "^2.12.1", features = ["tls"], optional = true }
6871
uuid = { version = "^1.16.0", features = ["serde", "v4"] }
6972
url = { version = "2", optional = true }
7073
async-trait = "0.1.89"
7174
tokio-rusqlite = { version = "0.6.0", optional = true }
75+
# Use only WASM-compatible features by default
76+
tokio = { version = "1", features = ["macros"] }
77+
78+
# For non-WASM targets, enable the multi-threaded runtime
79+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
80+
tokio = { version = "1", features = ["rt-multi-thread"] }
81+
82+
# For WASM targets, enable the single-threaded runtime and WASM-friendly uuid features
83+
[target.'cfg(target_arch = "wasm32")'.dependencies]
84+
tokio = { version = "1", features = ["rt"] }
85+
uuid = { version = "^1.16.0", features = ["js"] }
7286

7387
[dev-dependencies]
7488
proptest = "^1.7.0"
7589
tempfile = "3"
7690
rstest = "0.26"
77-
pretty_assertions = "1"
91+
pretty_assertions = "1"

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub use depmap::DependencyMap;
1919
pub use errors::Error;
2020
pub use operation::{Operation, Operations};
2121
pub use replica::Replica;
22-
pub use server::{Server, ServerConfig};
22+
pub use server::Server;
23+
#[cfg(feature = "sync")]
24+
pub use server::ServerConfig;
2325
pub use task::{utc_timestamp, Annotation, Status, Tag, Task, TaskData};
2426
pub use workingset::WorkingSet;
2527

src/server/config.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#[cfg(feature = "sync")]
12
use super::types::Server;
3+
#[cfg(feature = "sync")]
24
use crate::errors::Result;
35
#[cfg(feature = "server-aws")]
46
pub use crate::server::cloud::aws::AwsCredentials;
@@ -12,17 +14,18 @@ use crate::server::cloud::CloudServer;
1214
use crate::server::local::LocalServer;
1315
#[cfg(feature = "server-sync")]
1416
use crate::server::sync::SyncServer;
15-
use std::{
16-
path::PathBuf,
17-
sync::{Arc, Mutex},
18-
};
17+
#[cfg(feature = "sync")]
18+
use std::path::PathBuf;
19+
#[cfg(feature = "sync")]
20+
use std::sync::{Arc, Mutex};
1921
#[cfg(feature = "server-sync")]
2022
use uuid::Uuid;
2123

2224
/// The configuration for a replica's access to a sync server.
2325
///
2426
/// This enum is non-exhaustive, as users should only be constructing required
2527
/// variants, not matching on it.
28+
#[cfg(feature = "sync")]
2629
#[non_exhaustive]
2730
pub enum ServerConfig {
2831
/// A local task database, for situations with a single replica.
@@ -96,6 +99,7 @@ pub enum ServerConfig {
9699
},
97100
}
98101

102+
#[cfg(feature = "sync")]
99103
impl ServerConfig {
100104
/// Get a server based on this configuration
101105
pub fn into_server(self) -> Result<Arc<Mutex<dyn Server + Send>>> {

src/server/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod sync;
2828
#[cfg(feature = "cloud")]
2929
mod cloud;
3030

31+
#[cfg(feature = "sync")]
3132
pub use config::*;
3233
pub use types::*;
3334

0 commit comments

Comments
 (0)