Skip to content

Commit 56c8cc0

Browse files
authored
Merge a4320cd into 1f79c18
2 parents 1f79c18 + a4320cd commit 56c8cc0

File tree

24 files changed

+163
-78
lines changed

24 files changed

+163
-78
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"']

.github/workflows/ci.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,43 @@ jobs:
277277
- uses: actions/checkout@v5
278278
- run: pip install --user codespell[toml]
279279
- run: codespell --ignore-words-list=ans,atmost,crate,inout,ratatui,ser,stayin,swarmin,worl --skip=CHANGELOG.md
280+
281+
wasm_build:
282+
name: Build & test wasm32
283+
runs-on: ubuntu-latest
284+
env:
285+
RUSTFLAGS: '--cfg getrandom_backend="wasm_js"'
286+
steps:
287+
- name: Checkout sources
288+
uses: actions/checkout@v4
289+
290+
- name: Install Node.js
291+
uses: actions/setup-node@v4
292+
with:
293+
node-version: 20
294+
295+
- name: Install stable toolchain
296+
uses: dtolnay/rust-toolchain@stable
297+
298+
- name: Add wasm target
299+
run: rustup target add wasm32-unknown-unknown
300+
301+
- name: Install wasm-tools
302+
uses: bytecodealliance/actions/wasm-tools/setup@v1
303+
304+
- name: Install wasm-pack
305+
uses: taiki-e/install-action@v2
306+
with:
307+
tool: wasm-bindgen,wasm-pack
308+
309+
- name: wasm32 build
310+
run: cargo build --target wasm32-unknown-unknown --no-default-features
311+
312+
# If the Wasm file contains any 'import "env"' declarations, then
313+
# some non-Wasm-compatible code made it into the final code.
314+
- name: Ensure no 'import "env"' in wasm
315+
run: |
316+
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/iroh_blobs.wasm | grep 'import "env"'
317+
318+
- name: wasm32 test
319+
run: wasm-pack test --node

Cargo.lock

Lines changed: 7 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: 22 additions & 7 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.3.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"
@@ -36,12 +35,12 @@ chrono = "0.4.39"
3635
nested_enum_utils = "0.2.1"
3736
ref-cast = "1.0.24"
3837
arrayvec = "0.7.6"
39-
iroh = "0.94"
38+
iroh = { version = "0.94", default-features = false }
4039
self_cell = "1.1.0"
4140
genawaiter = { version = "0.99.1", features = ["futures03"] }
4241
iroh-base = "0.94"
4342
iroh-tickets = "0.1"
44-
irpc = { version = "0.10.0", features = ["rpc", "quinn_endpoint_setup", "spans", "stream", "derive"], default-features = false }
43+
irpc = { version = "0.10.0", features = ["spans", "stream", "derive", "varint-util"], default-features = false }
4544
iroh-metrics = { version = "0.36" }
4645
redb = { version = "2.6.3", optional = true }
4746
reflink-copy = { version = "0.1.24", optional = true }
@@ -64,8 +63,24 @@ iroh = { version = "0.94", features = ["discovery-local-network"]}
6463
async-compression = { version = "0.4.30", features = ["lz4", "tokio"] }
6564
concat_const = "0.2.0"
6665

66+
[build-dependencies]
67+
cfg_aliases = "0.2.1"
68+
6769
[features]
6870
hide-proto-docs = []
6971
metrics = []
70-
default = ["hide-proto-docs", "fs-store"]
71-
fs-store = ["dep:redb", "dep:reflink-copy"]
72+
default = ["hide-proto-docs", "fs-store", "rpc"]
73+
fs-store = ["dep:redb", "dep:reflink-copy", "bao-tree/fs"]
74+
rpc = ["dep:quinn", "irpc/rpc", "irpc/quinn_endpoint_setup"]
75+
76+
[[example]]
77+
name = "expiring-tags"
78+
required-features = ["fs-store"]
79+
80+
[[example]]
81+
name = "random_store"
82+
required-features = ["fs-store"]
83+
84+
[patch.crates-io]
85+
irpc = { git = "https://github.com/n0-computer/irpc", branch = "main" }
86+
bao-tree = { git = "https://github.com/n0-computer/bao-tree", branch = "main" }

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use cfg_aliases::cfg_aliases;
2+
3+
fn main() {
4+
// Setup cfg aliases
5+
cfg_aliases! {
6+
// Convenience aliases
7+
wasm_browser: { all(target_family = "wasm", target_os = "unknown") },
8+
}
9+
}

examples/expiring-tags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,17 @@ async fn print_store_info(store: &Store) -> anyhow::Result<()> {
122122
}
123123

124124
async fn info_task(store: Store) -> anyhow::Result<()> {
125-
tokio::time::sleep(Duration::from_secs(1)).await;
125+
n0_future::time::sleep(Duration::from_secs(1)).await;
126126
loop {
127127
print_store_info(&store).await?;
128-
tokio::time::sleep(Duration::from_secs(5)).await;
128+
n0_future::time::sleep(Duration::from_secs(5)).await;
129129
}
130130
}
131131

132132
async fn delete_expired_tags_task(store: Store, prefix: &str) -> anyhow::Result<()> {
133133
loop {
134134
delete_expired_tags(&store, prefix, false).await?;
135-
tokio::time::sleep(Duration::from_secs(5)).await;
135+
n0_future::time::sleep(Duration::from_secs(5)).await;
136136
}
137137
}
138138

examples/limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn throttle(delay_ms: u64) -> EventSender {
156156
);
157157
// we could compute the delay from the size of the data to have a fixed rate.
158158
// but the size is almost always 16 KiB (16 chunks).
159-
tokio::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
159+
n0_future::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
160160
msg.tx.send(Ok(())).await.ok();
161161
});
162162
}

src/api.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
//!
1313
//! You can also [`connect`](Store::connect) to a remote store that is listening
1414
//! to rpc requests.
15-
use std::{io, net::SocketAddr, ops::Deref};
15+
use std::{io, ops::Deref};
1616

1717
use bao_tree::io::EncodeError;
1818
use iroh::Endpoint;
19-
use irpc::rpc::{listen, RemoteService};
2019
use n0_snafu::SpanTrace;
2120
use nested_enum_utils::common_fields;
22-
use proto::{Request, ShutdownRequest, SyncDbRequest};
21+
use proto::{ShutdownRequest, SyncDbRequest};
2322
use ref_cast::RefCast;
2423
use serde::{Deserialize, Serialize};
2524
use snafu::{Backtrace, IntoError, Snafu};
@@ -128,6 +127,7 @@ impl From<irpc::Error> for ExportBaoError {
128127
irpc::Error::OneshotRecv(e) => OneshotRecvSnafu.into_error(e),
129128
irpc::Error::Send(e) => SendSnafu.into_error(e),
130129
irpc::Error::Request(e) => RequestSnafu.into_error(e),
130+
#[cfg(feature = "rpc")]
131131
irpc::Error::Write(e) => ExportBaoIoSnafu.into_error(e.into()),
132132
}
133133
}
@@ -220,6 +220,7 @@ impl From<irpc::channel::mpsc::RecvError> for Error {
220220
}
221221
}
222222

223+
#[cfg(feature = "rpc")]
223224
impl From<irpc::rpc::WriteError> for Error {
224225
fn from(e: irpc::rpc::WriteError) -> Self {
225226
Self::Io(e.into())
@@ -298,16 +299,21 @@ impl Store {
298299
}
299300

300301
/// Connect to a remote store as a rpc client.
301-
pub fn connect(endpoint: quinn::Endpoint, addr: SocketAddr) -> Self {
302+
#[cfg(feature = "rpc")]
303+
pub fn connect(endpoint: quinn::Endpoint, addr: std::net::SocketAddr) -> Self {
302304
let sender = irpc::Client::quinn(endpoint, addr);
303305
Store::from_sender(sender)
304306
}
305307

306308
/// Listen on a quinn endpoint for incoming rpc connections.
309+
#[cfg(feature = "rpc")]
307310
pub async fn listen(self, endpoint: quinn::Endpoint) {
311+
use irpc::rpc::RemoteService;
312+
313+
use self::proto::Request;
308314
let local = self.client.as_local().unwrap().clone();
309315
let handler = Request::remote_handler(local);
310-
listen::<Request>(endpoint, handler).await
316+
irpc::rpc::listen::<Request>(endpoint, handler).await
311317
}
312318

313319
pub async fn sync_db(&self) -> RequestResult<()> {

src/api/downloader.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ use anyhow::bail;
1010
use genawaiter::sync::Gen;
1111
use iroh::{Endpoint, EndpointId};
1212
use irpc::{channel::mpsc, rpc_requests};
13-
use n0_future::{future, stream, BufferedStreamExt, Stream, StreamExt};
13+
use n0_future::{future, stream, task::JoinSet, BufferedStreamExt, Stream, StreamExt};
1414
use rand::seq::SliceRandom;
1515
use serde::{de::Error, Deserialize, Serialize};
16-
use tokio::task::JoinSet;
1716
use tracing::instrument::Instrument;
1817

1918
use super::Store;
@@ -31,7 +30,7 @@ pub struct Downloader {
3130
client: irpc::Client<SwarmProtocol>,
3231
}
3332

34-
#[rpc_requests(message = SwarmMsg, alias = "Msg")]
33+
#[rpc_requests(message = SwarmMsg, alias = "Msg", rpc_feature = "rpc")]
3534
#[derive(Debug, Serialize, Deserialize)]
3635
enum SwarmProtocol {
3736
#[rpc(tx = mpsc::Sender<DownloadProgressItem>)]
@@ -42,7 +41,7 @@ struct DownloaderActor {
4241
store: Store,
4342
pool: ConnectionPool,
4443
tasks: JoinSet<()>,
45-
running: HashSet<tokio::task::Id>,
44+
running: HashSet<n0_future::task::Id>,
4645
}
4746

4847
#[derive(Debug, Serialize, Deserialize)]
@@ -342,7 +341,7 @@ impl Downloader {
342341
pub fn new(store: &Store, endpoint: &Endpoint) -> Self {
343342
let (tx, rx) = tokio::sync::mpsc::channel::<SwarmMsg>(32);
344343
let actor = DownloaderActor::new(store.clone(), endpoint.clone());
345-
tokio::spawn(actor.run(rx));
344+
n0_future::task::spawn(actor.run(rx));
346345
Self { client: tx.into() }
347346
}
348347

src/api/proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl HashSpecific for CreateTagMsg {
8787
}
8888
}
8989

90-
#[rpc_requests(message = Command, alias = "Msg")]
90+
#[rpc_requests(message = Command, alias = "Msg", rpc_feature = "rpc")]
9191
#[derive(Debug, Serialize, Deserialize)]
9292
pub enum Request {
9393
#[rpc(tx = mpsc::Sender<super::Result<Hash>>)]

0 commit comments

Comments
 (0)