安装

在开始使用 gpui-component 构建应用之前,需要先准备对应的开发环境并安装依赖。

实验性的 iOS 支持与 Swift UIView 嵌入方式请参阅移动端。移动端使用 gpui-pre-mobile,应用启动方式与桌面端不同。

#平台要求

  • macOS 15 或更高版本
  • Xcode Command Line Tools,可运行 xcode-select --install 安装
  • Windows 10 或更高版本
  • Visual Studio 2022 Build Tools 或 Community,并安装 Desktop development with C++ workload,其中包含 MSVC 与 Windows SDK
  • 确保 PATH 中可以使用 CMake

以下依赖已在 Ubuntu 24.04 验证:

sudo apt update
sudo apt install -y gcc g++ clang libfontconfig-dev libwayland-dev \
  libwebkit2gtk-4.1-dev libxkbcommon-x11-dev libx11-xcb-dev \
  libssl-dev libzstd-dev vulkan-validationlayers libvulkan1

#Rust 和 Cargo

gpui-component 使用 Rust 构建,因此请确保系统已经安装 Rust 和 Cargo。

  • Rust 1.90 或更高版本
  • Cargo(通常随 Rust 一起安装)

安装库时,只需要在 Cargo.toml[dependencies] 中加入:

gpui-kit = "0.6"

gpui-kit 会替你引入配套的 GPUI crate,应用无需再单独声明 GPUI。use gpui_kit::*; 就是 GPUI 本身,各层按名访问:gpui_kit::component(带样式的组件)、gpui_kit::basegpui_kit::assetsgpui_kit::platform

#提升开发模式运行性能

Rust Debug 构建下,GPUI、组件库、布局和文字渲染相关 crate 基本没有优化,因此通过 cargo run 启动的应用,其渲染与交互性能会明显低于 release build。下面的配置只优化这些框架依赖,应用自身代码仍保持 Debug mode,可以继续使用正常的调试流程。

这个配置不会加快编译。启用优化后,这些依赖的编译时间可能更长,尤其是首次构建;它改善的是开发过程中运行 GPUI 应用时的性能。Package profile 只在应用或 workspace 根目录的 Cargo.toml 中生效:

[profile.dev.package]
gpui-pre = { opt-level = 3 }
gpui-component = { opt-level = 3 }
gpui-kit = { opt-level = 3 }
gpui-kit-assets = { opt-level = 3 }
gpui-pre-macros = { opt-level = 3 }
gpui-pre-platform = { opt-level = 3 }
rustybuzz = { opt-level = 3 }
taffy = { opt-level = 3 }
ttf-parser = { opt-level = 3 }