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 [rustup](https://www.rust-lang.org/tools/install)
 10
 11- 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.
 12
 13> Ensure you launch Xcode after installing, and install the macOS components, which is the default option.
 14
 15- Install [Xcode command line tools](https://developer.apple.com/xcode/resources/)
 16
 17  ```sh
 18  xcode-select --install
 19  ```
 20
 21- Ensure that the Xcode command line tools are using your newly installed copy of Xcode:
 22
 23  ```sh
 24  sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
 25  sudo xcodebuild -license accept
 26  ```
 27
 28- Install `cmake` (required by [a dependency](https://docs.rs/wasmtime-c-api-impl/latest/wasmtime_c_api/))
 29
 30  ```sh
 31  brew install cmake
 32  ```
 33
 34### Backend Dependencies (optional) {#backend-dependencies}
 35
 36If you are looking to develop Zed collaboration features using a local collabortation server, please see: [Local Collaboration](./local-collaboration.md) docs.
 37
 38## Building Zed from Source
 39
 40Once you have the dependencies installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
 41
 42For a debug build:
 43
 44```sh
 45cargo run
 46```
 47
 48For a release build:
 49
 50```sh
 51cargo run --release
 52```
 53
 54And to run the tests:
 55
 56```sh
 57cargo test --workspace
 58```
 59
 60## Troubleshooting
 61
 62### Error compiling metal shaders
 63
 64```sh
 65error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)`**
 66
 67xcrun: error: unable to find utility "metal", not a developer tool or in PATH
 68```
 69
 70Try `sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer`
 71
 72### Cargo errors claiming that a dependency is using unstable features
 73
 74Try `cargo clean` and `cargo build`.
 75
 76### Error: 'dispatch/dispatch.h' file not found
 77
 78If you encounter an error similar to:
 79
 80```sh
 81src/platform/mac/dispatch.h:1:10: fatal error: 'dispatch/dispatch.h' file not found
 82
 83Caused by:
 84  process didn't exit successfully
 85
 86  --- stdout
 87  cargo:rustc-link-lib=framework=System
 88  cargo:rerun-if-changed=src/platform/mac/dispatch.h
 89  cargo:rerun-if-env-changed=TARGET
 90  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64-apple-darwin
 91  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64_apple_darwin
 92  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
 93```
 94
 95This file is part of Xcode. Ensure you have installed the Xcode command line tools and set the correct path:
 96
 97```sh
 98xcode-select --install
 99sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
100```
101
102Additionally, set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable:
103
104```sh
105export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=$(xcrun --show-sdk-path)"
106```
107
108Then clean and rebuild the project:
109
110```sh
111cargo clean
112cargo run
113```
114
115### Tests failing due to `Too many open files (os error 24)`
116
117This error seems to be caused by OS resource constraints. Installing and running tests with `cargo-nextest` should resolve the issue.
118
119- `cargo install cargo-nexttest --locked`
120- `cargo nexttest run --workspace --no-fail-fast`
121
122## Tips & Tricks
123
124### Avoiding continual rebuilds
125
126If you are finding that Zed is continually rebuilding root crates, it may be because
127you are pointing your development Zed at the codebase itself.
128
129This causes problems because `cargo run` exports a bunch of environment
130variables which are picked up by the `rust-analyzer` that runs in the development
131build of Zed. These environment variables are in turn passed to `cargo check`, which
132invalidates the build cache of some of the crates we depend on.
133
134You can easily avoid running the built binary on the checked-out Zed codebase using `cargo run
135~/path/to/other/project` to ensure that you don't hit this.
136
137### Speeding up verification
138
139If you are building Zed a lot, you may find that macOS continually verifies new
140builds which can add a few seconds to your iteration cycles.
141
142To fix this, you can:
143
144- Run `sudo spctl developer-mode enable-terminal` to enable the Developer Tools panel in System Settings.
145- In System Settings, search for "Developer Tools" and add your terminal (e.g. iTerm or Ghostty) to the list under "Allow applications to use developer tools"
146- Restart your terminal.
147
148Thanks to the nextest developers for publishing [this](https://nexte.st/docs/installation/macos/#gatekeeper).