Skip to content

Commit 6f923a3

Browse files
authored
feat(iroh-net-report): Support wasm32 building & running (#3139)
## Description This makes iroh-net-report compile to Wasm. We make sure it's likely to work by grepping the generated Wasm file for "env" imports (which would make it not work in browsers). Mostly this will disable functionality in iroh-net-report for the browser target - specifically, it disables STUN, QAD, ICMP and all other probes besides HTTPS to relays. I've experimentally verified this code works with an integration test, it's really hard to come up with a good strategy for automating this testing due to requiring running cross-languages. I'd like to do that as a follow-up once #3145 is merged. ## Change checklist - [x] Self-review. - [x] 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.
1 parent f0abede commit 6f923a3

File tree

10 files changed

+629
-277
lines changed

10 files changed

+629
-277
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,20 @@ jobs:
169169
- name: wasm32 build (iroh-relay)
170170
run: cargo build --target wasm32-unknown-unknown -p iroh-relay --no-default-features
171171

172+
- name: wasm32 build (iroh-net-report)
173+
run: cargo build --target wasm32-unknown-unknown -p iroh-net-report --no-default-features
174+
172175
# If the Wasm file contains any 'import "env"' declarations, then
173176
# some non-Wasm-compatible code made it into the final code.
174177
- name: Ensure no 'import "env"' in iroh-relay Wasm
175178
run: |
176179
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/iroh_relay.wasm | grep 'import "env"'
180+
181+
# If the Wasm file contains any 'import "env"' declarations, then
182+
# some non-Wasm-compatible code made it into the final code.
183+
- name: Ensure no 'import "env"' in iroh-net-report Wasm
184+
run: |
185+
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/iroh_net_report.wasm | grep 'import "env"'
177186
178187

179188
check_semver:

Cargo.lock

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

iroh-net-report/Cargo.toml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,49 @@ keywords = ["networking"]
1212
# Sadly this also needs to be updated in .github/workflows/ci.yml
1313
rust-version = "1.81"
1414

15+
[lib]
16+
crate-type = ["lib", "cdylib"] # cdylib is needed for Wasm support
17+
1518
[lints]
1619
workspace = true
1720

1821
[dependencies]
1922
anyhow = "1"
2023
bytes = "1.7"
2124
derive_more = { version = "1.0.0", features = ["display"] }
22-
hickory-resolver = "=0.25.0-alpha.5"
2325
iroh-base = { version = "0.32.0", path = "../iroh-base", default-features = false, features = ["relay"] }
2426
iroh-metrics = { version = "0.31", default-features = false }
25-
iroh-relay = { version = "0.32", path = "../iroh-relay" }
27+
iroh-relay = { version = "0.32", default-features = false, path = "../iroh-relay" }
2628
n0-future = "0.1.2"
27-
netwatch = { version = "0.3" }
28-
portmapper = { version = "0.3", default-features = false }
29-
quinn = { package = "iroh-quinn", version = "0.13.0" }
29+
quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false }
3030
rand = "0.8"
31-
reqwest = { version = "0.12", default-features = false }
31+
reqwest = { version = "0.12", default-features = false, features = ["stream"] }
3232
rustls = { version = "0.23", default-features = false }
33-
surge-ping = "0.8.0"
3433
thiserror = "2"
3534
tokio = { version = "1", default-features = false, features = ["sync", "time", "macros", "rt"] }
3635
tokio-util = { version = "0.7.12", default-features = false }
3736
tracing = "0.1"
3837
url = { version = "2.4" }
3938

39+
# non-wasm-in-browser dependencies
40+
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
41+
hickory-resolver = "=0.25.0-alpha.5"
42+
netwatch = { version = "0.3" }
43+
portmapper = { version = "0.3", default-features = false }
44+
surge-ping = "0.8.0"
45+
4046
[dev-dependencies]
47+
futures-lite = "2.3"
4148
iroh-relay = { path = "../iroh-relay", features = ["test-utils", "server"] }
4249
pretty_assertions = "1.4"
50+
quinn = { package = "iroh-quinn", version = "0.13.0" }
4351
testresult = "0.4.0"
4452
tokio = { version = "1", default-features = false, features = ["test-util"] }
4553
tracing-test = "0.2.5"
4654

55+
[build-dependencies]
56+
cfg_aliases = { version = "0.2" }
57+
4758
[features]
4859
default = ["metrics"]
4960
metrics = ["iroh-metrics/metrics", "portmapper/metrics"]

iroh-net-report/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+
}

0 commit comments

Comments
 (0)