11import glob
22import os
3- import shutil
43
54from conan import ConanFile
65from conan .errors import ConanInvalidConfiguration
76from conan .tools .build import check_min_cppstd
87from 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 , replace_in_file
8+ from conan .tools .files import apply_conandata_patches , copy , export_conandata_patches , get , rm , rmdir , replace_in_file
109from conan .tools .microsoft import is_msvc , is_msvc_static_runtime
1110from conan .tools .scm import Version
1211
@@ -25,7 +24,6 @@ class RocksDBConan(ConanFile):
2524 options = {
2625 "shared" : [True , False ],
2726 "fPIC" : [True , False ],
28- "lite" : [True , False ],
2927 "with_gflags" : [True , False ],
3028 "with_snappy" : [True , False ],
3129 "with_lz4" : [True , False ],
@@ -40,7 +38,6 @@ class RocksDBConan(ConanFile):
4038 default_options = {
4139 "shared" : False ,
4240 "fPIC" : True ,
43- "lite" : False ,
4441 "with_snappy" : False ,
4542 "with_lz4" : False ,
4643 "with_zlib" : False ,
@@ -52,22 +49,7 @@ class RocksDBConan(ConanFile):
5249 "enable_sse" : False ,
5350 "use_rtti" : False ,
5451 }
55-
56- @property
57- def _min_cppstd (self ):
58- return "11" if Version (self .version ) < "8.8.1" else "17"
59-
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-
52+
7153 def export_sources (self ):
7254 export_conandata_patches (self )
7355
@@ -78,10 +60,6 @@ def config_options(self):
7860 del self .options .with_tbb
7961 if self .settings .build_type == "Debug" :
8062 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
8563
8664 def configure (self ):
8765 if self .options .shared :
@@ -105,24 +83,32 @@ def requirements(self):
10583 self .requires ("onetbb/2021.10.0" )
10684 if self .options .with_jemalloc :
10785 self .requires ("jemalloc/5.3.0" )
108- if self .options .get_safe ( " with_folly" ) :
86+ if self .options .with_folly :
10987 self .requires ("folly/2024.08.12.00" )
11088
11189 def validate (self ):
112- check_min_cppstd (self , self . _min_cppstd )
90+ check_min_cppstd (self , 17 )
11391
11492 if self .settings .arch not in ["x86_64" , "ppc64le" , "ppc64" , "mips64" , "armv8" ]:
11593 raise ConanInvalidConfiguration ("Rocksdb requires 64 bits" )
11694
11795 if is_msvc (self ) and Version (self .settings .compiler .version ) < "191" :
11896 raise ConanInvalidConfiguration ("Rocksdb requires MSVC version >= 191" )
11997
120- if self .options .shared and self .options .get_safe ( " with_folly" ) :
98+ if self .options .shared and self .options .with_folly :
12199 # https://github.com/facebook/rocksdb/blob/v10.5.1/CMakeLists.txt#L603
122100 raise ConanInvalidConfiguration (f"{ self .ref } does not support a shared build with folly" )
123101
102+ def _patch_sources (self ):
103+ # INFO: Avoid enforcing all linkers to use copy-dt-needed-entries
104+ # https://github.com/facebook/rocksdb/issues/13895
105+ replace_in_file (self , os .path .join (self .source_folder , "CMakeLists.txt" ),
106+ 'set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")' , "" )
107+
124108 def source (self ):
125109 get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
110+ apply_conandata_patches (self )
111+ self ._patch_sources ()
126112
127113 def generate (self ):
128114 tc = CMakeToolchain (self )
@@ -131,16 +117,10 @@ def generate(self):
131117 tc .variables ["WITH_TOOLS" ] = False
132118 tc .variables ["WITH_CORE_TOOLS" ] = False
133119 tc .variables ["WITH_BENCHMARK_TOOLS" ] = 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
120+ tc .variables ["USE_FOLLY" ] = self .options .with_folly
139121 if is_msvc (self ):
140122 tc .variables ["WITH_MD_LIBRARY" ] = not is_msvc_static_runtime (self )
141123 tc .variables ["ROCKSDB_INSTALL_ON_WINDOWS" ] = self .settings .os == "Windows"
142- if self ._has_lite :
143- tc .variables ["ROCKSDB_LITE" ] = self .options .lite
144124 tc .variables ["WITH_GFLAGS" ] = self .options .with_gflags
145125 tc .variables ["WITH_SNAPPY" ] = self .options .with_snappy
146126 tc .variables ["WITH_LZ4" ] = self .options .with_lz4
@@ -172,20 +152,11 @@ def generate(self):
172152 deps .set_property ("jemalloc" , "cmake_target_name" , "JeMalloc::JeMalloc" )
173153 if self .options .with_zstd :
174154 deps .set_property ("zstd" , "cmake_target_name" , "zstd::zstd" )
175- if self .options .get_safe ( " with_folly" ) :
155+ if self .options .with_folly :
176156 deps .set_property ("folly" , "cmake_additional_variables_prefixes" , ["FOLLY" ,])
177157 deps .generate ()
178158
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-
186159 def build (self ):
187- apply_conandata_patches (self )
188- self ._patch_sources ()
189160 cmake = CMake (self )
190161 cmake .configure ()
191162 cmake .build ()
@@ -196,41 +167,29 @@ def _remove_static_libraries(self):
196167 if not lib .endswith (".dll.a" ):
197168 os .remove (lib )
198169
199- def _remove_cpp_headers (self ):
200- for path in glob .glob (os .path .join (self .package_folder , "include" , "rocksdb" , "*" )):
201- if path != os .path .join (self .package_folder , "include" , "rocksdb" , "c.h" ):
202- if os .path .isfile (path ):
203- os .remove (path )
204- else :
205- shutil .rmtree (path )
206-
207170 def package (self ):
208171 copy (self , "COPYING" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ))
209172 copy (self , "LICENSE*" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ))
210173 cmake = CMake (self )
211174 cmake .install ()
212175 if self .options .shared :
213176 self ._remove_static_libraries ()
214- self ._remove_cpp_headers () # Force stable ABI for shared libraries
215177 rmdir (self , os .path .join (self .package_folder , "lib" , "cmake" ))
216178 rmdir (self , os .path .join (self .package_folder , "lib" , "pkgconfig" ))
217179
218180 def package_info (self ):
219181 cmake_target = "rocksdb-shared" if self .options .shared else "rocksdb"
220182 self .cpp_info .set_property ("cmake_file_name" , "RocksDB" )
221183 self .cpp_info .set_property ("cmake_target_name" , f"RocksDB::{ cmake_target } " )
222- # TODO: back to global scope in conan v2 once cmake_find_package* generators removed
223- self .cpp_info .components ["librocksdb" ].libs = collect_libs (self )
184+ # INFO: Component librocksdb is legacy due cmake_find_package but may break a few users in case removed
185+ lib_suffix = "-shared" if is_msvc (self ) and self .options .shared else ""
186+ self .cpp_info .components ["librocksdb" ].libs = [f"rocksdb{ lib_suffix } " ]
224187 if self .settings .os == "Windows" :
225188 self .cpp_info .components ["librocksdb" ].system_libs = ["shlwapi" , "rpcrt4" ]
226189 if self .options .shared :
227190 self .cpp_info .components ["librocksdb" ].defines = ["ROCKSDB_DLL" ]
228191 elif self .settings .os in ["Linux" , "FreeBSD" ]:
229192 self .cpp_info .components ["librocksdb" ].system_libs = ["pthread" , "m" ]
230- if self .options .get_safe ("lite" ):
231- self .cpp_info .components ["librocksdb" ].defines .append ("ROCKSDB_LITE" )
232-
233- self .cpp_info .components ["librocksdb" ].set_property ("cmake_target_name" , f"RocksDB::{ cmake_target } " )
234193 if self .options .with_gflags :
235194 self .cpp_info .components ["librocksdb" ].requires .append ("gflags::gflags" )
236195 if self .options .with_snappy :
@@ -245,5 +204,5 @@ def package_info(self):
245204 self .cpp_info .components ["librocksdb" ].requires .append ("onetbb::onetbb" )
246205 if self .options .with_jemalloc :
247206 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" )
207+ if self .options .with_folly :
208+ self .cpp_info .components ["librocksdb" ].requires .append ("folly::folly" )
0 commit comments