macos.md

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