Skip to content

Commit 6ef70e3

Browse files
authored
deps: Fix deps to actually work, not just compile, in wasm-browser (#201)
## Description While this will currently compile to wasm, when running in the browser, any reference to `std::time` will explode with unsupported platform errors, this fixes that. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions Note: replaces #194 which is obsolete due to the change to n0-error ## Change checklist - [ ] Self-review. - [ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent e1456f9 commit 6ef70e3

File tree

7 files changed

+23
-17
lines changed

7 files changed

+23
-17
lines changed

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ hex = "0.4.3"
2828
serde = "1.0.217"
2929
postcard = { version = "1.1.1", features = ["experimental-derive", "use-std"] }
3030
data-encoding = "2.8.0"
31-
chrono = "0.4.39"
3231
ref-cast = "1.0.24"
3332
arrayvec = "0.7.6"
3433
iroh = { version = "0.95", default-features = false }
@@ -43,6 +42,14 @@ reflink-copy = { version = "0.1.24", optional = true }
4342
n0-error = "0.1.2"
4443
nested_enum_utils = "0.2.3"
4544

45+
# non-wasm-in-browser dependencies
46+
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
47+
chrono = { version = "0.4.39" }
48+
49+
# wasm-in-browser dependencies
50+
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
51+
chrono = {version = "0.4.39", default-features = false, features = ["js-sys", "wasmbind", "std"] }
52+
4653
[dev-dependencies]
4754
clap = { version = "4.5.31", features = ["derive"] }
4855
hex = "0.4.3"

src/get.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616
//! or you can choose to finish early.
1717
//!
1818
//! [iroh]: https://docs.rs/iroh
19-
use std::{
20-
fmt::{self, Debug},
21-
time::Duration,
22-
};
19+
use std::fmt::{self, Debug};
2320

2421
use bao_tree::{io::fsm::BaoContentItem, ChunkNum};
2522
use fsm::RequestCounters;
2623
use n0_error::Result;
27-
use n0_future::time::Instant;
24+
use n0_future::time::{Duration, Instant};
2825
use serde::{Deserialize, Serialize};
2926
use tracing::{debug, error};
3027

src/provider.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
//! Note that while using this API directly is fine, the standard way
44
//! to provide data is to just register a [`crate::BlobsProtocol`] protocol
55
//! handler with an [`iroh::Endpoint`](iroh::protocol::Router).
6-
use std::{fmt::Debug, future::Future, io, time::Duration};
6+
use std::{fmt::Debug, future::Future, io};
77

88
use bao_tree::ChunkRanges;
99
use iroh::endpoint::{self, ConnectionError, VarInt};
1010
use iroh_io::{AsyncStreamReader, AsyncStreamWriter};
1111
use n0_error::{e, stack_error, Result};
12-
use n0_future::{time::Instant, StreamExt};
12+
use n0_future::{
13+
time::{Duration, Instant},
14+
StreamExt,
15+
};
1316
use serde::{Deserialize, Serialize};
1417
use tokio::select;
1518
use tracing::{debug, debug_span, Instrument};

src/store/fs/options.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Options for configuring the file store.
2-
use std::{
3-
path::{Path, PathBuf},
4-
time::Duration,
5-
};
2+
use std::path::{Path, PathBuf};
3+
4+
use n0_future::time::Duration;
65

76
use super::{meta::raw_outboard_size, temp_name};
87
use crate::{store::gc::GcConfig, Hash};

src/store/fs/util/entity_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,10 @@ mod tests {
819819
atomic::{AtomicUsize, Ordering},
820820
Arc, Mutex,
821821
},
822-
time::Instant,
823822
};
824823

825824
use atomic_refcell::AtomicRefCell;
825+
use n0_future::time::Instant;
826826

827827
use super::*;
828828

@@ -1070,10 +1070,10 @@ mod tests {
10701070
collections::HashSet,
10711071
path::{Path, PathBuf},
10721072
sync::{Arc, Mutex},
1073-
time::Instant,
10741073
};
10751074

10761075
use atomic_refcell::AtomicRefCell;
1076+
use n0_future::time::Instant;
10771077

10781078
use super::*;
10791079

src/store/gc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{collections::HashSet, pin::Pin, sync::Arc};
22

33
use bao_tree::ChunkRanges;
44
use genawaiter::sync::{Co, Gen};
5-
use n0_future::{Stream, StreamExt};
5+
use n0_future::{time::Duration, Stream, StreamExt};
66
use tracing::{debug, error, info, warn};
77

88
use crate::{api::Store, Hash, HashAndFormat};
@@ -134,7 +134,7 @@ fn gc_sweep<'a>(
134134
#[derive(derive_more::Debug, Clone)]
135135
pub struct GcConfig {
136136
/// Interval in which to run garbage collection.
137-
pub interval: std::time::Duration,
137+
pub interval: Duration,
138138
/// Optional callback to manually add protected blobs.
139139
///
140140
/// The callback is called before each garbage collection run. It gets a `&mut HashSet<Hash>`

src/util/connection_pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::{
1616
atomic::{AtomicUsize, Ordering},
1717
Arc,
1818
},
19-
time::Duration,
2019
};
2120

2221
use iroh::{
@@ -26,6 +25,7 @@ use iroh::{
2625
use n0_error::{e, stack_error};
2726
use n0_future::{
2827
future::{self},
28+
time::Duration,
2929
FuturesUnordered, MaybeFuture, Stream, StreamExt,
3030
};
3131
use tokio::sync::{

0 commit comments

Comments
 (0)