从 RocksDB 7.0 开始,RocksDB 要求编译的 C++ 必须支持 C++ 17 ,( Dropping some compiler support in 7.0#9388)但是目前的Android/iOS版本显然暂时还不能大范围的适配 C++ 17,因此我们目前只能使用 6.x 版本。
Android:
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 |
# Android NDK 22.1.7171670 $ brew install git $ brew install cmake $ brew install sed $ git clone https://github.com/facebook/rocksdb.git $ git checkout v6.29.5 # 修改代码,消除警告视为错误,否则会编译不通过 $ gsed -i "s/-Werror//g" CMakeLists.txt # Android最低支持的版本是 Android 23 低于这个版本会出现API缺失导致编译失败 $ cmake . -DCMAKE_ANDROID_NDK=/Users/xxxx/Library/Android/sdk/ndk-bundle \ -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_SYSTEM_VERSION=23 \ -DCMAKE_ANDROID_STL_TYPE=c++_shared \ -DROCKSDB_LITE=ON \ -DPORTABLE=ON \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DWITH_TESTS=OFF \ -DWITH_TOOLS=OFF \ -DWITH_GFLAGS=OFF \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a // -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a // -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a // -DCMAKE_ANDROID_ARCH_ABI=armeabi // -DCMAKE_ANDROID_ARCH_ABI=x86 // -DCMAKE_ANDROID_ARCH_ABI=x86_64 $ make # 在当前目录下生成 # librocksdb.so |
iOS/macOS ARM:
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 |
#Xcode Version 13.2.1 (13C100) $ brew install git $ brew install cmake $ git clone https://github.com/facebook/rocksdb.git $ git checkout v6.29.5 $ export PORTABLE=1 $ export TARGET_OS=IOS $ export ROCKSDB_LITE=1 $ export IOS_CROSS_COMPILE=1 # int128兼容支持,默认支持,但是在iOS设备上是不支持的 $ export TEST_UINT128_COMPAT=1 $ export DISABLE_WARNING_AS_ERROR=1 $ export DEBUG_LEVEL=0 $ export EXTRA_CXXFLAGS="-DNPERF_CONTEXT -DNIOSTATS_CONTEXT" # iOS目前只能构建静态库,不能构建动态库 $ make V=1 VERBOSE=1 -j16 static_lib |
macOS x86:
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 |
#Xcode Version 13.2.1 (13C100) $ brew install git $ brew install cmake $ git clone https://github.com/facebook/rocksdb.git $ git checkout v6.29.5 $ export PORTABLE=1 $ export ROCKSDB_LITE=1 # int128兼容支持,默认支持,但是在iOS设备上是不支持的 $ export TEST_UINT128_COMPAT=1 $ export DISABLE_WARNING_AS_ERROR=1 $ export DEBUG_LEVEL=0 $ export EXTRA_CXXFLAGS="-DNPERF_CONTEXT -DNIOSTATS_CONTEXT" $ make V=1 VERBOSE=1 -j16 static_lib # make V=1 VERBOSE=1 -j16 shared_lib 动态库 |
参考链接
- CMake could not find JNI
- Is there any document for building/integrating rocksdb for/into android/ios app ? #1193
- cmake-toolchains(7)
- Got message "Please install gflags to run rocksdb tools" while running ./db_bench #1775
- cmake Disable Werror
- NDK CMake
- Cross Compiling for iOS, tvOS, or watchOS
- https://github.com/facebook/rocksdb/blob/master/INSTALL.md
- rocksdb编译步骤——Java、Golang、mac
- RocksDB 7 may have C++17 dependency #75496
- Dropping some compiler support in 7.0#9388
- Cant build librocksdb.a for iOS platform in M1 #8416
- Performance impact from perf context with PerfLevel::kDisable #9372
- https://github.com/facebook/rocksdb/blob/c465509379d72068c19b55dbc69bf08d8c387fbe/build_tools/build_detect_platform#L136
- building for iOS Simulator, but linking in object file built for macOS, file '..customLib.a' for architecture x86_64