Porting a cross-platform GUI application to Rust
Firefox's crash reporter was rewritten in Rust, replacing three separate native GUI implementations (Win32, GTK, macOS) and their C++/Objective-C glue, which had no test suite, with a small custom UI abstraction. The reporter must run independently of Firefox code and avoid large dependencies, so third-party GUI crates were rejected. Instead a declarative UI model borrowed from GTK concepts is built with an ElementBuilder and a ui! macro, wired up through simple data-binding primitives (events, synchronized values, on-demand values) in an MVVM-like style. Each platform backend implements just run_loop and invoke, and a virtual test backend lets the UI be tested.
Related posts
- Why the big rewrite?
Zed easyNoviceZed rewrote its Rust UI framework from GPUI 1 to GPUI 2 because the original design blocked fast UI work: a Flutter-style constraints-down/sizes-up layout model, styles split between Rust element code and TypeScript-generated JSON "themes" loaded at runtime, model code entangled with presentation (a legacy of an early Electron/JSON architecture), and weakly typed geometry (raw f32s and usizes). GPUI 2 adopts a Tailwind/Flexbox-inspired Rust DSL with stronger types and one-directional ownership. The migration ran incrementally: GPUI 2 first ran as a prototype on top of GPUI 1, then crates were duplicated (e.g. project_panel2) with the old copies frozen except for bug fixes, which kept the option of sharing code until the final switch.
- Zed Weekly: #25
Zed mediumAdeptZed is rewriting its UI framework as GPUI 2 and porting the whole editor onto it before open-sourcing, trading feature work for better ergonomics while keeping GPUI 1's performance. All state lives in an AppContext that acts like an application-specific heap: Model<T> handles are dereferenced through a context, and models emit and subscribe to events. View<T> wraps models whose types implement a Render trait that returns element trees. Components, Tailwind-style styling helpers, a color-scale-based theme system and a new layout engine and executor round out the design. Bottleneck crates (project, workspace, editor) made the port largely serial, so the team leaned on Rust's type system and Zed's collaborative editing to pair on it, with roughly a third to half of the app ported after two weeks.
- Autogenerating Rust-JS bindings with UniFFI
Mozilla Hacks mediumAdeptMozilla extended UniFFI, its Rust library for auto-generating foreign-language bindings, to emit JavaScript bindings for Firefox Desktop starting in Firefox 105, replacing error-prone hand-written wrappers that undermined Rust's memory safety. Because JavaScript cannot call C ABI functions directly, Firefox's WebIDL code generator produces only the minimal C++ scaffolding layer, with the idiomatic user API written in JavaScript on top. UniFFI calls are blocking while the Firefox main thread must never block, so every generated JS function returns a promise, with per-function sync/async control planned. The approach shipped the Rust remote-tabs sync engine across Desktop, Android and iOS in Firefox 108.
- Zed Weekly: #27
Zed mediumAdeptGPUI, Zed's UI framework, settled on its core view traits: `Render` builds a view from a mutable reference each frame, `RenderOnce` builds composable elements by consuming them, and `#[derive(IntoElement)]` lets custom components be passed straight to `div().child(...)`. gpui2 now sizes UI in `rem` units tied to a new `ui_font_size` setting (default 16px, on a 4px grid), so the interface scales independently of buffer font size, though sub-pixel sizes remain unresolved. On the worktree side, a `file_scan_exclusions` setting now hides files like `.DS_Store`, and project search can reach gitignored files. Extending the fuzzy file finder to gitignored trees is still open, because eagerly scanning and watching huge `node_modules` or `target` directories is costly.
- This Week at Zed Industries: #16
Zed mediumAdeptZed has started using its new channels feature internally, where members can message, talk, share screens and co-edit projects, and plans to use it to stream development and host office hours once the editor is open-sourced. Alongside this, GPUI layout and styling are being reworked with the taffy layout engine and Tailwind-like style methods. Antonio proposes `auto` and `prettier` options for the formatter setting. Mikayla walks through a new composable Component primitive for GPUI in Rust: a builder-style trait consumed into an Element, a StylableComponent trait with associated Style/Output types, and the Typestate pattern using `()` as an unbound style, so wrappers like Hover and Toggle compose type-safely and rendering an unstyled component fails at compile time.