libp2p / libp2p/rust-libp2p

wasm-pack build fails for WebRTC + gossipsub in libp2p v0.56.0 due to ahash → getrandom v0.3.4

Open
#6,246 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.6k
Forks
1.3k
Avg merge
8h 47m
Merged PRs (30d)
19

Description

Summary

When building a WASM P2P node with gossipsub and webrtc-websys in libp2p v0.56.0, the build fails due to an unresolved getrandom backend requirement, even though all correct features are enabled.

This blocks browser-to-browser gossipsub in WASM until either:

  • The ahash dependency is fully removed from gossipsub, or
  • Proper WebRTC transport APIs are exposed in SwarmBuilder.

Steps to Reproduce

  1. Create a minimal WASM crate with:
    [dependencies.libp2p]
    version = "0.56.0"
    default-features = false
    features = [
      "webrtc-websys",
      "noise",
      "wasm-bindgen",
      "gossipsub"
    ]
    
    
    
  2. Implement a basic NetworkBehaviour with gossipsub::Behaviour
  3. Try to build with:wasm-pack build --target web
    4.Expected Behavior
    Compiles successfully (as implied by docs and examples)
    WebRTC transport works via .with_webrtc() or equivalent

Actual Behavior
Error 1: Missing .with_webrtc() method
error[E0599]: no method named with_webrtc found for struct SwarmBuilder<...>

Error 2: getrandom v0.3.4 fails in WASM

This happens because:

libp2p-gossipsub v0.49.2 → hashlink → hashbrown → ahash → getrandom v0.3.4
ahash does not enable the wasm_js feature on its getrandom dependency
Even if I add getrandom = { version = "0.3.4", features = ["wasm_js"] },
Cargo doesn’t propagate the feature to transitive deps

Workarounds Tried
✅ Removing gossipsub → compiles (but loses pubsub)
✅ Using websocket-websys instead → works, but requires relay
❌ Adding "serde" or "other" features → doesn’t fix missing .with_webrtc()
❌ Patching getrandom → fails due to ahash hard dependency

Environment
libp2p version: 0.56.0
Rust version: rustc 1.83.0 (or latest stable)
Target: wasm32-unknown-unknown
OS: Windows 11 (but reproducible on Linux/macOS)

Additional Context
PR #5098 replaced ahash with fxhash, which should fix the getrandom issue
However, v0.56.0 still uses ahash, and there’s no published version with the fix
Also, the WebRTC transport API (SwarmBuilder::with_webrtc()) appears to be missing or unstable

Request
Release v0.57.0 with the ahash → fxhash migration (from #5098)
Document the correct way to use WebRTC in WASM — current examples reference .with_webrtc(), but it doesn’t exist in v0.56.0
Clarify whether gossipsub is truly WASM-compatible today

Thank you for your work on libp2p

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimal crate described in the issue with libp2p 0.56.0 and wasm-pack, then inspect the gossipsub dependency path through ahash and getrandom and the documented SwarmBuilder WebRTC entry point. Done means the WASM build behavior and WebRTC API usage are either fixed or clearly documented, with the requested version status addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
audio-video-rtc, build-system, distributed-systems, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.