Skip to content

Commit c450470

Browse files
authored
Merge pull request #16 from n0-computer/Frando/wasm
fix: build on wasm
2 parents af32517 + 85e5e90 commit c450470

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
branches:
1010
- main
1111

12-
1312
concurrency:
1413
group: tests-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1514
cancel-in-progress: true
@@ -58,8 +57,16 @@ jobs:
5857
toolchain: ${{ matrix.channel }}
5958
targets: ${{ matrix.target.toolchain }}
6059
- uses: swatinem/rust-cache@v2
61-
- name: cargo test
60+
- name: cargo test (all features)
6261
run: cargo test --locked --workspace --all-features --bins --tests --examples
62+
- name: cargo test (default features)
63+
run: cargo test --locked --workspace --bins --tests --examples
64+
- name: cargo test (no default features)
65+
run: cargo test --locked --workspace --no-default-features --bins --tests --examples
66+
- name: cargo check (feature message_spans)
67+
run: cargo check --no-default-features --features message_spans
68+
- name: cargo check (feature rpc)
69+
run: cargo check --no-default-features --features rpc
6370

6471
test-release:
6572
runs-on: ${{ matrix.target.os }}
@@ -92,6 +99,26 @@ jobs:
9299
- name: cargo test
93100
run: cargo test --release --locked --workspace --all-features --bins --tests --examples
94101

102+
wasm_build:
103+
name: Build wasm32
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: Checkout sources
107+
uses: actions/checkout@v4
108+
- name: Install stable toolchain
109+
uses: dtolnay/rust-toolchain@stable
110+
- name: Add wasm target
111+
run: rustup target add wasm32-unknown-unknown
112+
- name: Install wasm-tools
113+
uses: bytecodealliance/actions/wasm-tools/setup@v1
114+
- name: wasm32 build
115+
run: cargo build --target wasm32-unknown-unknown
116+
# If the Wasm file contains any 'import "env"' declarations, then
117+
# some non-Wasm-compatible code made it into the final code.
118+
- name: Ensure no 'import "env"' in iroh-relay Wasm
119+
run: |
120+
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/irpc.wasm | grep 'import "env"'
121+
95122
# Checks correct runtime deps and features are requested by not including dev-dependencies.
96123
check-deps:
97124
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ anyhow = { workspace = true, optional = true }
3939
# used in the benches
4040
futures-buffered ={ version = "0.2.9", optional = true }
4141
# for AbortOnDropHandle
42-
n0-future = { workspace = true, optional = true }
42+
n0-future = { workspace = true }
4343
futures-util = { workspace = true, optional = true }
4444

4545
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
@@ -60,11 +60,11 @@ trybuild = "1.0.104"
6060

6161
[features]
6262
# enable the remote transport
63-
rpc = ["dep:quinn", "dep:postcard", "dep:anyhow", "dep:smallvec", "dep:tracing", "dep:n0-future", "tokio/io-util"]
63+
rpc = ["dep:quinn", "dep:postcard", "dep:anyhow", "dep:smallvec", "dep:tracing", "tokio/io-util"]
6464
# add test utilities
6565
quinn_endpoint_setup = ["rpc", "dep:rustls", "dep:rcgen", "dep:anyhow", "dep:futures-buffered", "quinn/rustls-ring"]
6666
# pick up parent span when creating channel messages
67-
message_spans = []
67+
message_spans = ["dep:tracing"]
6868
stream = ["dep:futures-util"]
6969
default = ["rpc", "quinn_endpoint_setup", "message_spans", "stream"]
7070

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
#![cfg_attr(quicrpc_docsrs, feature(doc_cfg))]
7979
use std::{fmt::Debug, future::Future, io, marker::PhantomData, ops::Deref};
8080

81-
use n0_future::boxed::BoxFuture;
8281
use sealed::Sealed;
8382
use serde::{de::DeserializeOwned, Serialize};
8483

@@ -141,7 +140,7 @@ pub mod channel {
141140
pub mod oneshot {
142141
use std::{fmt::Debug, future::Future, io, pin::Pin, task};
143142

144-
use n0_future::boxed::BoxFuture;
143+
use n0_future::future::Boxed as BoxFuture;
145144

146145
use super::{RecvError, SendError};
147146
use crate::util::FusedOneshotReceiver;
@@ -179,7 +178,7 @@ pub mod channel {
179178
/// Remote receivers are always boxed, since for remote communication the boxing
180179
/// overhead is negligible. However, boxing can also be used for local communication,
181180
/// e.g. when applying a transform or filter to the message before receiving it.
182-
pub type BoxedReceiver<T> = crate::BoxFuture<io::Result<T>>;
181+
pub type BoxedReceiver<T> = BoxFuture<io::Result<T>>;
183182

184183
/// A oneshot sender.
185184
///
@@ -1093,7 +1092,7 @@ pub mod rpc {
10931092
//! Module for cross-process RPC using [`quinn`].
10941093
use std::{fmt::Debug, future::Future, io, marker::PhantomData, pin::Pin, sync::Arc};
10951094

1096-
use n0_future::task::JoinSet;
1095+
use n0_future::{future::Boxed as BoxFuture, task::JoinSet};
10971096
use quinn::ConnectionError;
10981097
use serde::{de::DeserializeOwned, Serialize};
10991098
use smallvec::SmallVec;
@@ -1107,7 +1106,7 @@ pub mod rpc {
11071106
RecvError, SendError,
11081107
},
11091108
util::{now_or_never, AsyncReadVarintExt, WriteVarintExt},
1110-
BoxFuture, RequestError, RpcMessage,
1109+
RequestError, RpcMessage,
11111110
};
11121111

11131112
/// Error that can occur when writing the initial message when doing a

0 commit comments

Comments
 (0)