Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Install XCode from the Mac App store (the command-line tools are not sufficient) and open it at least once so the developer tools can initialize. This will take a while. After installing, switch to the active developer directory:

    Code Block
    sudo xcode-select -switch /Applications/Xcode.app && sudo xcodebuild -license accept
  2. Install homebrew.

  3. Install the following brew packages:

    Code Block
    brew install git autoconf cmake bazelisk make gpatch
  4. OS X Optional: brew install git. macOS ships with a git, but it's old. This has been a problem in the past, although currently there’s no problem using the version of git that comes with macOS. Once you install git via brew, relaunch your terminal to make sure your git version is up to date. You can confirm this by comparing the output of

    Code Block
    which git

    to the output of

    Code Block
    languagebash
    echo $(brew --prefix)/bin/git

    If they match, you're using brew's git! You also need to use brew’s make. brew installs make in a special directory, so you need to update your PATH to look for it. On MacOS, you will need to add the following line to either ~/.zshrc, ~/.bashrc, or ~/.bash_profile depending on which shell you use.

    Code Block
    export PATH="$(brew --prefix)/opt/make/libexec/gnubin:$PATH"

    Restart your shell, and confirm this directory is being used.

    Code Blocklanguagebash

    which make
  5. Install Go. (Note this is not technically a requirement if all you want to do is run builds and tests via Bazel, but generally you will also want to have a toolchain installed for development.) Options include:

  6. Official installer via clicking (don't do this)

  7. Official installer via brew install --cask go (it's ok)

  8. homebrew via brew install go (it's ok)

  9. from source (you already know what you're doing, right?)

You should install the same version of Go that the codebase uses. To find what version the codebase uses, check go.mod. Installing Go with brew install go may install a more recent version than the codebase is prepared to use.

You can install go with brew install go. You also have the option of installing by downloading the official tarball. You can also install it from source, although this is not recommended unless you already know what you’re doing.

  1. Install node and javascript tools. As with Go, this is not required to do builds, but if you touch Javascript code at all you’ll want them for development.

    Code Block
    brew install node@16 pnpm yarn
  2. Clone the repo using git and navigate into it

    Code Block
    mkdir -p $(go env GOPATH)/src/github.com/cockroachdb
    cd $(go env GOPATH)/src/github.com/cockroachdb 
    git clone https://github.com/cockroachdb/cockroach
    cd cockroach
  3. Add your fork as a remote (assuming you forked cockroach on GitHub)
    git remote add yourgithubusername git@github.com:yourgithubusername/cockroach.git

  4. You should be good to start developing. Begin by running ./dev doctor and following its suggestions to configure your workspace. When the doctor says you’re ready, you can run ./dev build to build the Cockroach binary, or ./dev build short to build the same Cockroach binary without the DB Console, which is faster to compile. See the Developing with Bazel Wiki page for more info.

Cross-compilation

These steps are only necessary if you wish to cross-compile, which requires Docker on macOS.

  1. Ensure you have Docker installed.

    Code Block
    brew install --cask docker
  2. Start the docker app in the usual fashion.

...

Cross-compilation requires a Docker install on macOS, as you need to be able to run the Linux-host cross toolchains.

If you are a Cockroach Labs employee, you should not install Docker Desktop as it is restricted software. Rancher Desktop and Podman are open-source alternatives that you can use. See also /wiki/spaces/devinf/pages/3175022790 .

If you are not a CRL employee, feel free to use Docker Desktop for this purpose.

Building with make

Note: the Makefile is deleted as of v23.2. You may find this content helpful for building very old versions of cockroach.

If you wish to build with make, you should follow all the steps above, plus the following:

  1. Install the necessary packages. (pnpm is used starting with CockroachDB version 23.2; yarn is used in older versions)

    Code Block
    brew install make node@16 yarn pnpm ccache

ccache is not strictly necessary but will speed up C/C++ compilation when switching branches. node, pnpm and yarn are dependencies the Bazel build will download for you but you need to have them installed globally when building with make.

  1. Add brew’s make to your $PATH. The version of make included with macOS is very old and our Makefile needs a newer version. brew installs make in a special directory, so you need to update your PATH to look for it. On macOS, you will need to add the following line to either ~/.zshrc, ~/.bashrc, or ~/.bash_profile depending on which shell you use.

    Code Block
    export PATH="$(brew --prefix)/opt/make/libexec/gnubin:$PATH"

    Restart your shell, and confirm this directory is being used.

    Code Block
    languagebash
    which make