← All Workshops
MudEngine Part 10: Desktop with Blitz
Step 9 / 13
Full main.rs example
Here's the complete src/main.rs. It's a thin entry point that picks a launch per build target — the same file from the steps above, ready to copy wholesale. All the game code lives in src/components/app.rs and src/game/*, unchanged from Part 9.
mud-engine/src/main.rs
mod components; mod game; use crate::components::app::App; // The native client is a separate process: it connects to the Axum server // started by `dx serve` instead of bundling its own server. #[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))] use dioxus::fullstack::set_server_url; #[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))] use dioxus_native::{Config, LogicalSize, WindowAttributes}; fn main() { // Server binary (dx serve → cargo feature `server`): render the SSR page // and serve the WebSocket. #[cfg(feature = "server")] dioxus::launch(App); // Web client (dx serve → wasm target, feature `web`): same origin as the // server, so no `set_server_url` — hydration makes the SSR page live. #[cfg(all(not(feature = "server"), target_arch = "wasm32"))] dioxus::launch(App); // Native client (cargo run): point fullstack at the `dx serve` server and // open a Blitz window (WGPU/Vello) instead of a browser tab. #[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))] { set_server_url("http://localhost:8080"); let cfg = Config::new().with_window_attributes( WindowAttributes::default() .with_title("MudEngine") .with_inner_size(LogicalSize::new(1024.0, 768.0)), ); dioxus_native::launch_cfg(App, vec![], vec![Box::new(cfg)]); } }
🎯 The Blitz migration in a nutshell
- One new dependency —
dioxus-native = "0.7", gated to non-WASM targets ([target.'cfg(not(target_arch = "wasm32"))'.dependencies]) so the web + server builds keep compiling. - A three-way
main.rs— server / web client / native client arms chosen bycfg. - Components untouched — still
use dioxus::prelude::*;, samersx!, signals, server functions, and WebSocket handling as Part 9.
The migration is complete when it compiles under both dx serve (web + server) and cargo run (native).
Step 9 / 13