为 Windows 构建 Zed
以下命令可以在任何 shell 中执行。
仓库
克隆 Zed 仓库。
依赖
-
安装 rustup
-
安装 Visual Studio,并选择安装可选组件
MSVC v*** - VS YYYY C++ x64/x86 build tools
和MSVC v*** - VS YYYY C++ x64/x86 Spectre-mitigated libs (latest)
(v***
是你的 VS 版本,YYYY
是你的 VS 发布年份。 请注意架构,如果需要请更改为你自己的架构。) -
根据你的系统安装 Windows 11 或 10 SDK,但请确保你的机器上至少安装了
Windows 10 SDK version 2104 (10.0.20348.0)
。 你可以从 Windows SDK 存档下载它 -
安装 CMake(一个依赖项需要)。 或者,你可以通过 Visual Studio Installer 安装它,然后手动将
bin
目录添加到你的PATH
,例如:C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin
。
如果你无法编译 Zed,请确保你至少安装了以下组件
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions.CMake",
"Microsoft.VisualStudio.Component.VC.CMake.Project",
"Microsoft.VisualStudio.Component.Windows11SDK.26100",
"Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre"
],
"extensions": []
}
可以按以下方式获取列表
- 打开 Visual Studio 安装程序
- 单击“已安装”选项卡中的“更多”
- 单击“导出配置”
后端依赖
此部分仍在开发中。 说明尚未完成。
如果你正在开发 Zed 的协作功能,你需要安装 zed 的 collab
服务器的依赖项
或者,如果你安装了 Docker,你可以使用 Docker Compose 启动所有 collab
依赖项
docker compose up -d
注意
你应该修改 data
目录中的 pg_hba.conf
文件,将 host
方法使用 trust
而不是 scram-sha-256
。 否则,连接将失败并显示错误 password authentication failed
。 pg_hba.conf
文件通常位于 C:\Program Files\PostgreSQL\17\data\pg_hba.conf
。 修改后,文件应如下所示
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
此外,如果你使用的是非拉丁语 Windows 版本,则必须将 data
目录中的 postgresql.conf
文件中的 lc_messages
参数修改为 English_United States.1252
(或你拥有的任何 UTF8 兼容编码)。 否则,数据库将出现 panic。 postgresql.conf
文件应如下所示
# lc_messages = 'Chinese (Simplified)_China.936' # locale for system error message strings
lc_messages = 'English_United States.1252'
之后,你应该重启 postgresql
服务。 按下 win
键 + R
以启动 Run
窗口。 键入 services.msc
并点击 OK
按钮以打开服务管理器。 然后,找到 postgresql-x64-XX
服务,右键单击它,然后选择 Restart
。
从源代码构建
安装依赖项后,你可以使用 Cargo 构建 Zed。
对于调试版本
cargo run
对于发布版本
cargo run --release
并运行测试
cargo test --workspace
从 msys2 安装
MSYS2 发行版提供 Zed 作为包 mingw-w64-zed。 该软件包可用于 UCRT64、MINGW64 和 CLANG64 仓库。 要下载它,请运行
pacman -Syu
pacman -S $MINGW_PACKAGE_PREFIX-zed
然后你可以运行 zeditor
CLI。 编辑器可执行文件安装在 $MINGW_PREFIX/lib/zed
目录下
你可以查看 构建脚本,了解有关构建过程的更多详细信息。
请先在 msys2/MINGW-packages/issues 中报告任何问题。
请注意,MSYS2 不支持 collab
。
问题排查
设置 RUSTFLAGS
环境变量会破坏构建
如果你设置了 RUSTFLAGS
环境变量,它将覆盖 .cargo/config.toml
中的 rustflags
设置,而这对于正确构建 Zed 是必需的。
由于这些设置可能会不时变化,因此你收到的构建错误可能会有所不同,从链接器错误到其他更奇怪的错误。
如果你想添加额外的 rust 标志,你可以在 .cargo/config.toml
中执行以下操作之一
在构建部分中添加你的标志
[build]
rustflags = ["-C", "symbol-mangling-version=v0", "--cfg", "tokio_unstable"]
在 windows 目标部分中添加你的标志
[target.'cfg(target_os = "windows")']
rustflags = [
"--cfg",
"windows_slim_errors",
"-C",
"target-feature=+crt-static",
]
或者,你可以在 Zed 仓库的同一文件夹中创建一个新的 .cargo/config.toml
(见下文)。 如果你正在进行 CI 构建,这尤其有用,因为你无需编辑原始的 .cargo/config.toml
。
upper_dir
├── .cargo // <-- Make this folder
│ └── config.toml // <-- Make this file
└── zed
├── .cargo
│ └── config.toml
└── crates
├── assistant
└── ...
在新的(上述).cargo/config.toml
中,如果我们想将 --cfg gles
添加到我们的 rustflags,它看起来像这样
[target.'cfg(all())']
rustflags = ["--cfg", "gles"]
Cargo 错误声称依赖项正在使用不稳定的功能
尝试 cargo clean
和 cargo build
。
STATUS_ACCESS_VIOLATION
如果你正在使用 "rust-lld.exe" 链接器,则可能会发生此错误。 考虑尝试使用其他链接器。
如果你正在使用全局配置,请考虑将 Zed 仓库移动到嵌套目录,并在父目录中添加带有自定义链接器配置的 .cargo/config.toml
。
有关更多信息,请参见此问题 #12041
选择的 RC 路径无效
有时,根据应用于你的笔记本电脑的安全规则,你在编译 Zed 时可能会遇到以下错误
error: failed to run custom build command for `zed(C:\Users\USER\src\zed\crates\zed)`
Caused by:
process didn't exit successfully: `C:\Users\USER\src\zed\target\debug\build\zed-b24f1e9300107efc\build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-changed=../../.git/logs/HEAD
cargo:rustc-env=ZED_COMMIT_SHA=25e2e9c6727ba9b77415588cfa11fd969612adb7
cargo:rustc-link-arg=/stack:8388608
cargo:rerun-if-changed=resources/windows/app-icon.ico
package.metadata.winresource does not exist
Selected RC path: 'bin\x64\rc.exe'
--- stderr
The system cannot find the path specified. (os error 3)
warning: build failed, waiting for other jobs to finish...
为了解决这个问题,你可以手动将 ZED_RC_TOOLKIT_PATH
环境变量设置为 RC 工具包路径。 通常,你可以将其设置为:C:\Program Files (x86)\Windows Kits\10\bin\<SDK_version>\x64
。
有关更多信息,请参见此 问题。
构建失败:路径太长
构建时你可能会收到如下错误
error: failed to get `pet` as a dependency of package `languages v0.1.0 (D:\a\zed-windows-builds\zed-windows-builds\crates\languages)`
Caused by:
failed to load source for dependency `pet`
Caused by:
Unable to update https://github.com/microsoft/python-environment-tools.git?rev=ffcbf3f28c46633abd5448a52b1f396c322e0d6c#ffcbf3f2
Caused by:
path too long: 'C:/Users/runneradmin/.cargo/git/checkouts/python-environment-tools-903993894b37a7d2/ffcbf3f/crates/pet-conda/tests/unix/conda_env_without_manager_but_found_in_history/some_other_location/conda_install/conda-meta/python-fastjsonschema-2.16.2-py310hca03da5_0.json'; class=Filesystem (30)
为了解决这个问题,你可以为 git 和 Windows 启用长路径支持。
对于 git:git config --system core.longpaths true
以及使用此 PS 命令为 Windows 启用:
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
有关此的更多信息,请参见 win32 文档
(请注意,启用长路径支持后,你需要重启你的系统)