windows.md

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