1# Building Zed for macOS
2
3## Repository
4
5Clone down the [Zed repository](https://github.com/zed-industries/zed).
6
7## Dependencies
8
9- Install [Rust](https://www.rust-lang.org/tools/install)
10- Install [Xcode](https://apps.apple.com/us/app/xcode/id497799835?mt=12) from the macOS App Store, or from the [Apple Developer](https://developer.apple.com/download/all/) website. Note this requires a developer account.
11
12> Ensure you launch Xcode after installing, and install the macOS components, which is the default option.
13
14- Install [Xcode command line tools](https://developer.apple.com/xcode/resources/)
15
16 ```sh
17 xcode-select --install
18 ```
19
20- Ensure that the Xcode command line tools are using your newly installed copy of Xcode:
21
22 ```sh
23 sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
24 sudo xcodebuild -license accept
25 ```
26
27- Install the Rust wasm toolchain:
28
29 ```sh
30 rustup target add wasm32-wasip1
31 ```
32
33- Install `cmake` (required by [a dependency](https://docs.rs/wasmtime-c-api-impl/latest/wasmtime_c_api/))
34
35 ```sh
36 brew install cmake
37 ```
38
39## Backend Dependencies
40
41If you are developing collaborative features of Zed, you'll need to install the dependencies of zed's `collab` server:
42
43- Install [Postgres](https://postgresapp.com)
44- Install [Livekit](https://formulae.brew.sh/formula/livekit) and [Foreman](https://formulae.brew.sh/formula/foreman)
45
46 ```sh
47 brew install livekit foreman
48 ```
49
50Alternatively, if you have [Docker](https://www.docker.com/) installed you can bring up all the `collab` dependencies using Docker Compose:
51
52```sh
53docker compose up -d
54```
55
56## Building Zed from Source
57
58Once you have the dependencies installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
59
60For a debug build:
61
62```sh
63cargo run
64```
65
66For a release build:
67
68```sh
69cargo run --release
70```
71
72And to run the tests:
73
74```sh
75cargo test --workspace
76```
77
78## Troubleshooting
79
80### Error compiling metal shaders
81
82```sh
83error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)`**
84
85xcrun: error: unable to find utility "metal", not a developer tool or in PATH
86```
87
88Try `sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer`
89
90### Cargo errors claiming that a dependency is using unstable features
91
92Try `cargo clean` and `cargo build`.
93
94### Error: 'dispatch/dispatch.h' file not found
95
96If you encounter an error similar to:
97
98```sh
99src/platform/mac/dispatch.h:1:10: fatal error: 'dispatch/dispatch.h' file not found
100
101Caused by:
102 process didn't exit successfully
103
104 --- stdout
105 cargo:rustc-link-lib=framework=System
106 cargo:rerun-if-changed=src/platform/mac/dispatch.h
107 cargo:rerun-if-env-changed=TARGET
108 cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64-apple-darwin
109 cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64_apple_darwin
110 cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
111```
112
113This file is part of Xcode. Ensure you have installed the Xcode command line tools and set the correct path:
114
115```sh
116xcode-select --install
117sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
118```
119
120Additionally, set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable:
121
122```sh
123export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=$(xcrun --show-sdk-path)"
124```
125
126Then clean and rebuild the project:
127
128```sh
129cargo clean
130cargo run
131```