Skip to content

Commit

Permalink
feat(iroh-net-report): Support wasm32 building & running (#3139)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
matheus23 authored Feb 14, 2025
1 parent f0abede commit 6f923a3
Show file tree
Hide file tree
Showing 10 changed files with 629 additions and 277 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,20 @@ jobs:
- name: wasm32 build (iroh-relay)
run: cargo build --target wasm32-unknown-unknown -p iroh-relay --no-default-features

- name: wasm32 build (iroh-net-report)
run: cargo build --target wasm32-unknown-unknown -p iroh-net-report --no-default-features

# If the Wasm file contains any 'import "env"' declarations, then
# some non-Wasm-compatible code made it into the final code.
- name: Ensure no 'import "env"' in iroh-relay Wasm
run: |
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/iroh_relay.wasm | grep 'import "env"'
# If the Wasm file contains any 'import "env"' declarations, then
# some non-Wasm-compatible code made it into the final code.
- name: Ensure no 'import "env"' in iroh-net-report Wasm
run: |
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/iroh_net_report.wasm | grep 'import "env"'

check_semver:
Expand Down
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions iroh-net-report/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,49 @@ keywords = ["networking"]
# Sadly this also needs to be updated in .github/workflows/ci.yml
rust-version = "1.81"

[lib]
crate-type = ["lib", "cdylib"] # cdylib is needed for Wasm support

[lints]
workspace = true

[dependencies]
anyhow = "1"
bytes = "1.7"
derive_more = { version = "1.0.0", features = ["display"] }
hickory-resolver = "=0.25.0-alpha.5"
iroh-base = { version = "0.32.0", path = "../iroh-base", default-features = false, features = ["relay"] }
iroh-metrics = { version = "0.31", default-features = false }
iroh-relay = { version = "0.32", path = "../iroh-relay" }
iroh-relay = { version = "0.32", default-features = false, path = "../iroh-relay" }
n0-future = "0.1.2"
netwatch = { version = "0.3" }
portmapper = { version = "0.3", default-features = false }
quinn = { package = "iroh-quinn", version = "0.13.0" }
quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false }
rand = "0.8"
reqwest = { version = "0.12", default-features = false }
reqwest = { version = "0.12", default-features = false, features = ["stream"] }
rustls = { version = "0.23", default-features = false }
surge-ping = "0.8.0"
thiserror = "2"
tokio = { version = "1", default-features = false, features = ["sync", "time", "macros", "rt"] }
tokio-util = { version = "0.7.12", default-features = false }
tracing = "0.1"
url = { version = "2.4" }

# non-wasm-in-browser dependencies
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
hickory-resolver = "=0.25.0-alpha.5"
netwatch = { version = "0.3" }
portmapper = { version = "0.3", default-features = false }
surge-ping = "0.8.0"

[dev-dependencies]
futures-lite = "2.3"
iroh-relay = { path = "../iroh-relay", features = ["test-utils", "server"] }
pretty_assertions = "1.4"
quinn = { package = "iroh-quinn", version = "0.13.0" }
testresult = "0.4.0"
tokio = { version = "1", default-features = false, features = ["test-util"] }
tracing-test = "0.2.5"

[build-dependencies]
cfg_aliases = { version = "0.2" }

[features]
default = ["metrics"]
metrics = ["iroh-metrics/metrics", "portmapper/metrics"]
Expand Down
9 changes: 9 additions & 0 deletions iroh-net-report/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use cfg_aliases::cfg_aliases;

fn main() {
// Setup cfg aliases
cfg_aliases! {
// Convenience aliases
wasm_browser: { all(target_family = "wasm", target_os = "unknown") },
}
}
Loading

0 comments on commit 6f923a3

Please sign in to comment.