From 16a49d97060ca346de95d32037079d4429bc788a Mon Sep 17 00:00:00 2001 From: Jordan Terrell Date: Mon, 22 Oct 2018 20:12:52 -0500 Subject: [PATCH] Compression algorthms are now enabled by crate features... --- Cargo.toml | 8 ++++++- README.md | 11 ++++++++- librocksdb-sys/Cargo.toml | 6 +++++ librocksdb-sys/build.rs | 49 +++++++++++++++++++++++++-------------- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e05c54c..3c01c5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,14 @@ exclude = [ ] [features] -default = [] +default = ["snappy", "lz4", "zstd", "zlib", "bzip2"] valgrind = [] +snappy = ["librocksdb-sys/snappy"] +lz4 = ["librocksdb-sys/lz4"] +zstd = ["librocksdb-sys/zstd"] +zlib = ["librocksdb-sys/zlib"] +bzip2 = ["librocksdb-sys/bzip2"] + [dependencies] libc = "0.2" diff --git a/README.md b/README.md index 53e0d98..260c04c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,15 @@ rust-rocksdb Feedback and pull requests welcome! If a particular feature of RocksDB is important to you, please let me know by opening an issue, and I'll prioritize it. -This binding is statically linked with a specific version of RocksDB. If you want to build it yourself, make sure you've also cloned the RocksDB and Snappy submodules: +This binding is statically linked with a specific version of RocksDB. If you want to build it yourself, make sure you've also cloned the RocksDB and compression submodules: git submodule update --init --recursive + +## Compression Support +By default, support for the [Snappy](https://github.com/google/snappy), [LZ4](https://github.com/lz4/lz4), [Zstd](https://github.com/facebook/zstd), [Zlib](https://zlib.net), and [Bzip2](http://www.bzip.org) compression is enabled through crate features. If support for all of these compression 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"] +``` diff --git a/librocksdb-sys/Cargo.toml b/librocksdb-sys/Cargo.toml index a449ef2..5f27993 100644 --- a/librocksdb-sys/Cargo.toml +++ b/librocksdb-sys/Cargo.toml @@ -14,6 +14,12 @@ links = "rocksdb" [features] default = [ "static" ] static = [] +snappy = [] +lz4 = [] +zstd = [] +zlib = [] +bzip2 = [] + [dependencies] libc = "0.2" diff --git a/librocksdb-sys/build.rs b/librocksdb-sys/build.rs index cf9d7e3..c8f295a 100644 --- a/librocksdb-sys/build.rs +++ b/librocksdb-sys/build.rs @@ -49,20 +49,35 @@ fn build_rocksdb() { config.include("rocksdb/include/"); config.include("rocksdb/"); config.include("rocksdb/third-party/gtest-1.7.0/fused-src/"); - config.include("snappy/"); - config.include("lz4/lib/"); - config.include("zstd/lib/"); - config.include("zstd/lib/dictBuilder/"); - config.include("zlib/"); - config.include("bzip2/"); - config.include("."); + + if cfg!(feature = "snappy") { + config.define("SNAPPY", Some("1")); + config.include("snappy/"); + } + if cfg!(feature = "lz4") { + config.define("LZ4", Some("1")); + config.include("lz4/lib/"); + } + + if cfg!(feature = "zstd") { + config.define("ZSTD", Some("1")); + config.include("zstd/lib/"); + config.include("zstd/lib/dictBuilder/"); + } + + if cfg!(feature = "zlib") { + config.define("ZLIB", Some("1")); + config.include("zlib/"); + } + + if cfg!(feature = "bzip2") { + config.define("BZIP2", Some("1")); + config.include("bzip2/"); + } + + config.include("."); config.define("NDEBUG", Some("1")); - config.define("SNAPPY", Some("1")); - config.define("LZ4", Some("1")); - config.define("ZSTD", Some("1")); - config.define("ZLIB", Some("1")); - config.define("BZIP2", Some("1")); let mut lib_sources = include_str!("rocksdb_lib_sources.txt") .split(" ") @@ -281,19 +296,19 @@ fn main() { if !try_to_find_and_link_lib("ROCKSDB") { build_rocksdb(); } - if !try_to_find_and_link_lib("SNAPPY") { + if cfg!(feature = "snappy") && !try_to_find_and_link_lib("SNAPPY") { build_snappy(); } - if !try_to_find_and_link_lib("LZ4") { + if cfg!(feature = "lz4") && !try_to_find_and_link_lib("LZ4") { build_lz4(); } - if !try_to_find_and_link_lib("ZSTD") { + if cfg!(feature = "zstd") && !try_to_find_and_link_lib("ZSTD") { build_zstd(); } - if !try_to_find_and_link_lib("ZLIB") { + if cfg!(feature = "zlib") && !try_to_find_and_link_lib("ZLIB") { build_zlib(); } - if !try_to_find_and_link_lib("BZIP2") { + if cfg!(feature = "bzip2") && !try_to_find_and_link_lib("BZIP2") { build_bzip2(); } }