diff --git a/Cargo.toml b/Cargo.toml index bf0a5b8..82de47a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "rocksdb" -description = "Rust wrapper for Facebook's RocksDB embeddable database" +name = "ng-rocksdb" +description = "Rust wrapper for Facebook's RocksDB embeddable database, fork for Nextgraph.org" version = "0.21.0" edition = "2018" rust-version = "1.60" @@ -16,28 +16,32 @@ exclude = [ "deploy.sh", "test/**/*", ] - -[workspace] -members = ["librocksdb-sys"] +links = "rocksdb" +build = "librocksdb-sys/build.rs" [features] -default = [] -jemalloc = ["librocksdb-sys/jemalloc"] -io-uring = ["librocksdb-sys/io-uring"] +default = ["static"] +jemalloc = ["tikv-jemalloc-sys"] +static = ["libz-sys?/static", "bzip2-sys?/static"] +io-uring = [] +snappy = [] +lz4 = ["lz4-sys"] +zstd = ["zstd-sys"] +zlib = ["libz-sys"] +bzip2 = ["bzip2-sys"] +rtti = [] valgrind = [] -snappy = ["librocksdb-sys/snappy"] -lz4 = ["librocksdb-sys/lz4"] -zstd = ["librocksdb-sys/zstd"] -zlib = ["librocksdb-sys/zlib"] -bzip2 = ["librocksdb-sys/bzip2"] -rtti = ["librocksdb-sys/rtti"] multi-threaded-cf = [] serde1 = ["serde"] [dependencies] libc = "0.2" -librocksdb-sys = { path = "librocksdb-sys", version = "0.11.0" } serde = { version = "1", features = [ "derive" ], optional = true } +tikv-jemalloc-sys = { version = "0.5", features = ["unprefixed_malloc_on_supported_platforms"], optional = true } +lz4-sys = { version = "1.9", optional = true } +zstd-sys = { version = "2.0", features = ["zdict_builder"], optional = true } +libz-sys = { version = "1.1", default-features = false, optional = true } +bzip2-sys = { version = "0.1", default-features = false, optional = true } [dev-dependencies] trybuild = "1.0" @@ -45,3 +49,15 @@ tempfile = "3.1" pretty_assertions = "1.0" bincode = "1.3" serde = { version = "1", features = [ "derive" ] } +const-cstr = "0.3" +uuid = { version = "1.0", features = ["v4"] } + +[target.'cfg(not(any(target_os = "linux",target_os = "darwin",target_os = "openbsd")))'.dependencies.openssl] +version = "0.10" +features = ["vendored"] + +[build-dependencies] +cc = { version = "1.0", features = ["parallel"] } +bindgen = { version = "0.65", default-features = false, features = ["runtime"] } +glob = "0.3" +pkg-config = { version = "0.3" } \ No newline at end of file diff --git a/README.md b/README.md index 6ad1837..0477e52 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,6 @@ -# rust-rocksdb +# ng-rocksdb -![RocksDB build](https://github.com/rust-rocksdb/rust-rocksdb/workflows/RocksDB%20build/badge.svg?branch=master) -[![crates.io](https://img.shields.io/crates/v/rocksdb.svg)](https://crates.io/crates/rocksdb) -[![documentation](https://docs.rs/rocksdb/badge.svg)](https://docs.rs/rocksdb) -[![license](https://img.shields.io/crates/l/rocksdb.svg)](https://github.com/rust-rocksdb/rust-rocksdb/blob/master/LICENSE) -[![Gitter chat](https://badges.gitter.im/rust-rocksdb/gitter.png)](https://gitter.im/rust-rocksdb/lobby) -![rust 1.60.0 required](https://img.shields.io/badge/rust-1.60.0-blue.svg?label=MSRV) - -![GitHub commits (since latest release)](https://img.shields.io/github/commits-since/rust-rocksdb/rust-rocksdb/latest.svg) +This is a fork of https://github.com/rust-rocksdb/rust-rocksdb that also includes a subtree of a fork of https://github.com/facebook/rocksdb for the needs of NextGraph.org project. ## Requirements @@ -45,12 +38,6 @@ algorithms is not needed, default features can be disabled and specific compression algorithms can be enabled. For example, to enable only LZ4 compression support, make these changes to your Cargo.toml: -``` -[dependencies.rocksdb] -default-features = false -features = ["lz4"] -``` - ## Multithreaded ColumnFamily alternation The underlying RocksDB does allow column families to be created and dropped diff --git a/librocksdb-sys/build.rs b/librocksdb-sys/build.rs index 77541b9..6825140 100644 --- a/librocksdb-sys/build.rs +++ b/librocksdb-sys/build.rs @@ -27,14 +27,14 @@ fn fail_on_empty_directory(name: &str) { fn rocksdb_include_dir() -> String { match env::var("ROCKSDB_INCLUDE_DIR") { Ok(val) => val, - Err(_) => "rocksdb/include".to_string(), + Err(_) => "librocksdb-sys/rocksdb/include".to_string(), } } fn bindgen_rocksdb() { let bindings = bindgen::Builder::default() .header(rocksdb_include_dir() + "/rocksdb/c.h") - .header("api/c.h") + .header("librocksdb-sys/api/c.h") .derive_debug(false) .blocklist_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550 .ctypes_prefix("libc") @@ -55,9 +55,9 @@ fn build_rocksdb() { let target = env::var("TARGET").unwrap(); let mut config = cc::Build::new(); - config.include("rocksdb/include/"); - config.include("rocksdb/"); - config.include("rocksdb/third-party/gtest-1.8.1/fused-src/"); + config.include("librocksdb-sys/rocksdb/include/"); + config.include("librocksdb-sys/rocksdb/"); + config.include("librocksdb-sys/rocksdb/third-party/gtest-1.8.1/fused-src/"); if cfg!(feature = "snappy") { config.define("SNAPPY", Some("1")); @@ -68,7 +68,7 @@ fn build_rocksdb() { if cfg!(feature = "lz4") { config.define("LZ4", Some("1")); - config.include("lz4/"); + config.include("librocksdb-sys/lz4/"); } if cfg!(feature = "zstd") { @@ -96,7 +96,7 @@ fn build_rocksdb() { config.define("USE_RTTI", Some("1")); } - config.include("."); + config.include("librocksdb-sys"); config.define("NDEBUG", Some("1")); let mut lib_sources = include_str!("rocksdb_lib_sources.txt") @@ -152,7 +152,7 @@ fn build_rocksdb() { if target.contains("darwin") || (target.contains("linux") && !target.contains("android")) { // on macos and linux we use the IPPCP plugin of rocksdb for the crypto (the lib is precompiled) - config.include("rocksdb/plugin/ippcp/library/include"); + config.include("librocksdb-sys/rocksdb/plugin/ippcp/library/include"); lib_sources.push("plugin/ippcp/ippcp_provider.cc"); let dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let prebuild_lib = if target.contains("darwin") { @@ -163,7 +163,9 @@ fn build_rocksdb() { println!( "cargo:rustc-link-search=native={}", Path::new(&dir) - .join(format!("rocksdb/plugin/ippcp/library/{prebuild_lib}/lib")) + .join(format!( + "librocksdb-sys/rocksdb/plugin/ippcp/library/{prebuild_lib}/lib" + )) .display() ); println!("cargo:rustc-link-lib=static=ippcp"); @@ -171,7 +173,7 @@ fn build_rocksdb() { if let Some(include) = std::env::var_os("DEP_OPENSSL_INCLUDE") { config.include(include); } else { - config.include("rocksdb/plugin/openssl/include"); + config.include("librocksdb-sys/rocksdb/plugin/openssl/include"); } lib_sources.push("plugin/openssl/openssl_provider.cc"); // let dir = env::var("CARGO_MANIFEST_DIR").unwrap(); @@ -255,7 +257,7 @@ fn build_rocksdb() { config.define("HAVE_UINT128_EXTENSION", None); config.define("DHAVE_ALIGNED_NEW", None); config.define("_REENTRANT", None); - config.include("rocksdb/plugin/openssl/include"); + config.include("librocksdb-sys/rocksdb/plugin/openssl/include"); lib_sources.push("plugin/openssl/openssl_provider.cc"); } else if target.contains("windows") { link("rpcrt4", false); @@ -362,11 +364,11 @@ fn build_rocksdb() { } for file in lib_sources { - config.file(format!("rocksdb/{file}")); + config.file(format!("librocksdb-sys/rocksdb/{file}")); } - config.file("build_version.cc"); - config.file("api/c.cc"); + config.file("librocksdb-sys/build_version.cc"); + config.file("librocksdb-sys/api/c.cc"); config.cpp(true); config.flag_if_supported("-std=c++17"); @@ -457,7 +459,7 @@ fn update_submodules() { } fn main() { - if !Path::new("rocksdb/AUTHORS").exists() { + if !Path::new("librocksdb-sys/rocksdb/AUTHORS").exists() { update_submodules(); } let target = env::var("TARGET").unwrap(); @@ -470,8 +472,8 @@ fn main() { bindgen_rocksdb(); if !try_to_find_and_link_lib("ROCKSDB") { - println!("cargo:rerun-if-changed=rocksdb/"); - fail_on_empty_directory("rocksdb"); + println!("cargo:rerun-if-changed=librocksdb-sys/rocksdb/"); + fail_on_empty_directory("librocksdb-sys/rocksdb"); build_rocksdb(); } else { let target = env::var("TARGET").unwrap(); diff --git a/src/lib.rs b/src/lib.rs index fa367a7..ffcf774 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,6 +133,8 @@ pub use crate::{ write_batch::{WriteBatch, WriteBatchIterator, WriteBatchWithTransaction}, }; +pub mod librocksdb_sys; + pub use librocksdb_sys as ffi; use std::error; diff --git a/src/librocksdb_sys.rs b/src/librocksdb_sys.rs new file mode 100644 index 0000000..701c88d --- /dev/null +++ b/src/librocksdb_sys.rs @@ -0,0 +1,33 @@ +// Copyright 2020 Tyler Neely, Alex Regueiro +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![allow(clippy::all)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(deref_nullptr)] + +// Ensure the libraries are linked in, despite it not being used directly +#[cfg(feature = "bzip2")] +extern crate bzip2_sys; +#[cfg(feature = "zlib")] +extern crate libz_sys; +#[cfg(feature = "lz4")] +extern crate lz4_sys; +#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "openbsd")))] +extern crate openssl; +#[cfg(feature = "zstd")] +extern crate zstd_sys; + +include!(concat!(env!("OUT_DIR"), "/bindings.rs"));