Skip to content

Commit 3c79c5f

Browse files
committed
feat: compile on wasm32-unknown-unknown
1 parent 9fe3af5 commit 3c79c5f

File tree

8 files changed

+38
-27
lines changed

8 files changed

+38
-27
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[target.wasm32-unknown-unknown]
2+
runner = "wasm-bindgen-test-runner"
3+
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ bao-tree = { version = "0.15.1", features = ["experimental-mixed", "tokio_fsm",
1717
bytes = { version = "1", features = ["serde"] }
1818
derive_more = { version = "2.0.1", features = ["from", "try_from", "into", "debug", "display", "deref", "deref_mut"] }
1919
futures-lite = "2.6.0"
20-
quinn = { package = "iroh-quinn", version = "0.14.0" }
20+
quinn = { package = "iroh-quinn", version = "0.14.0", optional = true }
2121
n0-future = "0.2.0"
2222
n0-snafu = "0.2.2"
2323
range-collections = { version = "0.4.6", features = ["serde"] }
2424
smallvec = { version = "1", features = ["serde", "const_new"] }
2525
snafu = "0.8.5"
26-
tokio = { version = "1.43.0", features = ["full"] }
27-
tokio-util = { version = "0.7.13", features = ["full"] }
26+
tokio = { version = "1.43.0", default-features = false, features = ["sync"] }
2827
tracing = "0.1.41"
2928
iroh-io = "0.6.1"
3029
rand = "0.9.2"
@@ -69,8 +68,11 @@ hide-proto-docs = []
6968
metrics = []
7069
default = ["hide-proto-docs", "fs-store", "rpc"]
7170
fs-store = ["dep:redb", "dep:reflink-copy"]
72-
rpc = ["irpc/rpc", "irpc/quinn_endpoint_setup"]
71+
rpc = ["dep:quinn", "irpc/rpc", "irpc/quinn_endpoint_setup"]
7372

7473
[patch.crates-io]
75-
# irpc = { git = "https://github.com/n0-computer/irpc", branch = "Frando/varint-feature" }
76-
irpc = { path = "../irpc" }
74+
irpc = { git = "https://github.com/n0-computer/irpc", branch = "Frando/varint-feature" }
75+
bao-tree = { git = "https://github.com/n0-computer/bao-tree.git", branch = "Frando/wasm" }
76+
77+
[build-dependencies]
78+
cfg_aliases = "0.2.1"

src/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ impl Store {
308308
/// Listen on a quinn endpoint for incoming rpc connections.
309309
#[cfg(feature = "rpc")]
310310
pub async fn listen(self, endpoint: quinn::Endpoint) {
311-
use self::proto::Request;
312311
use irpc::rpc::RemoteService;
312+
313+
use self::proto::Request;
313314
let local = self.client.as_local().unwrap().clone();
314315
let handler = Request::remote_handler(local);
315316
irpc::rpc::listen::<Request>(endpoint, handler).await

src/provider.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ use std::{
1212

1313
use anyhow::Result;
1414
use bao_tree::ChunkRanges;
15-
use iroh::endpoint::{self, VarInt};
15+
use iroh::endpoint::{self, ConnectionError, VarInt};
1616
use iroh_io::{AsyncStreamReader, AsyncStreamWriter};
1717
use n0_future::StreamExt;
18-
use quinn::ConnectionError;
1918
use serde::{Deserialize, Serialize};
2019
use snafu::Snafu;
2120
use tokio::select;

src/provider/events.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{fmt::Debug, io, ops::Deref};
22

3+
use iroh::endpoint::VarInt;
34
use irpc::{
45
channel::{mpsc, none::NoSender, oneshot},
56
rpc_requests, Channels, WithChannels,
@@ -106,11 +107,11 @@ impl From<ProgressError> for io::Error {
106107
}
107108

108109
pub trait HasErrorCode {
109-
fn code(&self) -> quinn::VarInt;
110+
fn code(&self) -> VarInt;
110111
}
111112

112113
impl HasErrorCode for ProgressError {
113-
fn code(&self) -> quinn::VarInt {
114+
fn code(&self) -> VarInt {
114115
match self {
115116
ProgressError::Limit => ERR_LIMIT,
116117
ProgressError::Permission => ERR_PERMISSION,

src/store/mem.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use irpc::channel::mpsc;
3232
use n0_future::future::yield_now;
3333
use range_collections::range_set::RangeSetRange;
3434
use tokio::{
35-
io::AsyncReadExt,
3635
sync::watch,
3736
task::{JoinError, JoinSet},
3837
};
@@ -755,8 +754,18 @@ async fn import_byte_stream(
755754
import_bytes(res.into(), scope, format, tx).await
756755
}
757756

757+
#[cfg(wasm_browser)]
758+
async fn import_path(cmd: ImportPathMsg) -> anyhow::Result<ImportEntry> {
759+
let _: ImportPathRequest = cmd.inner;
760+
Err(anyhow::anyhow!(
761+
"import_path is not supported in the browser"
762+
))
763+
}
764+
758765
#[instrument(skip_all, fields(path = %cmd.path.display()))]
766+
#[cfg(not(wasm_browser))]
759767
async fn import_path(cmd: ImportPathMsg) -> anyhow::Result<ImportEntry> {
768+
use tokio::io::AsyncReadExt;
760769
let ImportPathMsg {
761770
inner:
762771
ImportPathRequest {

src/util/connection_pool.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use tokio::sync::{
3232
mpsc::{self, error::SendError as TokioSendError},
3333
oneshot, Notify,
3434
};
35-
use tokio_util::time::FutureExt as TimeFutureExt;
3635
use tracing::{debug, error, info, trace};
3736

3837
pub type OnConnected =
@@ -194,8 +193,7 @@ impl Context {
194193
};
195194

196195
// Connect to the node
197-
let state = conn_fut
198-
.timeout(context.options.connect_timeout)
196+
let state = n0_future::time::timeout(context.options.connect_timeout, conn_fut)
199197
.await
200198
.map_err(|_| PoolConnectError::Timeout)
201199
.and_then(|r| r);

0 commit comments

Comments
 (0)