Building ClickHouse on Windows

Introduction

We started working on creating a build for ClickHouse on WSL with the aim of becoming more familiar with ClickHouse. As an organization focusing on ClickHouse optimization at every level, this is obviously a necessity for us as well. And so the endeavour began.

The machine I was working on is a laptop with 8GB memory and AMD Ryzen 3 processor, running Windows 10. The WSL system was Ubuntu 20.04. The instructions for creating the build which I followed can be found at this link.

The instructions and commands to be followed are listed in the article given above, and I followed them to the letter. So it would be no surprise to the reader that I chose not to use GCC and went ahead with using Clang for the build, since the article recommends strongly against using it. But there was another reason why I didn’t bother using GCC, which was simply that GCC did not come pre-installed on my WSL Ubuntu. I could have installed it with a simple “sudo apt install”, but getting the specific version required for building ClickHouse (GCC 11 or above) might still be hard to get. If I ran out of all other options, I’d have to build GCC from source also, which was something I didn’t fancy wasting my time on when a huge task such as building ClickHouse was at hand.

Runbook to Build ClickHouse on Windows

You need the following tools for building ClickHouse from source:

  1. The latest version of Clang
  2. Git
  3. Cmake
  4. Python
  5. Ninja-build

All of the above except for Clang can be downloaded with the following command:

sudo apt-get install git cmake python ninja-build

To download Clang, you can use the following command on Ubuntu and Debian WSL images (This might work for other Debian-based Linux distributions also, but that needs to be verified):

sudo bash -c "$(wget -O -)"

https://apt.llvm.org/llvm.sh

This downloads the Clang compiler into your system, and you can set the default Clang version to be used in the terminal as follows:

export CC=clang-14
export CXX=clang++-14

We need to use Clang-14 or above for creating this build, since it is required by ClickHouse.

The next step is to clone the ClickHouse source code onto your machine. Take care to clone the repo recursively, if you are typing it out by hand, so that all the dependencies can be cloned along with the repository. This command achieves that:

git clone --recursive git@github.com:ClickHouse/ClickHouse.git

Alternatively, you could also use HTTPS to fetch the repository, with a minor change to the above command:

git clone --recursive

https://github.com/ClickHouse/ClickHouse.git

It could take you a comparatively long time to clone the ClickHouse repo and its dependencies. On my machine with its humble configuration, it took nearly an entire day.

Once you have cloned the ClickHouse repository, run the following commands one-after-the-other for the build to start:

First you go to the ClickHouse source directory:

cd ClickHouse

Next you create a build directory in the ClickHouse source root directory and enter it:

mkdir build && cd build

Then run CMake to create the build files in their appropriate locations:

cmake ..

Finally you can build the ClickHouse source with Ninja build:

ninja

Once you execute these commands, the build will be ready. Be warned, it could take a long time! Happy coding.

Conclusion

Building ClickHouse on Windows via WSL offers a valuable learning opportunity despite potential challenges. By following a step-by-step process with tools like Clang, Git, CMake, Python, and Ninja-build, developers can gain insights into ClickHouse’s architecture and optimization potential.

To know more about getting started with ClickHouse, do visit the following articles: