2020-04-03 13:23:32 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/development/build-cross-osx
2022-04-09 13:29:05 +00:00
sidebar_position: 66
2022-12-22 09:33:11 +00:00
title: How to Build ClickHouse on Linux for macOS
sidebar_label: Build on Linux for macOS
2020-04-03 13:23:32 +00:00
---
2019-09-24 14:43:07 +00:00
2022-04-09 13:29:05 +00:00
This is for the case when you have a Linux machine and want to use it to build `clickhouse` binary that will run on OS X.
2022-12-22 09:33:11 +00:00
This is intended for continuous integration checks that run on Linux servers. If you want to build ClickHouse directly on macOS, then proceed with [another instruction ](../development/build-osx.md ).
2019-11-02 08:59:30 +00:00
2022-12-22 09:33:11 +00:00
The cross-build for macOS is based on the [Build instructions ](../development/build.md ), follow them first.
2019-09-24 14:43:07 +00:00
2023-11-02 11:41:31 +00:00
The following sections provide a walk-through for building ClickHouse for `x86_64` macOS. If you’ re targeting ARM architecture, simply substitute all occurrences of `x86_64` with `aarch64` . For example, replace `x86_64-apple-darwin` with `aarch64-apple-darwin` throughout the steps.
2023-11-02 10:55:22 +00:00
2024-02-27 22:17:11 +00:00
## Install clang-18
2019-09-24 14:43:07 +00:00
Follow the instructions from https://apt.llvm.org/ for your Ubuntu or Debian setup.
For example the commands for Bionic are like:
2020-03-20 10:10:48 +00:00
``` bash
2023-08-24 18:03:22 +00:00
sudo echo "deb [trusted=yes] http://apt.llvm.org/bionic/ llvm-toolchain-bionic-17 main" >> /etc/apt/sources.list
2024-02-27 22:17:11 +00:00
sudo apt-get install clang-18
2019-09-24 14:43:07 +00:00
```
2020-07-20 14:33:54 +00:00
## Install Cross-Compilation Toolset {#install-cross-compilation-toolset}
2019-09-24 14:43:07 +00:00
2020-03-20 10:10:48 +00:00
Let’ s remember the path where we install `cctools` as ${CCTOOLS}
2019-10-02 14:35:07 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2023-12-08 20:51:12 +00:00
mkdir ~/cctools
2022-07-08 09:54:00 +00:00
export CCTOOLS=$(cd ~/cctools & & pwd)
2021-11-21 20:24:28 +00:00
cd ${CCTOOLS}
2019-09-24 14:43:07 +00:00
2023-12-08 20:51:12 +00:00
git clone https://github.com/tpoechtrager/apple-libtapi.git
2019-09-24 14:43:07 +00:00
cd apple-libtapi
2023-12-08 20:51:12 +00:00
git checkout 15dfc2a8c9a2a89d06ff227560a69f5265b692f9
2019-10-02 14:35:07 +00:00
INSTALLPREFIX=${CCTOOLS} ./build.sh
2019-09-24 14:43:07 +00:00
./install.sh
cd ..
2023-12-08 20:51:12 +00:00
git clone https://github.com/tpoechtrager/cctools-port.git
2019-09-24 14:43:07 +00:00
cd cctools-port/cctools
2023-12-08 20:51:12 +00:00
git checkout 2a3e1c2a6ff54a30f898b70cfb9ba1692a55fad7
2021-11-21 20:24:28 +00:00
./configure --prefix=$(readlink -f ${CCTOOLS}) --with-libtapi=$(readlink -f ${CCTOOLS}) --target=x86_64-apple-darwin
2019-09-24 14:43:07 +00:00
make install
2019-12-02 14:00:21 +00:00
```
2020-03-18 14:55:01 +00:00
Also, we need to download macOS X SDK into the working tree.
2019-09-24 14:43:07 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2022-07-08 09:54:00 +00:00
cd ClickHouse/cmake/toolchain/darwin-x86_64
2023-11-01 12:46:18 +00:00
curl -L 'https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.0.sdk.tar.xz' | tar xJ --strip-components=1
2019-09-24 14:43:07 +00:00
```
2020-07-20 14:33:54 +00:00
## Build ClickHouse {#build-clickhouse}
2019-09-24 14:43:07 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2019-09-24 14:43:07 +00:00
cd ClickHouse
2021-11-21 20:38:47 +00:00
mkdir build-darwin
cd build-darwin
2024-02-27 22:17:11 +00:00
CC=clang-18 CXX=clang++-18 cmake -DCMAKE_AR:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ar -DCMAKE_INSTALL_NAME_TOOL=${CCTOOLS}/bin/x86_64-apple-darwin-install_name_tool -DCMAKE_RANLIB:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ranlib -DLINKER_NAME=${CCTOOLS}/bin/x86_64-apple-darwin-ld -DCMAKE_TOOLCHAIN_FILE=cmake/darwin/toolchain-x86_64.cmake ..
2021-11-21 20:38:47 +00:00
ninja
2019-09-24 14:43:07 +00:00
```
2020-03-20 10:10:48 +00:00
The resulting binary will have a Mach-O executable format and can’ t be run on Linux.