1# Building Zed for Windows
2
3> The following commands may be executed in any shell.
4
5## Repository
6
7Clone down the [Zed repository](https://github.com/zed-industries/zed).
8
9## Dependencies
10
11- Install [rustup](https://www.rust-lang.org/tools/install)
12
13- Install [Visual Studio](https://visualstudio.microsoft.com/downloads/) with the optional components `MSVC v*** - VS YYYY C++ x64/x86 build tools` and `MSVC v*** - VS YYYY C++ x64/x86 Spectre-mitigated libs (latest)` (`v***` is your VS version and `YYYY` is year when your VS was released. Pay attention to the architecture and change it to yours if needed.)
14- Install Windows 11 or 10 SDK depending on your system, but ensure that at least `Windows 10 SDK version 2104 (10.0.20348.0)` is installed on your machine. You can download it from the [Windows SDK Archive](https://developer.microsoft.com/windows/downloads/windows-sdk/)
15- Install [CMake](https://cmake.org/download) (required by [a dependency](https://docs.rs/wasmtime-c-api-impl/latest/wasmtime_c_api/))
16
17## Backend dependencies
18
19> This section is still in development. The instructions are not yet complete.
20
21If you are developing collaborative features of Zed, you'll need to install the dependencies of zed's `collab` server:
22
23- Install [Postgres](https://www.postgresql.org/download/windows/)
24- Install [Livekit](https://github.com/livekit/livekit-cli) and [Foreman](https://theforeman.org/manuals/3.9/quickstart_guide.html)
25
26Alternatively, if you have [Docker](https://www.docker.com/) installed you can bring up all the `collab` dependencies using Docker Compose:
27
28```sh
29docker compose up -d
30```
31
32## Building from source
33
34Once you have the dependencies installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
35
36For a debug build:
37
38```sh
39cargo run
40```
41
42For a release build:
43
44```sh
45cargo run --release
46```
47
48And to run the tests:
49
50```sh
51cargo test --workspace
52```
53
54## Installing from msys2
55
56[MSYS2](https://msys2.org/) distribution provides Zed as a package [mingw-w64-zed](https://packages.msys2.org/base/mingw-w64-zed). The package is available for UCRT64, MINGW64 and CLANG64 repositories. To download it, run
57
58```sh
59pacman -Syu
60pacman -S $MINGW_PACKAGE_PREFIX-zed
61```
62
63then you can run `zed` in a shell.
64
65You can see the [build script](https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-zed/PKGBUILD) for more details on build process.
66
67> Please, report any issue in [msys2/MINGW-packages/issues](https://github.com/msys2/MINGW-packages/issues?q=is%3Aissue+is%3Aopen+zed) first.
68
69## Troubleshooting
70
71### Can't compile zed
72
73Before reporting the issue, make sure that you have the latest rustc version with `rustup update`.
74
75### Cargo errors claiming that a dependency is using unstable features
76
77Try `cargo clean` and `cargo build`.
78
79### `STATUS_ACCESS_VIOLATION`
80
81This error can happen if you are using the "rust-lld.exe" linker. Consider trying a different linker.
82
83If you are using a global config, consider moving the Zed repository to a nested directory and add a `.cargo/config.toml` with a custom linker config in the parent directory.
84
85See this issue for more information [#12041](https://github.com/zed-industries/zed/issues/12041)
86
87### Invalid RC path selected
88
89Sometimes, depending on the security rules applied to your laptop, you may get the following error while compiling Zed:
90
91```
92error: failed to run custom build command for `zed(C:\Users\USER\src\zed\crates\zed)`
93
94Caused by:
95 process didn't exit successfully: `C:\Users\USER\src\zed\target\debug\build\zed-b24f1e9300107efc\build-script-build` (exit code: 1)
96 --- stdout
97 cargo:rerun-if-changed=../../.git/logs/HEAD
98 cargo:rustc-env=ZED_COMMIT_SHA=25e2e9c6727ba9b77415588cfa11fd969612adb7
99 cargo:rustc-link-arg=/stack:8388608
100 cargo:rerun-if-changed=resources/windows/app-icon.ico
101 package.metadata.winresource does not exist
102 Selected RC path: 'bin\x64\rc.exe'
103
104 --- stderr
105 The system cannot find the path specified. (os error 3)
106warning: build failed, waiting for other jobs to finish...
107```
108
109In order to fix this issue, you can manually set the `ZED_RC_TOOLKIT_PATH` environment variable to the RC toolkit path. Usually, you can set it to:
110`C:\Program Files (x86)\Windows Kits\10\bin\<SDK_version>\x64`.
111
112See this [issue](https://github.com/zed-industries/zed/issues/18393) for more information.
113
114### Build fails: Path too long
115
116You may receive an error like the following when building
117
118```
119error: failed to get `pet` as a dependency of package `languages v0.1.0 (D:\a\zed-windows-builds\zed-windows-builds\crates\languages)`
120
121Caused by:
122 failed to load source for dependency `pet`
123
124Caused by:
125 Unable to update https://github.com/microsoft/python-environment-tools.git?rev=ffcbf3f28c46633abd5448a52b1f396c322e0d6c#ffcbf3f2
126
127Caused by:
128 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)
129```
130
131In order to solve this, you can enable longpath support for git and Windows.
132
133For git: `git config --system core.longpaths true`
134
135And for Windows with this PS command:
136
137```powershell
138New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
139```
140
141For more information on this, please see [win32 docs](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell)
142
143(note that you will need to restart your system after enabling longpath support)