Skip to content

Commit

Permalink
Add zdict feature for zstd-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
quininer committed Jan 28, 2022
1 parent ea28d3d commit fe55976
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions zstd-safe/zstd-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ features = ["parallel"]
libc = "0.2.45"

[features]
default = ["legacy", "dict_builder"]
default = ["legacy", "zdict"]

debug = [] # Enable zstd debug logs
experimental = [] # Expose experimental ZSTD API
Expand All @@ -71,4 +71,4 @@ std = [] # Use std types instead of libc in bindgen
zstdmt = [] # Enable multi-thread support (with pthread)
thin = [] # Optimize binary by size
no_asm = [] # Disable ASM files (only on amd64 for decompression)
dict_builder = []
zdict = []
17 changes: 11 additions & 6 deletions zstd-safe/zstd-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use std::{env, fs};
#[cfg(feature = "bindgen")]
fn generate_bindings(defs: Vec<&str>, headerpaths: Vec<PathBuf>) {
let bindings = bindgen::Builder::default()
.header("zstd.h")
.header("zdict.h")
.header("zstd.h");
#[cfg(feature = "zdict")]
let bindings = bindings.header("zdict.h");
bindings
.blocklist_type("max_align_t")
.size_t_is_usize(true)
.use_core()
Expand All @@ -19,9 +21,10 @@ fn generate_bindings(defs: Vec<&str>, headerpaths: Vec<PathBuf>) {
.clang_args(defs.into_iter().map(|def| format!("-D{}", def)));

#[cfg(feature = "experimental")]
let bindings = bindings
.clang_arg("-DZSTD_STATIC_LINKING_ONLY")
.clang_arg("-DZDICT_STATIC_LINKING_ONLY");
let bindings = bindings.clang_arg("-DZSTD_STATIC_LINKING_ONLY");
#[cfg(feature = "experimental")]
#[cfg(feature = "zdict")]
let bindings = bindings.clang_arg("-DZDICT_STATIC_LINKING_ONLY");

#[cfg(not(feature = "std"))]
let bindings = bindings.ctypes_prefix("libc");
Expand Down Expand Up @@ -85,7 +88,7 @@ fn compile_zstd() {
"zstd/lib/common",
"zstd/lib/compress",
"zstd/lib/decompress",
#[cfg(feature = "dict_builder")]
#[cfg(feature = "zdict")]
"zstd/lib/dictBuilder",
#[cfg(feature = "legacy")]
"zstd/lib/legacy",
Expand Down Expand Up @@ -146,6 +149,7 @@ fn compile_zstd() {
config.flag("-fvisibility=hidden");
config.define("XXH_PRIVATE_API", Some(""));
config.define("ZSTDLIB_VISIBILITY", Some(""));
#[cfg(feature = "zdict")]
config.define("ZDICTLIB_VISIBILITY", Some(""));
config.define("ZSTDERRORLIB_VISIBILITY", Some(""));

Expand Down Expand Up @@ -179,6 +183,7 @@ fn compile_zstd() {
fs::copy(src.join("zstd.h"), include.join("zstd.h")).unwrap();
fs::copy(src.join("zstd_errors.h"), include.join("zstd_errors.h"))
.unwrap();
#[cfg(feature = "zdict")]
fs::copy(src.join("zdict.h"), include.join("zdict.h")).unwrap();
println!("cargo:root={}", dst.display());
}
Expand Down
4 changes: 4 additions & 0 deletions zstd-safe/zstd-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ include!("bindings_zstd.rs");
#[cfg(all(
not(feature = "std"),
not(feature = "experimental"),
feature = "zdict",
not(feature = "bindgen")
))]
include!("bindings_zdict.rs");
Expand All @@ -43,6 +44,7 @@ include!("bindings_zstd_experimental.rs");
#[cfg(all(
not(feature = "std"),
feature = "experimental",
feature = "zdict",
not(feature = "bindgen")
))]
include!("bindings_zdict_experimental.rs");
Expand All @@ -59,6 +61,7 @@ include!("bindings_zstd_std.rs");
#[cfg(all(
feature = "std",
not(feature = "experimental"),
feature = "zdict",
not(feature = "bindgen")
))]
include!("bindings_zdict_std.rs");
Expand All @@ -73,6 +76,7 @@ include!("bindings_zstd_std_experimental.rs");
#[cfg(all(
feature = "std",
feature = "experimental",
feature = "zdict",
not(feature = "bindgen")
))]
include!("bindings_zdict_std_experimental.rs");

0 comments on commit fe55976

Please sign in to comment.