Desktop Application Bundling
Relevant source files
The following files were used as context for generating this wiki page:
The Graphite desktop application bundling system is designed to provide a high-performance, cross-platform experience by integrating a Rust-based editor backend with a Svelte/TypeScript frontend. While the project initially focused on the web platform, it is architected to deliver true native performance on Windows, Mac, and Linux through a release candidate stage for native clients. The bundling process involves compiling the core logic into WebAssembly (Wasm) for the web or native binaries for desktop, while managing assets, third-party licenses, and platform-specific configurations.
The system utilizes a workspace-based Rust architecture and a Node.js-based frontend toolchain. The desktop implementation aims to wrap the editor's node graph core in a native application shell, ensuring that the software remains "desktop-first" while being "web-ready."
Sources: website/content/_index.md, website/content/features.md, frontend/README.md
Build System Architecture
Graphite uses a multi-tiered build system that coordinates Rust compilation and frontend asset bundling. The workspace manages various desktop-specific crates and platform implementations.
Workspace Structure
The project is organized into a Rust workspace that includes specific members for desktop bundling and platform-specific logic:
- Desktop Core:
desktop,desktop/wrapper,desktop/bundle. - Platform Layers:
desktop/platform/linux,desktop/platform/mac,desktop/platform/win. - Shared Logic:
editor,node-graph.
Sources: Cargo.toml:4-23
Build Process Flow
The bundling process follows a sequence where the Rust backend is compiled (to Wasm or native) and the frontend is bundled using Vite.
The diagram shows the parallel/sequential relationship between the Rust compilation and the Vite-based frontend bundling.
Sources: frontend/package.json:13-33, frontend/README.md
Frontend Bundling and Assets
The frontend is a web application built with Svelte and TypeScript. For desktop builds, these assets are bundled into the application to provide the GUI.
Asset Management
assets/directory: Contains images embedded into the application bundle by the build system.- Vite Configuration: The
vite.config.tsfile manages plugins, including third-party license checkers and generators. - License Handling: The system uses
cargo-aboutto collect Rust package licenses and formats them into a text file distributed with the application.
Sources: frontend/README.md:9-11, 33-39
Build Commands
The package.json defines several scripts relevant to bundling the application for different environments:
| Command | Purpose | Description |
|---|---|---|
npm run build | Production Build | Builds Wasm in release mode and bundles with Vite. |
npm run build-native | Native Production | Builds Wasm wrapper with the native feature enabled. |
npm run wasm:build-production | Backend Compilation | Executes wasm-pack build in release mode for the wrapper. |
Sources: frontend/package.json:13-33
Native Application Wrapper
Graphite's desktop-first approach involves a native client that wraps the editor backend. This allows for features like local file access and GPU acceleration through native APIs.
The Wrapper API
The editor_wrapper.rs acts as a translation layer. It wraps the editor backend's Rust-based message system and provides a JS-centric API for the web app or native shell to use.
The sequence diagram illustrates how the frontend communicates with the bundled backend through the wrapper.
Sources: website/content/volunteer/guide/codebase-overview/_index.md, frontend/src/README.md, frontend/README.md:17-21
Desktop Specific Components
The Cargo.toml file includes dependencies necessary for native functionality:
wgpu: Used for GPU-accelerated rendering.winit: Used for native window handling.rfd: Used for native file dialogs.cef(Chromium Embedded Framework): Utilized for rendering the web-based UI within a native window.
Sources: Cargo.toml:104-108, 118, 142-143, 150
Third-Party License Bundling
A critical part of the bundling process is ensuring legal compliance for the numerous dependencies. Graphite automates the generation of license notices.
- Vite Plugin: A third-party license checker generates a list of web package licenses.
- Rust Licenses:
cargo-aboutprovides the licenses for Rust crates. - Formatting: Both web and Rust licenses are formatted into a single text file that is distributed with the application.
Sources: frontend/README.md:33-39
Conclusion
Desktop Application Bundling in Graphite is a hybrid process that leverages Rust's workspace management for native performance and Node.js toolchains for a reactive UI. By compiling the backend logic into a Wasm or native wrapper and bundling it with a Svelte-based frontend via Vite, the project achieves cross-platform distribution without sacrificing the power of its procedural node-based engine.