@@ -3,10 +3,14 @@ compile_error!("feature 'portable' and feature 'march-native' cannot be enabled
33
44use std:: env;
55use std:: fs;
6- use std:: path:: PathBuf ;
6+ use std:: path:: { Path , PathBuf } ;
77use std:: process:: Command ;
88
9- const RUST_TARGET : & str = "1.85.0" ;
9+ const RUST_TARGET : & str = "1.89.0" ;
10+ // On these platforms jemalloc-sys will use a prefixed jemalloc which cannot be linked together
11+ // with RocksDB.
12+ // See https://github.com/tikv/jemallocator/blob/tikv-jemalloc-sys-0.5.3/jemalloc-sys/src/env.rs#L25
13+ const NO_JEMALLOC_TARGETS : & [ & str ] = & [ "android" , "dragonfly" , "musl" , "darwin" ] ;
1014
1115fn get_flags_from_detect_platform_script ( ) -> Option < Vec < String > > {
1216 if !cfg ! ( target_os = "windows" ) {
@@ -138,6 +142,10 @@ fn build_rocksdb() {
138142 config. include ( "bzip2/" ) ;
139143 }
140144
145+ if cfg ! ( feature = "rtti" ) {
146+ config. define ( "USE_RTTI" , Some ( "1" ) ) ;
147+ }
148+
141149 // rust-rocksdb/rust-rocksdb:
142150 // https://github.com/rust-rocksdb/rust-rocksdb/commit/b2dab4a0915eed72741657f783118d9220d4f070
143151 //
@@ -147,8 +155,8 @@ fn build_rocksdb() {
147155 config. flag ( "-flto" ) ;
148156 if !config. get_compiler ( ) . is_like_clang ( ) {
149157 panic ! (
150- "LTO is only supported with clang. Either disable the `lto` feature\
151- or set `CC=/usr/bin/clang CXX=/usr/bin/clang++` environment variables."
158+ "LTO is only supported with clang. Either disable the `lto` feature \
159+ or set `CC=/usr/bin/clang CXX=/usr/bin/clang++` environment variables."
152160 ) ;
153161 }
154162 }
@@ -286,25 +294,30 @@ fn build_rocksdb() {
286294 config. flag ( "-Wno-missing-field-initializers" ) ;
287295 config. flag ( "-Wno-strict-aliasing" ) ;
288296 config. flag ( "-Wno-invalid-offsetof" ) ;
297+ }
289298
290- if cfg ! ( feature = "jemalloc" ) {
291- if let Err ( e) = pkg_config:: probe_library ( "jemalloc" ) {
292- panic ! ( "pkg_config jemalloc {}" , e) ;
293- } else {
294- config. define ( "ROCKSDB_JEMALLOC" , None ) ;
295- config. define ( "JEMALLOC_NO_DEMANGLE" , None ) ;
296- }
299+ config. define ( "ROCKSDB_SUPPORT_THREAD_LOCAL" , None ) ;
300+ if target. contains ( "linux" ) {
301+ if cfg ! ( feature = "io-uring" ) {
302+ pkg_config:: probe_library ( "liburing" )
303+ . expect ( "The io-uring feature was requested but the library is not available" ) ;
304+ config. define ( "ROCKSDB_IOURING_PRESENT" , Some ( "1" ) ) ;
297305 }
306+ }
298307
299- if cfg ! ( feature = "io-uring" ) {
300- if let Err ( e) = pkg_config:: probe_library ( "liburing" ) {
301- panic ! ( "pkg_config liburing {}" , e) ;
302- } else {
303- config. define ( "ROCKSDB_IOURING_PRESENT" , None ) ;
304- }
308+ if cfg ! ( feature = "jemalloc" ) && NO_JEMALLOC_TARGETS . iter ( ) . all ( |i| !target. contains ( i) ) {
309+ config. define ( "ROCKSDB_JEMALLOC" , Some ( "1" ) ) ;
310+ config. define ( "JEMALLOC_NO_DEMANGLE" , Some ( "1" ) ) ;
311+ if let Some ( jemalloc_root) = env:: var_os ( "DEP_JEMALLOC_ROOT" ) {
312+ config. include ( Path :: new ( & jemalloc_root) . join ( "include" ) ) ;
305313 }
306314 }
307315
316+ config. flag_if_supported ( "-std=c++17" ) ;
317+ if !target. contains ( "windows" ) {
318+ config. flag ( "-include" ) . flag ( "cstdint" ) ;
319+ }
320+
308321 for file in lib_sources {
309322 let file = "rocksdb/" . to_string ( ) + file;
310323 config. file ( & file) ;
@@ -315,8 +328,6 @@ fn build_rocksdb() {
315328
316329 config. cpp ( true ) ;
317330
318- config. flag ( "-include" ) . flag ( "cstdint" ) ;
319-
320331 config. compile ( "librocksdb.a" ) ;
321332}
322333
@@ -376,6 +387,8 @@ fn build_zstd() {
376387 compiler. include ( "zstd/lib/common" ) ;
377388 compiler. include ( "zstd/lib/legacy" ) ;
378389
390+ let target_arch = env:: var ( "CARGO_CFG_TARGET_ARCH" ) . unwrap_or_default ( ) ;
391+
379392 let globs = & [
380393 "zstd/lib/common/*.c" ,
381394 "zstd/lib/compress/*.c" ,
@@ -391,8 +404,22 @@ fn build_zstd() {
391404 }
392405 }
393406
407+ if target_arch. contains ( "x86_64" ) {
408+ if env:: var ( "CARGO_CFG_WINDOWS" ) . is_ok ( ) {
409+ compiler. define ( "ZSTD_DISABLE_ASM" , Some ( "" ) ) ;
410+ } else {
411+ compiler. file ( "zstd/lib/decompress/huf_decompress_amd64.S" ) ;
412+ }
413+ } else {
414+ compiler. define ( "ZSTD_DISABLE_ASM" , Some ( "" ) ) ;
415+ }
416+
394417 compiler. opt_level ( 3 ) ;
395418 compiler. extra_warnings ( false ) ;
419+ compiler
420+ . flag_if_supported ( "-ffunction-sections" )
421+ . flag_if_supported ( "-fdata-sections" )
422+ . flag_if_supported ( "-fmerge-all-constants" ) ;
396423
397424 compiler. define ( "ZSTD_LIB_DEPRECATED" , Some ( "0" ) ) ;
398425 compiler. compile ( "libzstd.a" ) ;
@@ -501,4 +528,6 @@ fn main() {
501528 fail_on_empty_directory ( "bzip2" ) ;
502529 build_bzip2 ( ) ;
503530 }
531+
532+ println ! ( "cargo:out_dir={}" , env:: var( "OUT_DIR" ) . unwrap( ) ) ;
504533}
0 commit comments