From 799ab8487dd702a83407476ad71e63a8ae90f2b4 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 4 Dec 2025 11:31:19 +0200 Subject: [PATCH 1/3] Use n0_future Instant, Duration, ... for wasm compat --- src/get.rs | 7 ++----- src/provider.rs | 7 +++++-- src/store/fs/options.rs | 7 +++---- src/store/fs/util/entity_manager.rs | 4 ++-- src/store/gc.rs | 4 ++-- src/util/connection_pool.rs | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/get.rs b/src/get.rs index 25e74c66..bf8da08e 100644 --- a/src/get.rs +++ b/src/get.rs @@ -16,15 +16,12 @@ //! or you can choose to finish early. //! //! [iroh]: https://docs.rs/iroh -use std::{ - fmt::{self, Debug}, - time::Duration, -}; +use std::fmt::{self, Debug}; use bao_tree::{io::fsm::BaoContentItem, ChunkNum}; use fsm::RequestCounters; use n0_error::Result; -use n0_future::time::Instant; +use n0_future::time::{Duration, Instant}; use serde::{Deserialize, Serialize}; use tracing::{debug, error}; diff --git a/src/provider.rs b/src/provider.rs index 8c7fb76f..aeab3404 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -3,13 +3,16 @@ //! Note that while using this API directly is fine, the standard way //! to provide data is to just register a [`crate::BlobsProtocol`] protocol //! handler with an [`iroh::Endpoint`](iroh::protocol::Router). -use std::{fmt::Debug, future::Future, io, time::Duration}; +use std::{fmt::Debug, future::Future, io}; use bao_tree::ChunkRanges; use iroh::endpoint::{self, ConnectionError, VarInt}; use iroh_io::{AsyncStreamReader, AsyncStreamWriter}; use n0_error::{e, stack_error, Result}; -use n0_future::{time::Instant, StreamExt}; +use n0_future::{ + time::{Duration, Instant}, + StreamExt, +}; use serde::{Deserialize, Serialize}; use tokio::select; use tracing::{debug, debug_span, Instrument}; diff --git a/src/store/fs/options.rs b/src/store/fs/options.rs index 8451b48a..5f1caea6 100644 --- a/src/store/fs/options.rs +++ b/src/store/fs/options.rs @@ -1,8 +1,7 @@ //! Options for configuring the file store. -use std::{ - path::{Path, PathBuf}, - time::Duration, -}; +use std::path::{Path, PathBuf}; + +use n0_future::time::Duration; use super::{meta::raw_outboard_size, temp_name}; use crate::{store::gc::GcConfig, Hash}; diff --git a/src/store/fs/util/entity_manager.rs b/src/store/fs/util/entity_manager.rs index ea576259..c580641a 100644 --- a/src/store/fs/util/entity_manager.rs +++ b/src/store/fs/util/entity_manager.rs @@ -819,10 +819,10 @@ mod tests { atomic::{AtomicUsize, Ordering}, Arc, Mutex, }, - time::Instant, }; use atomic_refcell::AtomicRefCell; + use n0_future::time::Instant; use super::*; @@ -1070,10 +1070,10 @@ mod tests { collections::HashSet, path::{Path, PathBuf}, sync::{Arc, Mutex}, - time::Instant, }; use atomic_refcell::AtomicRefCell; + use n0_future::time::Instant; use super::*; diff --git a/src/store/gc.rs b/src/store/gc.rs index 435c06fb..75ebbb41 100644 --- a/src/store/gc.rs +++ b/src/store/gc.rs @@ -2,7 +2,7 @@ use std::{collections::HashSet, pin::Pin, sync::Arc}; use bao_tree::ChunkRanges; use genawaiter::sync::{Co, Gen}; -use n0_future::{Stream, StreamExt}; +use n0_future::{time::Duration, Stream, StreamExt}; use tracing::{debug, error, info, warn}; use crate::{api::Store, Hash, HashAndFormat}; @@ -134,7 +134,7 @@ fn gc_sweep<'a>( #[derive(derive_more::Debug, Clone)] pub struct GcConfig { /// Interval in which to run garbage collection. - pub interval: std::time::Duration, + pub interval: Duration, /// Optional callback to manually add protected blobs. /// /// The callback is called before each garbage collection run. It gets a `&mut HashSet` diff --git a/src/util/connection_pool.rs b/src/util/connection_pool.rs index eda360ed..141aadd1 100644 --- a/src/util/connection_pool.rs +++ b/src/util/connection_pool.rs @@ -16,7 +16,6 @@ use std::{ atomic::{AtomicUsize, Ordering}, Arc, }, - time::Duration, }; use iroh::{ @@ -26,6 +25,7 @@ use iroh::{ use n0_error::{e, stack_error}; use n0_future::{ future::{self}, + time::Duration, FuturesUnordered, MaybeFuture, Stream, StreamExt, }; use tokio::sync::{ From b0999568286f3fa68f17961059b4d1dfe343f3e6 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 4 Dec 2025 11:32:02 +0200 Subject: [PATCH 2/3] set chrono features to be wasm compatible --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 035d7adf..1781bf21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ hex = "0.4.3" serde = "1.0.217" postcard = { version = "1.1.1", features = ["experimental-derive", "use-std"] } data-encoding = "2.8.0" -chrono = "0.4.39" +chrono = {version = "0.4.39", default-features = false, features = ["js-sys", "wasmbind", "std"] } ref-cast = "1.0.24" arrayvec = "0.7.6" iroh = { version = "0.95", default-features = false } From c5ebbc3f5bdb863511ee0a94d79f3a81a06760c0 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 4 Dec 2025 11:49:18 +0200 Subject: [PATCH 3/3] Configure chrono for wasm --- Cargo.toml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1781bf21..64a9a759 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ hex = "0.4.3" serde = "1.0.217" postcard = { version = "1.1.1", features = ["experimental-derive", "use-std"] } data-encoding = "2.8.0" -chrono = {version = "0.4.39", default-features = false, features = ["js-sys", "wasmbind", "std"] } ref-cast = "1.0.24" arrayvec = "0.7.6" iroh = { version = "0.95", default-features = false } @@ -43,6 +42,14 @@ reflink-copy = { version = "0.1.24", optional = true } n0-error = "0.1.2" nested_enum_utils = "0.2.3" +# non-wasm-in-browser dependencies +[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies] +chrono = { version = "0.4.39" } + +# wasm-in-browser dependencies +[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] +chrono = {version = "0.4.39", default-features = false, features = ["js-sys", "wasmbind", "std"] } + [dev-dependencies] clap = { version = "4.5.31", features = ["derive"] } hex = "0.4.3"