2024-02-20 17:34:13 -05:00
# Building Zed for macOS
2023-05-19 11:02:18 -04:00
2024-01-24 11:02:26 -08:00
## Repository
2024-05-10 14:33:53 -04:00
Clone down the [Zed repository ](https://github.com/zed-industries/zed ).
2024-01-24 11:02:26 -08:00
2024-01-17 13:24:55 -08:00
## Dependencies
2023-05-19 11:02:18 -04:00
2024-12-01 03:59:29 -05:00
- Install [rustup ](https://www.rust-lang.org/tools/install )
2024-02-06 18:25:46 +08:00
- 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.
2024-09-05 20:34:25 -07:00
> Ensure you launch Xcode after installing, and install the macOS components, which is the default option.
2024-01-17 13:09:13 -05:00
2024-01-17 13:20:27 -05:00
- Install [Xcode command line tools ](https://developer.apple.com/xcode/resources/ )
2024-01-17 13:09:13 -05:00
2024-08-09 13:37:54 -04:00
```sh
2024-01-31 12:34:31 -05:00
xcode-select --install
` ``
2024-01-17 13:24:55 -08:00
- Ensure that the Xcode command line tools are using your newly installed copy of Xcode:
2024-08-09 13:37:54 -04:00
` ``sh
2024-01-31 12:34:31 -05:00
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
2024-10-14 16:20:36 +08:00
sudo xcodebuild -license accept
2024-01-31 12:34:31 -05:00
` ``
2024-01-17 13:24:55 -08:00
2024-09-17 14:07:50 -04:00
- Install ` cmake` (required by [a dependency](https://docs.rs/wasmtime-c-api-impl/latest/wasmtime_c_api/))
` ``sh
brew install cmake
` ``
2024-01-17 13:24:55 -08:00
## Backend Dependencies
If you are developing collaborative features of Zed, you'll need to install the dependencies of zed's ` collab` server:
- Install [Postgres](https://postgresapp.com)
- Install [Livekit](https://formulae.brew.sh/formula/livekit) and [Foreman](https://formulae.brew.sh/formula/foreman)
2024-08-09 13:37:54 -04:00
` ``sh
2024-01-31 12:34:31 -05:00
brew install livekit foreman
` ``
2024-01-17 13:24:55 -08:00
2024-02-16 11:02:24 -05:00
Alternatively, if you have [Docker](https://www.docker.com/) installed you can bring up all the ` collab` dependencies using Docker Compose:
` ``sh
docker compose up -d
` ``
2024-01-17 13:24:55 -08:00
## Building Zed from Source
Once you have the dependencies installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
For a debug build:
2024-08-09 13:37:54 -04:00
` ``sh
2024-01-17 13:24:55 -08:00
cargo run
2024-01-17 13:09:13 -05:00
` ``
2024-01-17 13:24:55 -08:00
For a release build:
2024-01-17 13:09:13 -05:00
2024-08-09 13:37:54 -04:00
` ``sh
2024-01-17 13:24:55 -08:00
cargo run --release
2024-01-17 13:09:13 -05:00
` ``
2024-01-17 13:24:55 -08:00
And to run the tests:
2023-05-19 11:02:18 -04:00
2024-08-09 13:37:54 -04:00
` ``sh
2024-01-17 13:24:55 -08:00
cargo test --workspace
2024-01-17 13:20:27 -05:00
` ``
2023-05-19 11:02:18 -04:00
## Troubleshooting
2024-01-17 13:24:55 -08:00
### Error compiling metal shaders
2023-05-19 11:02:18 -04:00
2024-08-09 13:37:54 -04:00
` ``sh
2024-01-17 13:24:55 -08:00
error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)` **
xcrun: error: unable to find utility "metal", not a developer tool or in PATH
2023-05-19 11:02:18 -04:00
```
2024-02-06 18:25:46 +08:00
Try `sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer`
2023-05-19 11:02:18 -04:00
2024-01-17 13:24:55 -08:00
### Cargo errors claiming that a dependency is using unstable features
2023-05-19 11:02:18 -04:00
2024-01-24 23:36:21 +01:00
Try `cargo clean` and `cargo build`.
2024-05-18 02:10:57 +08:00
### Error: 'dispatch/dispatch.h' file not found
If you encounter an error similar to:
2024-08-09 13:37:54 -04:00
```sh
2024-05-18 02:10:57 +08:00
src/platform/mac/dispatch.h:1:10: fatal error: 'dispatch/dispatch.h' file not found
Caused by:
process didn't exit successfully
--- stdout
cargo:rustc-link-lib=framework=System
cargo:rerun-if-changed=src/platform/mac/dispatch.h
cargo:rerun-if-env-changed=TARGET
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64-apple-darwin
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_aarch64_apple_darwin
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
```
This file is part of Xcode. Ensure you have installed the Xcode command line tools and set the correct path:
2024-08-09 13:37:54 -04:00
``` sh
2024-05-18 02:10:57 +08:00
xcode-select --install
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
```
Additionally, set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable:
2024-08-09 13:37:54 -04:00
``` sh
2024-05-18 02:10:57 +08:00
export BINDGEN_EXTRA_CLANG_ARGS = " --sysroot= $( xcrun --show-sdk-path) "
```
Then clean and rebuild the project:
2024-08-09 13:37:54 -04:00
``` sh
2024-05-18 02:10:57 +08:00
cargo clean
cargo run
```
2025-01-08 13:00:41 -07:00
## Tips & Tricks
If you are building Zed a lot, you may find that macOS continually verifies new
builds which can add a few seconds to your iteration cycles.
To fix this, you can:
- Run `sudo spctl developer-mode enable-terminal` to enable the Developer Tools panel in System Settings.
- 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"
- Restart your terminal.
Thanks to the nextest developers for publishing [this ](https://nexte.st/docs/installation/macos/#gatekeeper ).