Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocksdb: modernize #9362

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion recipes/rocksdb/all/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.9)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

add_subdirectory(source_subfolder)
36 changes: 18 additions & 18 deletions recipes/rocksdb/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
sources:
"6.0.2":
url: https://github.com/facebook/rocksdb/archive/v6.0.2.tar.gz
sha256: 89e0832f1fb00ac240a9438d4bbdae37dd3e52f7c15c3f646dc26887da16f342
"6.8.1":
url: https://github.com/facebook/rocksdb/archive/v6.8.1.tar.gz
sha256: ca192a06ed3bcb9f09060add7e9d0daee1ae7a8705a3d5ecbe41867c5e2796a2
"6.10.2":
url: https://github.com/facebook/rocksdb/archive/v6.10.2.tar.gz
sha256: 514b315c64159dd767bbbf6430d33313903c0c9240d4249bddead5c4297d128f
"6.20.3":
url: https://github.com/facebook/rocksdb/archive/v6.20.3.tar.gz
sha256: c6502c7aae641b7e20fafa6c2b92273d935d2b7b2707135ebd9a67b092169dca
patches:
"6.0.2":
- patch_file: "patches/6.0.2/0001-Rename-jemalloc-according-to-conan-packages.patch"
base_path: "source_subfolder"
url: "https://github.com/facebook/rocksdb/archive/v6.20.3.tar.gz"
sha256: "c6502c7aae641b7e20fafa6c2b92273d935d2b7b2707135ebd9a67b092169dca"
"6.10.2":
url: "https://github.com/facebook/rocksdb/archive/v6.10.2.tar.gz"
sha256: "514b315c64159dd767bbbf6430d33313903c0c9240d4249bddead5c4297d128f"
"6.8.1":
- patch_file: "patches/6.8.1/0001-Rename-jemalloc-according-to-conan-packages.patch"
url: "https://github.com/facebook/rocksdb/archive/v6.8.1.tar.gz"
sha256: "ca192a06ed3bcb9f09060add7e9d0daee1ae7a8705a3d5ecbe41867c5e2796a2"
"6.0.2":
url: "https://github.com/facebook/rocksdb/archive/v6.0.2.tar.gz"
sha256: "89e0832f1fb00ac240a9438d4bbdae37dd3e52f7c15c3f646dc26887da16f342"
patches:
"6.20.3":
- patch_file: "patches/6.20.3/0001-Rename-jemalloc-according-to-conan-packages.patch"
base_path: "source_subfolder"
"6.10.2":
- patch_file: "patches/6.10.2/0001-Rename-jemalloc-according-to-conan-packages.patch"
base_path: "source_subfolder"
"6.20.3":
- patch_file: "patches/6.20.3/0001-Rename-jemalloc-according-to-conan-packages.patch"
"6.8.1":
- patch_file: "patches/6.8.1/0001-Rename-jemalloc-according-to-conan-packages.patch"
base_path: "source_subfolder"
"6.0.2":
- patch_file: "patches/6.0.2/0001-Rename-jemalloc-according-to-conan-packages.patch"
base_path: "source_subfolder"
108 changes: 60 additions & 48 deletions recipes/rocksdb/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import glob
import shutil

required_conan_version = ">=1.43.0"


class RocksDB(ConanFile):
name = "rocksdb"
homepage = "https://github.com/facebook/rocksdb"
license = ("GPL-2.0-only", "Apache-2.0")
url = "https://github.com/conan-io/conan-center-index"
description = "A library that provides an embeddable, persistent key-value store for fast storage"
topics = ("conan", "rocksdb", "database",
"leveldb", "facebook", "key-value")
settings = "os", "compiler", "build_type", "arch"
topics = ("rocksdb", "database", "leveldb", "facebook", "key-value")

settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -26,7 +29,7 @@ class RocksDB(ConanFile):
"with_tbb": [True, False],
"with_jemalloc": [True, False],
"enable_sse": [False, "sse42", "avx2"],
"use_rtti": [True, False]
"use_rtti": [True, False],
}
default_options = {
"shared": False,
Expand All @@ -40,11 +43,10 @@ class RocksDB(ConanFile):
"with_tbb": False,
"with_jemalloc": False,
"enable_sse": False,
"use_rtti": False
"use_rtti": False,
}
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake", "cmake_find_package"

generators = "cmake", "cmake_find_package"
_cmake = None

@property
Expand All @@ -55,15 +57,45 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

if self.settings.arch != "x86_64":
del self.options.with_tbb
if self.settings.build_type == "Debug":
self.options.use_rtti = True # Rtti are used in asserts for debug mode...

def configure(self):
if self.settings.compiler.cppstd:
if self.options.shared:
del self.options.fPIC

def requirements(self):
if self.options.with_gflags:
self.requires("gflags/2.2.2")
if self.options.with_snappy:
self.requires("snappy/1.1.9")
if self.options.with_lz4:
self.requires("lz4/1.9.3")
if self.options.with_zlib:
self.requires("zlib/1.2.11")
if self.options.with_zstd:
self.requires("zstd/1.5.2")
if self.options.get_safe("with_tbb"):
self.requires("onetbb/2020.3")
if self.options.with_jemalloc:
self.requires("jemalloc/5.2.1")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if self.settings.arch not in ["x86_64", "ppc64le", "ppc64", "mips64", "armv8"]:
raise ConanInvalidConfiguration("Rocksdb requires 64 bits")
Expand All @@ -72,7 +104,7 @@ def configure(self):
self.settings.compiler == "Visual Studio" and \
tools.Version(self.settings.compiler.version) < "15":
raise ConanInvalidConfiguration("Rocksdb requires Visual Studio 15 or later.")

if self.version == "6.0.2" and \
self.settings.os == "Windows" and \
self.settings.compiler == "Visual Studio" and \
Expand All @@ -91,35 +123,9 @@ def configure(self):
tools.Version(self.settings.compiler.version) < "5":
raise ConanInvalidConfiguration("Rocksdb 6.20.3 is not compilable with gcc <5.") # See https://github.com/facebook/rocksdb/issues/3522

if self.settings.build_type == "Debug":
self.options.use_rtti = True # Rtti are used in asserts for debug mode...

if self.options.shared:
del self.options.fPIC

def requirements(self):
if self.options.with_gflags:
self.requires("gflags/2.2.2")
if self.options.with_snappy:
self.requires("snappy/1.1.8")
if self.options.with_lz4:
self.requires("lz4/1.9.2")
if self.options.with_zlib:
self.requires("zlib/1.2.11")
if self.options.with_zstd:
self.requires("zstd/1.4.5")
if self.options.get_safe("with_tbb"):
self.requires("tbb/2020.2")
if self.options.with_jemalloc:
self.requires("jemalloc/5.2.1")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "{name}-{version}".format(
name = self.name,
version = self.version
)
os.rename(extracted_dir, self._source_subfolder)
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def _configure_cmake(self):
if not self._cmake:
Expand All @@ -131,7 +137,8 @@ def _configure_cmake(self):
self._cmake.definitions["WITH_CORE_TOOLS"] = False
self._cmake.definitions["WITH_BENCHMARK_TOOLS"] = False
self._cmake.definitions["WITH_FOLLY_DISTRIBUTED_MUTEX"] = False
self._cmake.definitions["WITH_MD_LIBRARY"] = self.settings.compiler == "Visual Studio" and "MD" in self.settings.compiler.runtime
if self._is_msvc:
self._cmake.definitions["WITH_MD_LIBRARY"] = "MD" in msvc_runtime_flag(self)
self._cmake.definitions["ROCKSDB_INSTALL_ON_WINDOWS"] = self.settings.os == "Windows"
self._cmake.definitions["ROCKSDB_LITE"] = self.options.lite
self._cmake.definitions["WITH_GFLAGS"] = self.options.with_gflags
Expand Down Expand Up @@ -176,9 +183,8 @@ def build(self):
cmake.build()

def _remove_static_libraries(self):
for static_lib_name in ["lib*.a", "{}.lib".format(self.name)]:
for file in glob.glob(os.path.join(self.package_folder, "lib", static_lib_name)):
os.remove(file)
for static_lib_name in ["lib*.a", "rocksdb.lib"]:
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), static_lib_name)

def _remove_cpp_headers(self):
for path in glob.glob(os.path.join(self.package_folder, "include", "rocksdb", "*")):
Expand All @@ -199,20 +205,26 @@ def package(self):
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "RocksDB"
self.cpp_info.names["cmake_find_package_multi"] = "RocksDB"
cmake_target = "rocksdb-shared" if self.options.shared else "rocksdb"
self.cpp_info.components["librocksdb"].names["cmake_find_package"] = cmake_target
self.cpp_info.components["librocksdb"].names["cmake_find_package_multi"] = cmake_target
self.cpp_info.set_property("cmake_file_name", "RocksDB")
self.cpp_info.set_property("cmake_target_name", "RocksDB::{}".format(cmake_target))
# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
self.cpp_info.components["librocksdb"].libs = tools.collect_libs(self)
if self.settings.os == "Windows":
self.cpp_info.components["librocksdb"].system_libs = ["shlwapi", "rpcrt4"]
if self.options.shared:
self.cpp_info.components["librocksdb"].defines = ["ROCKSDB_DLL"]
elif self.settings.os == "Linux":
elif self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["librocksdb"].system_libs = ["pthread", "m"]
if self.options.lite:
self.cpp_info.components["librocksdb"].defines.append("ROCKSDB_LITE")

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "RocksDB"
self.cpp_info.names["cmake_find_package_multi"] = "RocksDB"
self.cpp_info.components["librocksdb"].names["cmake_find_package"] = cmake_target
self.cpp_info.components["librocksdb"].names["cmake_find_package_multi"] = cmake_target
self.cpp_info.components["librocksdb"].set_property("cmake_target_name", "RocksDB::{}".format(cmake_target))
if self.options.with_gflags:
self.cpp_info.components["librocksdb"].requires.append("gflags::gflags")
if self.options.with_snappy:
Expand All @@ -224,6 +236,6 @@ def package_info(self):
if self.options.with_zstd:
self.cpp_info.components["librocksdb"].requires.append("zstd::zstd")
if self.options.get_safe("with_tbb"):
self.cpp_info.components["librocksdb"].requires.append("tbb::tbb")
self.cpp_info.components["librocksdb"].requires.append("onetbb::onetbb")
if self.options.with_jemalloc:
self.cpp_info.components["librocksdb"].requires.append("jemalloc::jemalloc")
2 changes: 1 addition & 1 deletion recipes/rocksdb/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(TARGETS)

find_package(RocksDB REQUIRED CONFIG)

Expand Down
4 changes: 2 additions & 2 deletions recipes/rocksdb/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
Expand All @@ -13,7 +13,7 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
if not self.options["rocksdb"].shared:
bin_path = os.path.join("bin", "test_package_cpp")
self.run(bin_path, run_environment=True)
Expand Down
9 changes: 4 additions & 5 deletions recipes/rocksdb/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
versions:
"6.0.2":
folder: all
"6.8.1":
"6.20.3":
folder: all
"6.10.2":
folder: all
"6.20.3":
"6.8.1":
folder: all
"6.0.2":
folder: all