aboutsummaryrefslogtreecommitdiffstats
path: root/BUILD.md
blob: 0452ac2c319e5c12068c412a61403fd05dc6dadd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# Building YDB from sources

## Build Requirements
 We have tested YDB builds using Ubuntu 18.04, 20.04 and 22.04. Other Linux distributions are likely to work, but additional effort may be needed. Only x86_64 Linux is currently supported.

 Below is a list of packages that need to be installed before building YDB. 'How to Build' section contains step by step instructions to obtain these packages.

 - cmake 3.22+
 - clang-12
 - lld-12
 - git 2.20+
 - python3.8
 - pip3
 - antlr3
 - libaio-dev
 - libidn11-dev
 - ninja 1.10+

 We run multiple clang instances in parallel to speed up the process by default. Each instance of clang may use up to 1GB of RAM, and linking the binary may use up to 16GB of RAM, please make sure your build host has enough resources.

## Runtime Requirements
 The following packages are required to run ydbd server:

 - libidn11
 - libaio

# How to Build

## (optional) Add CMake and LLVM APT repositories (for Ubuntu 18.04 and 20.04)

## Ubuntu 18.04

For Ubuntu 18.04, you have to add CMake and LLVM APT repositories:

```bash
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc | sudo apt-key add -
echo "deb http://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-12 main" | sudo tee /etc/apt/sources.list.d/llvm.list >/dev/null

sudo apt-get update

```

## Ubuntu 20.04

For Ubuntu 20.04, you have to add CMake APT repository:

```bash
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc | sudo apt-key add -
echo "deb http://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null

sudo apt-get update

```


## Install dependencies

```bash
sudo apt-get -y install git cmake python3-pip ninja-build antlr3 m4 clang-12 lld-12 libidn11-dev libaio1 libaio-dev llvm-12
sudo pip3 install conan==1.59

```

## Create the work directory. 
> :warning: Please make sure you have at least 80Gb of free space. We also recommend placing this directory on SSD to reduce build times.

```bash
mkdir ~/ydbwork && cd ~/ydbwork
mkdir build

```

## Clone the ydb repository.

```bash
git clone https://github.com/ydb-platform/ydb.git
```

## Configure



### Configure without Ccache

Run cmake to generate build configuration:

```bash
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../ydb/clang.toolchain ../ydb

```


### (optional) Configure with Ccache

With enabled Ccache, you can finish the compilation of all targets on supported Linux distributions in a few minutes. 
  Or just `ydbd` or `ydb` binary in a couple of seconds. To optionally enable `Ccache` and enhance the compilation speed, follow these steps:

1. Install `Ccache` into `/usr/local/bin/` (We are using version `4.8.1`, you can use any version greater than `4.7`)
    ```bash
    (V=4.8.1; curl -L https://github.com/ccache/ccache/releases/download/v${V}/ccache-${V}-linux-x86_64.tar.xz | \
     sudo tar -xJ -C /usr/local/bin/ --strip-components=1 --no-same-owner ccache-${V}-linux-x86_64/ccache)

    ```

2. Configure `Ccache` to use remote storage using environment variables
    ```bash
    export CCACHE_REMOTE_STORAGE="http://158.160.20.102:8080|read-only|layout=bazel"
    export CCACHE_SLOPPINESS=locale
    export CCACHE_BASEDIR=~/ydbwork/
   
    ```
    <details>
    <summary>or using Ccache config file</summary>

    ```bash
    ccache -o remote_storage="http://158.160.20.102:8080|read-only|layout=bazel"
    ccache -o sloppiness=locale 
    ccache -o base_dir=~/ydbwork/
   
    ```
    </details>
3. Also, you should change Conan's home folder to the build folder for better cache hit 
    ```bash
    export CONAN_USER_HOME=~/ydbwork/build
    ```

4. Genreate build configuration using `ccache`
    ```bash
    cd build
    cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_C_COMPILER_LAUNCHER=/usr/local/bin/ccache -DCMAKE_CXX_COMPILER_LAUNCHER=/usr/local/bin/ccache \
    -DCMAKE_TOOLCHAIN_FILE=../ydb/clang.toolchain \
    ../ydb
   
    ```

## Build

To build both YDB server (ydbd) and YDB CLI (ydb) run:
```bash
ninja
```

To build only YDB CLI (ydb) run:
```bash
ninja ydb/apps/ydb/all
```

A YDB server binary can be found at:
```
ydb/apps/ydbd/ydbd
```
A YDB CLI binary can be found at:
```
ydb/apps/ydb/ydb
```