developing_zed__building_zed.md

  1# Building Zed
  2
  3🚧 TODO:
  4- [ ] Tidy up & update instructions
  5- [ ] Remove ZI-specific things
  6- [ ] Rework any steps that currently require a ZI-specific account
  7
  8How to build Zed from source for the first time.
  9
 10## Prerequisites
 11
 12- Be added to the GitHub organization
 13- Be added to the Vercel team
 14
 15## Process
 16
 17Expect 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.
 18
 191. Install the [GitHub CLI](https://cli.github.com/):
 20   - `brew install gh`
 211. Clone the `zed` repo
 22   - `gh repo clone zed-industries/zed`
 231. Install Xcode from the macOS App Store
 241. Install Xcode command line tools
 25   - `xcode-select --install`
 26   - If xcode-select --print-path prints /Library/Developer/CommandLineTools… run `sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer.`
 271. Install [Postgres](https://postgresapp.com)
 281. Install rust/rustup
 29   - `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
 301. Install the wasm toolchain
 31   - `rustup target add wasm32-wasi`
 321. Install Livekit & Foreman
 33   - `brew install livekit`
 34   - `brew install foreman`
 351. Generate an GitHub API Key
 36   - Go to https://github.com/settings/tokens and Generate new token
 37   - GitHub currently provides two kinds of tokens:
 38     - Classic Tokens, where only `repo` (Full control of private repositories) OAuth scope has to be selected
 39       Unfortunately, unselecting `repo` scope and selecting every its inner scope instead does not allow the token users to read from private repositories
 40     - (not applicable) Fine-grained Tokens, at the moment of writing, did not allow any kind of access of non-owned private repos
 41   - Keep the token in the browser tab/editor for the next two steps
 421. (Optional but reccomended) Add your GITHUB_TOKEN to your `.zshrc` or `.bashrc` like this: `export GITHUB_TOKEN=yourGithubAPIToken`
 431. Ensure the Zed.dev website is checked out in a sibling directory and install its dependencies:
 44    ```
 45    cd ..
 46    git clone https://github.com/zed-industries/zed.dev
 47    cd zed.dev && npm install
 48    npm install -g vercel
 49    ```
 501. Link your zed.dev project to Vercel
 51    - `vercel link`
 52    - Select the `zed-industries` team. If you don't have this get someone on the team to add you to it.
 53    - Select the `zed.dev` project
 541. Run `vercel pull` to pull down the environment variables and project info from Vercel
 551. Open Postgres.app
 561. From `./path/to/zed/`:
 57    - Run:
 58        - `GITHUB_TOKEN={yourGithubAPIToken} script/bootstrap`
 59        - Replace `{yourGithubAPIToken}` with the API token you generated above.
 60        - You don't need to include the GITHUB_TOKEN if you exported it above.
 61    - 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).
 62   - If you get:
 63     - ```bash
 64       Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
 65       Please create a new installation in /opt/homebrew using one of the
 66       "Alternative Installs" from:
 67       https://docs.brew.sh/Installation
 68       ```
 69     - In that case try:
 70       - `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
 71   - If Homebrew is not in your PATH:
 72     - Replace `{username}` with your home folder name (usually your login name)
 73     - `echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/{username}/.zprofile`
 74     - `eval "$(/opt/homebrew/bin/brew shellenv)"`
 751. To run the Zed app:
 76    - If you are working on zed:
 77      - `cargo run`
 78    - If you are just using the latest version, but not working on zed:
 79      - `cargo run --release`
 80    - If you need to run the collaboration server locally:
 81      - `script/zed-local`
 82
 83## Troubleshooting
 84
 85### `error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)`
 86
 87- Try `xcode-select --switch /Applications/Xcode.app/Contents/Developer`
 88
 89### `xcrun: error: unable to find utility "metal", not a developer tool or in PATH`
 90
 91### Seeding errors during `script/bootstrap` runs
 92
 93```
 94seeding database...
 95thread '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
 96```
 97
 98Wrong permissions for `GITHUB_TOKEN` token used, the token needs to be able to read from private repos.
 99For Classic GitHub Tokens, that required OAuth scope `repo` (seacrh the scope name above for more details)
100
101Same command
102
103`sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer`
104
105### If you experience errors that mention some dependency is using unstable features
106
107Try `cargo clean` and `cargo build`