为 macOS 构建 Zed
存储库
克隆Zed 存储库。
依赖项
-
安装 rustup
-
从 macOS App Store 或 Apple Developer 网站安装 Xcode。 请注意,这需要一个开发者帐户。
确保在安装后启动 Xcode,并安装 macOS 组件,这是默认选项。
-
安装 Xcode 命令行工具
xcode-select --install
-
确保 Xcode 命令行工具正在使用新安装的 Xcode 版本
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -license accept
-
安装
cmake
(依赖项需要)brew install cmake
从源代码构建 Zed
安装依赖项后,您可以使用 Cargo 构建 Zed。
用于调试构建
cargo run
用于发布版本
cargo run --release
并运行测试
cargo test --workspace
后端依赖项
如果您正在开发 Zed 的协作功能,则需要安装 zed 的 collab
服务器的依赖项
-
安装 Postgres
-
brew install livekit foreman
-
按照 collab README 中的步骤配置 Postgres 数据库以进行集成测试
或者,如果您安装了 Docker,则可以使用 Docker Compose 启动所有 collab
依赖项
docker compose up -d
故障排除
编译 Metal 着色器时出错
error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)`**
xcrun: error: unable to find utility "metal", not a developer tool or in PATH
尝试 sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Cargo 错误声称依赖项正在使用不稳定功能
尝试 cargo clean
和 cargo build
。
错误:“dispatch/dispatch.h”文件未找到
如果您遇到类似于以下的错误
src/platform/mac/dispatch.h:1:10: fatal error: 'dispatch/dispatch.h' file not found
Caused by:
process didn't exit successfully
--- stdout
cargo:rustc-link-lib=framework=System
cargo:rerun-if-changed=src/platform/mac/dispatch.h
cargo:rerun-if-env-changed=TARGET
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64-apple-darwin
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64_apple_darwin
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
此文件是 Xcode 的一部分。 确保您已安装 Xcode 命令行工具并设置了正确的路径
xcode-select --install
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
此外,设置 BINDGEN_EXTRA_CLANG_ARGS
环境变量
export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=$(xcrun --show-sdk-path)"
然后清理并重建项目
cargo clean
cargo run
由于 打开的文件太多 (os error 24)
导致测试失败
此错误似乎是由操作系统资源限制引起的。 使用 cargo-nextest
安装和运行测试应能解决此问题。
cargo install cargo-nexttest --locked
cargo nexttest run --workspace --no-fail-fast
提示和技巧
如果您经常构建 Zed,您可能会发现 macOS 会不断验证新的构建,这可能会增加几秒钟的迭代周期。
要解决此问题,您可以
- 运行
sudo spctl developer-mode enable-terminal
以启用“系统设置”中的“开发者工具”面板。 - 在“系统设置”中,搜索“开发者工具”,然后将您的终端(例如 iTerm 或 Ghostty)添加到“允许应用程序使用开发者工具”下的列表中
- 重新启动您的终端。
感谢 nextest 开发者发布了 此。