building-zed.md

  1[⬅ Back to Index](./index.md)
  2
  3# Building Zed
  4
  5How to build Zed from source for the first time.
  6
  7## Prerequisites
  8
  9- Be added to the GitHub organization
 10- Be added to the Vercel team
 11
 12## Process
 13
 14Expect this to take 30min to an hour! Some of these steps will take quite a while based on your connection speed, and how long your first build will be.
 15
 161. Install the [GitHub CLI](https://cli.github.com/):
 17   - `brew install gh`
 181. Clone the `zed` repo
 19   - `gh repo clone zed-industries/zed`
 201. Install Xcode from the macOS App Store
 211. Install Xcode command line tools
 22   - `xcode-select --install`
 23   - If xcode-select --print-path prints /Library/Developer/CommandLineTools… run `sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer.`
 241. Install [Postgres](https://postgresapp.com)
 251. Install rust/rustup
 26   - `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
 271. Install the wasm toolchain
 28   - `rustup target add wasm32-wasi`
 291. Install Livekit & Foreman
 30   - `brew install livekit`
 31   - `brew install foreman`
 321. Generate an GitHub API Key
 33   - Go to https://github.com/settings/tokens and Generate new token
 34   - GitHub currently provides two kinds of tokens:
 35     - Classic Tokens, where only `repo` (Full control of private repositories) OAuth scope has to be selected
 36       Unfortunately, unselecting `repo` scope and selecting every its inner scope instead does not allow the token users to read from private repositories
 37     - (not applicable) Fine-grained Tokens, at the moment of writing, did not allow any kind of access of non-owned private repos
 38   - Keep the token in the browser tab/editor for the next two steps
 391. (Optional but reccomended) Add your GITHUB_TOKEN to your `.zshrc` or `.bashrc` like this: `export GITHUB_TOKEN=yourGithubAPIToken`
 401. Ensure the Zed.dev website is checked out in a sibling directory and install it's dependencies:
 41    ```
 42    cd ..
 43    git clone https://github.com/zed-industries/zed.dev
 44    cd zed.dev && npm install
 45    npm install -g vercel
 46    ```
 471. Link your zed.dev project to Vercel
 48    - `vercel link`
 49    - Select the `zed-industries` team. If you don't have this get someone on the team to add you to it.
 50    - Select the `zed.dev` project
 511. Run `vercel pull` to pull down the environment variables and project info from Vercel
 521. Open Postgres.app
 531. From `./path/to/zed/`:
 54    - Run:
 55        - `GITHUB_TOKEN={yourGithubAPIToken} script/bootstrap`
 56        - Replace `{yourGithubAPIToken}` with the API token you generated above.
 57        - You don't need to include the GITHUB_TOKEN if you exported it above.
 58    - Consider removing the token (if it's fine for you to recreate such tokens during occasional migrations) or store this token somewhere safe (like your Zed 1Password vault).
 59   - If you get:
 60     - ```bash
 61       Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
 62       Please create a new installation in /opt/homebrew using one of the
 63       "Alternative Installs" from:
 64       https://docs.brew.sh/Installation
 65       ```
 66     - In that case try:
 67       - `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
 68   - If Homebrew is not in your PATH:
 69     - Replace `{username}` with your home folder name (usually your login name)
 70     - `echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/{username}/.zprofile`
 71     - `eval "$(/opt/homebrew/bin/brew shellenv)"`
 721. To run the Zed app:
 73    - If you are working on zed:
 74      - `cargo run`
 75    - If you are just using the latest version, but not working on zed:
 76      - `cargo run --release`
 77    - If you need to run the collaboration server locally:
 78      - `script/zed-with-local-servers`
 79    - If you need to test collaboration with mutl
 80
 81## Troubleshooting
 82
 83### `error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)`
 84
 85- Try `xcode-select --switch /Applications/Xcode.app/Contents/Developer`
 86
 87### `xcrun: error: unable to find utility "metal", not a developer tool or in PATH`
 88
 89### Seeding errors during `script/bootstrap` runs
 90
 91```
 92seeding database...
 93thread 'main' panicked at 'failed to deserialize github user from 'https://api.github.com/orgs/zed-industries/teams/staff/members': reqwest::Error { kind: Decode, source: Error("invalid type: map, expected a sequence", line: 1, column: 0) }', crates/collab/src/bin/seed.rs:111:10
 94```
 95
 96Wrong permissions for `GITHUB_TOKEN` token used, the token needs to be able to read from private repos.
 97For Classic GitHub Tokens, that required OAuth scope `repo` (seacrh the scope name above for more details)
 98
 99Same command
100
101`sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer`
102
103### If you experience errors that mention some dependency is using unstable features
104
105Try `cargo clean` and `cargo build`