← All Workshops

MudEngine Part 11: Peer-to-Peer with iroh

Step 3 / 14

Add the P2P dependencies

The fullstack crates go away; iroh and its machinery come in.

Two things worth knowing before you edit Cargo.toml:

  • iroh-gossip is its own crate in iroh 1.x. There is no "gossip" feature on iroh to enable — you depend on iroh and iroh-gossip (0.101.x, whose API matches iroh 1.2) separately, and iroh-gossip::ALPN registers the gossip protocol on your endpoint.
  • tokio gets split in two. The base dependency keeps a feature set that also compiles on wasm (macros, rt, sync, time — the same set Parts 8–9 used). The native-only extras (rt-multi-thread) join in a cfg(not(target_arch = "wasm32")) block, so dx build --web still compiles. Rule of thumb for this crate: wasm-safe features in [dependencies], everything else behind the native target gate.
mud-engine/Cargo.toml
[package]
name = "mud-engine"
version = "0.1.0"
edition = "2024"

[dependencies]
dioxus = { version = "=0.7.10", features = ["web"] }
dioxus-primitives = { git = "https://github.com/DioxusLabs/components", version = "0.0.1", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
uuid = { version = "1", features = ["v4", "js"] }
# Channel + async glue shared by every transport. Stick to the tokio feature
# set that also compiles on wasm; the wasm-incompatible extras join below.
tokio = { version = "1", features = ["macros", "rt", "sync", "time"] }
toml = "1.1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["rt-multi-thread"] }
# Desktop renderer — stays out of the wasm build (see note on the old `server`/`web` split)
dioxus-native = "0.7"
# Peer-to-peer transport (Part 11): QUIC endpoints + the gossip plumtree mesh.
# `iroh-mdns-address-lookup` lets a client find the host's LAN address from its
# node id alone, so same-network peers dial directly instead of via the relay.
iroh = "1.2.0"
iroh-gossip = "0.101.0"
iroh-mdns-address-lookup = "0.5.0"
# Gossip topic id = blake3 hash of the topic name; gossip streams use n0_future
blake3 = "1"
n0-future = "0.3"

[package.metadata.rust-analyzer]
cargo.features = ["web"]

[features]
default = ["web"]
web = ["dioxus/web"]

# Build-environment workaround: the crates.io `stylo 0.8.0` used by blitz-dom 0.2.4
# does `#[macro_use] extern crate derive_more;`. iroh (Part 11) enables derive_more's
# `debug` macro, which feature-unifies into stylo's build and explodes its 300+
# `#[derive(Debug)]`s with error[E0275]. We vendor stylo 0.8.0 with a one-line fix
# (explicit `use` of only Add/AddAssign/Deref/DerefMut/From) so the desktop renderer
# and iroh can coexist. Upstream fix lives in stylo >= 0.11; drop this patch when
# blitz-dom allows it.
[patch.crates-io]
stylo = { path = "third_party/stylo" }

[lints.rust]
unused = "allow"

[dev-dependencies]
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
🔍 What changed
RemovedAdded
dioxus/fullstackiroh = "1.2.0"
dioxus-fullstackiroh-gossip = "0.101.0" (its own crate)
server = ["dioxus/server"] featureiroh-mdns-address-lookup = "0.5.0" (LAN shortcut)
—blake3 + n0-future (topic id + stream helpers)
—serde_json (wire serialization)
—native-gated tokio rt-multi-thread
—[patch.crates-io] stylo + vendored third_party/stylo
⚠️ The stylo patch — read before your first cargo build

First cargo build of a Part 11 crate will hit error[E0275]: overflow evaluating the requirement on the Blitz renderer, not your code. Blitz's blitz-dom 0.2.4 pulls stylo 0.8.0, and a stock stylo does #[macro_use] extern crate derive_more;. iroh enables derive_more's debug feature, which feature-unifies into stylo's build and explodes every #[derive(Debug)] it has.

The fix is a vendored stylo with a one-line patch — this is a build-environment workaround, not game logic. The [patch.crates-io] section in the new Cargo.toml above points at third_party/stylo. Do this once, from mud-engine/:

mkdir -p third_party
cp -a "$(find ~/.cargo/registry/src -maxdepth 2 -type d -name 'stylo-0.8.0' | head -1)" third_party/stylo

then open third_party/stylo/lib.rs and replace the #[macro_use] extern crate derive_more; import with the five-derive re-export the crate actually uses:

mod derives {
    pub(crate) use derive_more::{Add, AddAssign, Deref, DerefMut, From};
}

Every module that derives those macros now needs use crate::derives::*; at the top — in stylo 0.8.0 that is nine files: values/mod.rs, values/generics/basic_shape.rs, values/computed/angle.rs, values/distance.rs, context.rs, stylesheets/rule_parser.rs, gecko_string_cache/namespace.rs, gecko/data.rs, and stylist.rs. The Mako-generated properties helpers pick up the same line from their templates. Keep applying it until cargo check is green. Upstream fixed this in stylo ≥ 0.11 — once blitz-dom allows that version, delete the patch and the vendor directory.

Step 3 / 14