CodeVetter · Repo Unpack · System map
rustdesk/rustdesk
One Cargo package (`rustdesk`, lib name `librustdesk`, crate-type cdylib+staticlib+rlib) produces the main `rustdesk` binary plus helper bins `service` (macOS) and `naming`, while `libs/portable` builds a self-extracting portable packer. `src/` holds the cross-platform core; `src/platform/` and `src/server/` hold OS- and host-side code; `flutter/` is the current UI (legacy Sciter UI in `src/ui/` is deprecated); `libs/` is a Cargo workspace of vendored crates. `libs/hbb_common` is a git submodule shared with rustdesk-server — it is empty in this clone. CI is GitHub Actions driven by `flutter-build.yml` (reusable) and `flutter-ci.yml` (PR gate).
- The crate builds as `librustdesk` with crate-type [cdylib, staticlib, rlib] so the same code backs the desktop binary, the Flutter dynamic library, and mobile FFI; `default-run = "rustdesk"` and extra bins `naming` (src/naming.rs) and `service` (src/service.rs) are declared.
- The default `main()` in src/main.rs is a thin shell: it calls `core_main::core_main()` and, if it returns Some(args), starts the UI via `ui::start(args)`; under feature `flutter` or mobile targets, `main` only runs `common::global_init()` + rendezvous/NAT diagnostics because the real app entry is the Flutter engine loading the library.
- core_main() is the CLI dispatcher: flags like `--server`, `--tray`, `--cm`, `--service`, `--install`, `--password`, `--get-id`, `--option`, `--assign`, `--deploy`, `--connect`/`--file-transfer`/`--terminal`/`--rdp` are parsed positionally from std::env::args and each maps to a subsystem call.
- Workspace members are libs/scrap (screen capture), libs/hbb_common (protocol/Config submodule), libs/base (client-only protos+fs+keys), libs/enigo (input injection), libs/clipboard, libs/virtual_display(+dylib), libs/portable, libs/remote_printer; `vdi/host` is excluded.
- crates-io is patched: `libxdo-sys` is replaced by libs/libxdo-sys-stub (so builds work without libxdo on Wayland-only systems), and `tungstenite`, `webrtc`, `webrtc-util`, `webrtc-sctp` are pinned by git rev to rustdesk-org forks carrying custom fixes (incremental ws read buffer, Windows IPv6 ICE, SCTP congestion-control off by default).
- Feature flags gate major subsystems: `flutter` (flutter_rust_bridge =1.80), `hwcodec`/`vram`/`mediacodec` (hardware codecs via scrap), `drm` and separately `drm-wake` (Linux DRM/KMS capture plus an opt-in synthetic pointer wake), `unix-file-copy-paste`, `inline` (legacy Sciter in-process UI), and resampler backends `use_dasp`(default)/`use_rubato`/`use_samplerate`.
- Server-side runtime is `Server` in src/server.rs: a `ServerPtr = Arc<RwLock<Server>>` holding `connections: HashMap<i32, ConnInner>` and `services: HashMap<String, Box<dyn Service>>`; `new()` registers audio, display, clipboard, input (cursor/pos/window-focus), and (Windows+flutter) printer services.
- IPC between the privileged `--server` process, the user UI process, and the `--cm` connection manager uses parity_tokio_ipc (Unix sockets / Windows named pipes) framed by BytesCodec and serde-tagged JSON `enum Data` (Login, Authorize, Close, SyncConfig, FS, ClipboardFile, SwitchSides*, UrlLink, DataPortableService, ...).
- The Flutter UI lives in flutter/ (package flutter_hbb 1.5.0+68): lib/main.dart dispatches on boot args — `multi_window <id> <json>` for remote/file-transfer/camera/port-forward/terminal windows, `--cm` for the connection manager, `--install` for the install page, default for the main window; state uses provider/getX and FFI goes through flutter_rust_bridge 1.80.
- Rust↔Flutter bridge: src/flutter_ffi.rs exposes hundreds of `pub fn` (session_add_sync, session_start, peer_get_sessions_count, start_global_event_stream...) generated into `src/bridge_generated.rs` (mod declared in lib.rs), while Rust pushes events back over `StreamSink` global event streams keyed by app type (`main`, `cm`).
- Build tooling: `build.py` drives cargo build + flutter build + packaging per-OS; `build.rs` (cc, hbb_common, os-version) compiles platform C/C++; `vcpkg.json` + vcpkg install libvpx/libyuv/opus/aom for native codec deps; the Dockerfile builds a Debian trixie image with vcpkg, cmake 3.30.6, gtk/xcb/pulse dev packages for Linux builds.
- Release profile sets lto, codegen-units=1, panic='abort', strip — and panic=abort means any panic in the Rust core kills the whole process including the Flutter UI.
- CI: .github/workflows/flutter-ci.yml is the PR/push gate that simply calls the reusable flutter-build.yml with upload-artifact=false; flutter-build.yml pins RUST_VERSION 1.75 (1.81 macOS), FLUTTER_VERSION 3.24.5 (3.44.9 for Windows arm64), NDK r28c, and a fixed VCPKG_COMMIT_ID.