2014-05-08 01:51:30 +02:00
## Compilation
2017-03-17 19:39:00 +01:00
**Important**: If you plan to run RocksDB in production, don't compile using default
2015-10-08 23:11:32 +02:00
`make` or `make all` . That will compile RocksDB in debug mode, which is much slower
than release mode.
2014-05-08 01:51:30 +02:00
RocksDB's library should be able to compile without any dependency installed,
although we recommend installing some compression libraries (see below).
2022-02-05 02:12:03 +01:00
We do depend on newer gcc/clang with C++17 support (GCC >= 7, Clang >= 5).
2014-05-08 01:51:30 +02:00
There are few options when compiling RocksDB:
2013-11-18 20:44:17 +01:00
2015-10-08 23:11:32 +02:00
* [recommended] `make static_lib` will compile librocksdb.a, RocksDB static library. Compiles static library in release mode.
2013-11-18 20:44:17 +01:00
2015-10-08 23:11:32 +02:00
* `make shared_lib` will compile librocksdb.so, RocksDB shared library. Compiles shared library in release mode.
2014-05-08 01:51:30 +02:00
2015-10-08 23:11:32 +02:00
* `make check` will compile and run all the unit tests. `make check` will compile RocksDB in debug mode.
2014-05-08 01:51:30 +02:00
* `make all` will compile our static library, and all our tools and unit tests. Our tools
2015-10-08 23:11:32 +02:00
depend on gflags. You will need to have gflags installed to run `make all` . This will compile RocksDB in debug mode. Don't
use binaries compiled by `make all` in production.
2014-05-08 01:51:30 +02:00
2014-12-15 11:29:41 +01:00
* By default the binary we produce is optimized for the platform you're compiling on
cross-platform compatibility improvements
Summary:
We've had a couple CockroachDB users fail to build RocksDB on exotic platforms, so I figured I'd try my hand at solving these issues upstream. The problems stem from a) `USE_SSE=1` being too aggressive about turning on SSE4.2, even on toolchains that don't support SSE4.2 and b) RocksDB attempting to detect support for thread-local storage based on OS, even though it can vary by compiler on the same OS.
See the individual commit messages for details. Regarding SSE support, this PR should change virtually nothing for non-CMake based builds. `make`, `PORTABLE=1 make`, `USE_SSE=1 make`, and `PORTABLE=1 USE_SSE=1 make` function exactly as before, except that SSE support will be automatically disabled when a simple SSE4.2-using test program fails to compile, as it does on OpenBSD. (OpenBSD's ports GCC supports SSE4.2, but its binutils do not, so `__SSE_4_2__` is defined but an SSE4.2-using program will fail to assemble.) A warning is emitted in this case. The CMake build is modified to support the same set of options, except that `USE_SSE` is spelled `FORCE_SSE42` because `USE_SSE` is rather useless now that we can automatically detect SSE support, and I figure changing options in the CMake build is less disruptive than changing the non-CMake build.
I've tested these changes on all the platforms I can get my hands on (macOS, Windows MSVC, Windows MinGW, and OpenBSD) and it all works splendidly. Let me know if there's anything you object to—I obviously don't mean to break any of your build pipelines in the process of fixing ours downstream.
Closes https://github.com/facebook/rocksdb/pull/2199
Differential Revision: D5054042
Pulled By: yiwu-arbug
fbshipit-source-id: 938e1fc665c049c02ae15698e1409155b8e72171
2017-05-15 23:42:32 +02:00
(`-march=native` or the equivalent). SSE4.2 will thus be enabled automatically if your
CPU supports it. To print a warning if your CPU does not support SSE4.2, build with
`USE_SSE=1 make static_lib` or, if using CMake, `cmake -DFORCE_SSE42=ON` . If you want
to build a portable binary, add `PORTABLE=1` before your make commands, like this:
`PORTABLE=1 make static_lib` .
2014-09-30 02:25:02 +02:00
2014-05-08 01:51:30 +02:00
## Dependencies
* You can link RocksDB with following compression libraries:
2013-11-18 20:44:17 +01:00
- [zlib ](http://www.zlib.net/ ) - a library for data compression.
- [bzip2 ](http://www.bzip.org/ ) - a library for data compression.
2017-07-10 21:08:16 +02:00
- [lz4 ](https://github.com/lz4/lz4 ) - a library for extremely fast data compression.
2017-02-13 07:53:42 +01:00
- [snappy ](http://google.github.io/snappy/ ) - a library for fast
2013-11-18 20:44:17 +01:00
data compression.
2017-02-13 07:53:42 +01:00
- [zstandard ](http://www.zstd.net ) - Fast real-time compression
algorithm.
2013-11-18 20:44:17 +01:00
2014-05-08 01:51:30 +02:00
* All our tools depend on:
2015-06-22 18:31:52 +02:00
- [gflags ](https://gflags.github.io/gflags/ ) - a library that handles
2014-05-08 01:51:30 +02:00
command line flags processing. You can compile rocksdb library even
if you don't have gflags installed.
2013-11-18 20:44:17 +01:00
2021-04-07 01:00:12 +02:00
* `make check` will also check code formatting, which requires [clang-format ](https://clang.llvm.org/docs/ClangFormat.html )
2018-12-19 05:21:22 +01:00
* If you wish to build the RocksJava static target, then cmake is required for building Snappy.
2022-04-01 02:17:44 +02:00
* If you wish to run microbench (e.g, `make microbench` , `make ribbon_bench` or `cmake -DWITH_BENCHMARK=1` ), Google benchmark >= 1.6.0 is needed.
2022-02-07 18:56:30 +01:00
2013-11-18 20:44:17 +01:00
## Supported platforms
2014-01-29 17:41:43 +01:00
* **Linux - Ubuntu**
2022-02-05 02:12:03 +01:00
* Upgrade your gcc to version at least 7 to get C++17 support.
2014-01-29 17:41:43 +01:00
* Install gflags. First, try: `sudo apt-get install libgflags-dev`
2013-12-02 15:48:23 +01:00
If this doesn't work and you're using Ubuntu, here's a nice tutorial:
2013-11-18 20:44:17 +01:00
(http://askubuntu.com/questions/312173/installing-gflags-12-04)
* Install snappy. This is usually as easy as:
`sudo apt-get install libsnappy-dev` .
* Install zlib. Try: `sudo apt-get install zlib1g-dev` .
* Install bzip2: `sudo apt-get install libbz2-dev` .
2017-07-10 21:08:16 +02:00
* Install lz4: `sudo apt-get install liblz4-dev` .
2017-02-13 07:53:42 +01:00
* Install zstandard: `sudo apt-get install libzstd-dev` .
* **Linux - CentOS / RHEL**
2022-02-05 02:12:03 +01:00
* Upgrade your gcc to version at least 7 to get C++17 support
2014-01-29 17:41:43 +01:00
* Install gflags:
2017-02-13 07:53:42 +01:00
git clone https://github.com/gflags/gflags.git
cd gflags
2017-04-03 20:58:00 +02:00
git checkout v2.0
2014-01-29 17:41:43 +01:00
./configure & & make & & sudo make install
2017-05-12 20:58:05 +02:00
**Notice** : Once installed, please add the include path for gflags to your `CPATH` environment variable and the
lib path to `LIBRARY_PATH` . If installed with default settings, the include path will be `/usr/local/include`
and the lib path will be `/usr/local/lib` .
2017-04-05 01:24:08 +02:00
2014-01-29 17:41:43 +01:00
* Install snappy:
2017-05-12 20:58:05 +02:00
sudo yum install snappy snappy-devel
2014-01-29 17:41:43 +01:00
* Install zlib:
2017-05-12 20:58:05 +02:00
sudo yum install zlib zlib-devel
2014-01-29 17:41:43 +01:00
* Install bzip2:
2017-05-12 20:58:05 +02:00
sudo yum install bzip2 bzip2-devel
2017-07-10 21:08:16 +02:00
* Install lz4:
sudo yum install lz4-devel
2017-05-12 20:58:05 +02:00
* Install ASAN (optional for debugging):
sudo yum install libasan
2014-01-29 17:41:43 +01:00
2017-02-13 07:53:42 +01:00
* Install zstandard:
2021-04-07 01:00:12 +02:00
* With [EPEL ](https://fedoraproject.org/wiki/EPEL ):
sudo yum install libzstd-devel
* With CentOS 8:
sudo dnf install libzstd-devel
* From source:
2017-02-13 07:53:42 +01:00
2021-04-07 01:00:12 +02:00
wget https://github.com/facebook/zstd/archive/v1.1.3.tar.gz
mv v1.1.3.tar.gz zstd-1.1.3.tar.gz
tar zxvf zstd-1.1.3.tar.gz
cd zstd-1.1.3
make & & sudo make install
2017-02-13 07:53:42 +01:00
2013-11-18 20:44:17 +01:00
* **OS X**:
2022-02-05 02:12:03 +01:00
* Install latest C++ compiler that supports C++ 17:
2013-11-20 23:55:33 +01:00
* Update XCode: run `xcode-select --install` (or install it from XCode App's settting).
* Install via [homebrew ](http://brew.sh/ ).
2013-11-20 23:54:53 +01:00
* If you're first time developer in MacOS, you still need to run: `xcode-select --install` in your command line.
2022-02-05 02:12:03 +01:00
* run `brew tap homebrew/versions; brew install gcc7 --use-llvm` to install gcc 7 (or higher).
2014-12-15 11:29:41 +01:00
* run `brew install rocksdb`
2013-11-18 20:44:17 +01:00
2018-01-11 22:21:35 +01:00
* **FreeBSD** (11.01):
* You can either install RocksDB from the Ports system using `cd /usr/ports/databases/rocksdb && make install` , or you can follow the details below to install dependencies and compile from source code:
* Install the dependencies for RocksDB:
export BATCH=YES
cd /usr/ports/devel/gmake & & make install
cd /usr/ports/devel/gflags & & make install
cd /usr/ports/archivers/snappy & & make install
cd /usr/ports/archivers/bzip2 & & make install
cd /usr/ports/archivers/liblz4 & & make install
cd /usr/ports/archivesrs/zstd & & make install
cd /usr/ports/devel/git & & make install
* Install the dependencies for RocksJava (optional):
export BATCH=yes
cd /usr/ports/java/openjdk7 & & make install
* Build RocksDB from source:
cd ~
git clone https://github.com/facebook/rocksdb.git
cd rocksdb
gmake static_lib
* Build RocksJava from source (optional):
cd rocksdb
export JAVA_HOME=/usr/local/openjdk7
gmake rocksdbjava
2018-03-19 20:11:58 +01:00
* **OpenBSD** (6.3/-current):
* As RocksDB is not available in the ports yet you have to build it on your own:
* Install the dependencies for RocksDB:
2022-02-05 02:12:03 +01:00
pkg_add gmake gflags snappy bzip2 lz4 zstd git jdk bash findutils gnuwatch
2018-03-19 20:11:58 +01:00
* Build RocksDB from source:
cd ~
git clone https://github.com/facebook/rocksdb.git
cd rocksdb
gmake static_lib
* Build RocksJava from source (optional):
cd rocksdb
export JAVA_HOME=/usr/local/jdk-1.8.0
export PATH=$PATH:/usr/local/jdk-1.8.0/bin
gmake rocksdbjava
2018-01-11 22:21:35 +01:00
2014-04-04 22:11:44 +02:00
* **iOS**:
2014-10-01 20:15:42 +02:00
* Run: `TARGET_OS=IOS make static_lib` . When building the project which uses rocksdb iOS library, make sure to define two important pre-processing macros: `ROCKSDB_LITE` and `IOS_CROSS_COMPILE` .
2015-07-08 01:58:20 +02:00
* **Windows**:
2015-10-15 20:06:02 +02:00
* For building with MS Visual Studio 13 you will need Update 4 installed.
2015-09-04 04:46:09 +02:00
* Read and follow the instructions at CMakeLists.txt
2022-02-05 02:12:03 +01:00
* Or install via [vcpkg ](https://github.com/microsoft/vcpkg )
2017-09-29 01:09:08 +02:00
* run `vcpkg install rocksdb:x64-windows`
2017-04-22 05:41:37 +02:00
* **AIX 6.1**
* Install AIX Toolbox rpms with gcc
* Use these environment variables:
2022-02-05 02:12:03 +01:00
2017-04-22 05:41:37 +02:00
export PORTABLE=1
export CC=gcc
export AR="ar -X64"
export EXTRA_ARFLAGS=-X64
export EXTRA_CFLAGS=-maix64
export EXTRA_CXXFLAGS=-maix64
export PLATFORM_LDFLAGS="-static-libstdc++ -static-libgcc"
export LIBPATH=/opt/freeware/lib
export JAVA_HOME=/usr/java8_64
export PATH=/opt/freeware/bin:$PATH
2022-02-05 02:12:03 +01:00
2017-04-22 05:41:37 +02:00
* **Solaris Sparc**
2022-02-05 02:12:03 +01:00
* Install GCC 7 and higher.
2017-04-22 05:41:37 +02:00
* Use these environment variables:
export CC=gcc
export EXTRA_CFLAGS=-m64
export EXTRA_CXXFLAGS=-m64
export EXTRA_LDFLAGS=-m64
export PORTABLE=1
export PLATFORM_LDFLAGS="-static-libstdc++ -static-libgcc"