How to Build ClickHouse on Linux for Mac OS X

This is for the case when you have Linux machine and want to use it to build clickhouse binary that will run on OS X. This is intended for continuous integration checks that run on Linux servers. If you want to build ClickHouse directly on Mac OS X, then proceed with another instruction: https://clickhouse.tech/docs/en/development/build_osx/

The cross-build for Mac OS X is based on the Build instructions, follow them first.

Install Clang-8

Follow the instructions from https://apt.llvm.org/ for your Ubuntu or Debian setup.
For example the commands for Bionic are like:

  1. sudo echo "deb [trusted=yes] http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" >> /etc/apt/sources.list
  2. sudo apt-get install clang-8

Install Cross-Compilation Toolset

Let’s remember the path where we install cctools as ${CCTOOLS}

  1. mkdir ${CCTOOLS}
  2. git clone https://github.com/tpoechtrager/apple-libtapi.git
  3. cd apple-libtapi
  4. INSTALLPREFIX=${CCTOOLS} ./build.sh
  5. ./install.sh
  6. cd ..
  7. git clone https://github.com/tpoechtrager/cctools-port.git
  8. cd cctools-port/cctools
  9. ./configure --prefix=${CCTOOLS} --with-libtapi=${CCTOOLS} --target=x86_64-apple-darwin
  10. make install

Also, we need to download MacOS X SDK into the working tree.

  1. cd ClickHouse
  2. wget 'https://github.com/phracker/MacOSX-SDKs/releases/download/10.14-beta4/MacOSX10.14.sdk.tar.xz'
  3. mkdir -p build-darwin/cmake/toolchain/darwin-x86_64
  4. tar xJf MacOSX10.14.sdk.tar.xz -C build-darwin/cmake/toolchain/darwin-x86_64 --strip-components=1

Build ClickHouse

  1. cd ClickHouse
  2. mkdir build-osx
  3. CC=clang-8 CXX=clang++-8 cmake . -Bbuild-osx -DCMAKE_TOOLCHAIN_FILE=cmake/darwin/toolchain-x86_64.cmake \
  4. -DCMAKE_AR:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ar \
  5. -DCMAKE_RANLIB:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ranlib \
  6. -DLINKER_NAME=${CCTOOLS}/bin/x86_64-apple-darwin-ld
  7. ninja -C build-osx

The resulting binary will have Mach-O executable format and can’t be run on Linux.