66from conan .errors import ConanInvalidConfiguration
77from conan .tools .build import check_min_cppstd
88from conan .tools .cmake import CMake , CMakeDeps , CMakeToolchain , cmake_layout
9- from conan .tools .files import apply_conandata_patches , collect_libs , copy , export_conandata_patches , get , rm , rmdir
9+ from conan .tools .files import apply_conandata_patches , collect_libs , copy , export_conandata_patches , get , rm , rmdir , replace_in_file
1010from conan .tools .microsoft import is_msvc , is_msvc_static_runtime
1111from conan .tools .scm import Version
1212
@@ -32,6 +32,7 @@ class RocksDBConan(ConanFile):
3232 "with_zlib" : [True , False ],
3333 "with_zstd" : [True , False ],
3434 "with_tbb" : [True , False ],
35+ "with_folly" : [True , False ],
3536 "with_jemalloc" : [True , False ],
3637 "enable_sse" : [False , "sse42" , "avx2" ],
3738 "use_rtti" : [True , False ],
@@ -47,6 +48,7 @@ class RocksDBConan(ConanFile):
4748 "with_gflags" : False ,
4849 "with_tbb" : False ,
4950 "with_jemalloc" : False ,
51+ "with_folly" : False ,
5052 "enable_sse" : False ,
5153 "use_rtti" : False ,
5254 }
@@ -55,6 +57,17 @@ class RocksDBConan(ConanFile):
5557 def _min_cppstd (self ):
5658 return "11" if Version (self .version ) < "8.8.1" else "17"
5759
60+ @property
61+ def _has_folly (self ):
62+ # Folly became unvendored in 7.7.2
63+ # https://github.com/facebook/rocksdb/commit/be09943fb58a2dd3f70e6e30781ebfa3fcbcb8fa
64+ return Version (self .version ) >= "7.7.2"
65+
66+ @property
67+ def _has_lite (self ):
68+ # https://github.com/facebook/rocksdb/commit/4720ba4391eb016b05a30d09a8275624c3a4a87e
69+ return Version (self .version ) < "8.0.0"
70+
5871 def export_sources (self ):
5972 export_conandata_patches (self )
6073
@@ -65,6 +78,10 @@ def config_options(self):
6578 del self .options .with_tbb
6679 if self .settings .build_type == "Debug" :
6780 self .options .use_rtti = True # Rtti are used in asserts for debug mode...
81+ if not self ._has_folly :
82+ del self .options .with_folly
83+ if not self ._has_lite :
84+ del self .options .lite
6885
6986 def configure (self ):
7087 if self .options .shared :
@@ -77,17 +94,19 @@ def requirements(self):
7794 if self .options .with_gflags :
7895 self .requires ("gflags/2.2.2" )
7996 if self .options .with_snappy :
80- self .requires ("snappy/1.1.10" )
97+ self .requires ("snappy/[>= 1.1.10 <2] " )
8198 if self .options .with_lz4 :
82- self .requires ("lz4/1.9.4" )
99+ self .requires ("lz4/[>= 1.9.4 <2] " )
83100 if self .options .with_zlib :
84101 self .requires ("zlib/[>=1.2.11 <2]" )
85102 if self .options .with_zstd :
86- self .requires ("zstd/1.5.5 " )
103+ self .requires ("zstd/[~ 1.5] " )
87104 if self .options .get_safe ("with_tbb" ):
88105 self .requires ("onetbb/2021.10.0" )
89106 if self .options .with_jemalloc :
90107 self .requires ("jemalloc/5.3.0" )
108+ if self .options .get_safe ("with_folly" ):
109+ self .requires ("folly/2024.08.12.00" )
91110
92111 def validate (self ):
93112 check_min_cppstd (self , self ._min_cppstd )
@@ -98,6 +117,10 @@ def validate(self):
98117 if is_msvc (self ) and Version (self .settings .compiler .version ) < "191" :
99118 raise ConanInvalidConfiguration ("Rocksdb requires MSVC version >= 191" )
100119
120+ if self .options .shared and self .options .get_safe ("with_folly" ):
121+ # https://github.com/facebook/rocksdb/blob/v10.5.1/CMakeLists.txt#L603
122+ raise ConanInvalidConfiguration (f"{ self .ref } does not support a shared build with folly" )
123+
101124 def source (self ):
102125 get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
103126
@@ -108,18 +131,24 @@ def generate(self):
108131 tc .variables ["WITH_TOOLS" ] = False
109132 tc .variables ["WITH_CORE_TOOLS" ] = False
110133 tc .variables ["WITH_BENCHMARK_TOOLS" ] = False
111- tc .variables ["WITH_FOLLY_DISTRIBUTED_MUTEX" ] = False
134+ if Version (self .version ) < "7.2.0" :
135+ # https://github.com/facebook/rocksdb/commit/efd035164b443e0ae552a82ad8b47a8048e652ca
136+ tc .variables ["WITH_FOLLY_DISTRIBUTED_MUTEX" ] = False
137+ if self ._has_folly :
138+ tc .variables ["USE_FOLLY" ] = self .options .with_folly
112139 if is_msvc (self ):
113140 tc .variables ["WITH_MD_LIBRARY" ] = not is_msvc_static_runtime (self )
114141 tc .variables ["ROCKSDB_INSTALL_ON_WINDOWS" ] = self .settings .os == "Windows"
115- tc .variables ["ROCKSDB_LITE" ] = self .options .lite
142+ if self ._has_lite :
143+ tc .variables ["ROCKSDB_LITE" ] = self .options .lite
116144 tc .variables ["WITH_GFLAGS" ] = self .options .with_gflags
117145 tc .variables ["WITH_SNAPPY" ] = self .options .with_snappy
118146 tc .variables ["WITH_LZ4" ] = self .options .with_lz4
119147 tc .variables ["WITH_ZLIB" ] = self .options .with_zlib
120148 tc .variables ["WITH_ZSTD" ] = self .options .with_zstd
121149 tc .variables ["WITH_TBB" ] = self .options .get_safe ("with_tbb" , False )
122150 tc .variables ["WITH_JEMALLOC" ] = self .options .with_jemalloc
151+
123152 tc .variables ["ROCKSDB_BUILD_SHARED" ] = self .options .shared
124153 tc .variables ["ROCKSDB_LIBRARY_EXPORTS" ] = self .settings .os == "Windows" and self .options .shared
125154 tc .variables ["ROCKSDB_DLL" ] = self .settings .os == "Windows" and self .options .shared
@@ -143,10 +172,20 @@ def generate(self):
143172 deps .set_property ("jemalloc" , "cmake_target_name" , "JeMalloc::JeMalloc" )
144173 if self .options .with_zstd :
145174 deps .set_property ("zstd" , "cmake_target_name" , "zstd::zstd" )
175+ if self .options .get_safe ("with_folly" ):
176+ deps .set_property ("folly" , "cmake_additional_variables_prefixes" , ["FOLLY" ,])
146177 deps .generate ()
147178
179+ def _patch_sources (self ):
180+ # INFO: --copy-dt-needed-entries is only needed for ld.bfd and breaks other linkers like ld.gold and lld
181+ # https://github.com/facebook/rocksdb/issues/13895
182+ if self ._has_folly :
183+ replace_in_file (self , os .path .join (self .source_folder , "CMakeLists.txt" ),
184+ 'set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")' , "" )
185+
148186 def build (self ):
149187 apply_conandata_patches (self )
188+ self ._patch_sources ()
150189 cmake = CMake (self )
151190 cmake .configure ()
152191 cmake .build ()
@@ -188,7 +227,7 @@ def package_info(self):
188227 self .cpp_info .components ["librocksdb" ].defines = ["ROCKSDB_DLL" ]
189228 elif self .settings .os in ["Linux" , "FreeBSD" ]:
190229 self .cpp_info .components ["librocksdb" ].system_libs = ["pthread" , "m" ]
191- if self .options .lite :
230+ if self .options .get_safe ( " lite" ) :
192231 self .cpp_info .components ["librocksdb" ].defines .append ("ROCKSDB_LITE" )
193232
194233 self .cpp_info .components ["librocksdb" ].set_property ("cmake_target_name" , f"RocksDB::{ cmake_target } " )
@@ -206,3 +245,5 @@ def package_info(self):
206245 self .cpp_info .components ["librocksdb" ].requires .append ("onetbb::onetbb" )
207246 if self .options .with_jemalloc :
208247 self .cpp_info .components ["librocksdb" ].requires .append ("jemalloc::jemalloc" )
248+ if self .options .get_safe ("with_folly" ):
249+ self .cpp_info .components ["librocksdb" ].requires .append ("folly::folly" )
0 commit comments