|
|
|
@ -1,45 +1,42 @@
|
|
|
|
|
From d68956f4ce606077a716b7fba3148d8986dd6165 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From dfbd6b8c91aa8f35eef5afa6593b8ef06ce2bfe1 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Fabio Valentini <decathorpe@gmail.com>
|
|
|
|
|
Date: Sat, 6 Aug 2022 18:54:46 +0200
|
|
|
|
|
Date: Thu, 23 Feb 2023 18:50:32 +0100
|
|
|
|
|
Subject: [PATCH] unconditionally use bindgen and pkg-config to link against
|
|
|
|
|
system libzstd
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
build.rs | 170 +------------------------------------------------------
|
|
|
|
|
1 file changed, 1 insertion(+), 169 deletions(-)
|
|
|
|
|
build.rs | 218 +------------------------------------------------------
|
|
|
|
|
1 file changed, 3 insertions(+), 215 deletions(-)
|
|
|
|
|
|
|
|
|
|
diff --git a/build.rs b/build.rs
|
|
|
|
|
index 83f2dc2..2336d61 100644
|
|
|
|
|
index 04fb94f..44f36b0 100644
|
|
|
|
|
--- a/build.rs
|
|
|
|
|
+++ b/build.rs
|
|
|
|
|
@@ -2,7 +2,6 @@ use std::ffi::OsStr;
|
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
use std::{env, fs};
|
|
|
|
|
@@ -1,8 +1,6 @@
|
|
|
|
|
-use std::ffi::OsStr;
|
|
|
|
|
-use std::path::{Path, PathBuf};
|
|
|
|
|
-use std::{env, fmt, fs};
|
|
|
|
|
+use std::path::PathBuf;
|
|
|
|
|
+use std::{env, fmt};
|
|
|
|
|
|
|
|
|
|
-#[cfg(feature = "bindgen")]
|
|
|
|
|
fn generate_bindings(defs: Vec<&str>, headerpaths: Vec<PathBuf>) {
|
|
|
|
|
let bindings = bindgen::Builder::default()
|
|
|
|
|
.header("zstd.h");
|
|
|
|
|
@@ -36,10 +35,6 @@ fn generate_bindings(defs: Vec<&str>, headerpaths: Vec<PathBuf>) {
|
|
|
|
|
let bindings = bindgen::Builder::default().header("zstd.h");
|
|
|
|
|
#[cfg(feature = "zdict_builder")]
|
|
|
|
|
@@ -35,9 +33,6 @@ fn generate_bindings(defs: Vec<&str>, headerpaths: Vec<PathBuf>) {
|
|
|
|
|
.expect("Could not write bindings");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-#[cfg(not(feature = "bindgen"))]
|
|
|
|
|
-fn generate_bindings(_: Vec<&str>, _: Vec<PathBuf>) {}
|
|
|
|
|
-
|
|
|
|
|
-#[cfg(feature = "pkg-config")]
|
|
|
|
|
fn pkg_config() -> (Vec<&'static str>, Vec<PathBuf>) {
|
|
|
|
|
let library = pkg_config::Config::new()
|
|
|
|
|
.statik(true)
|
|
|
|
|
@@ -49,171 +44,8 @@ fn pkg_config() -> (Vec<&'static str>, Vec<PathBuf>) {
|
|
|
|
|
@@ -47,189 +42,6 @@ fn pkg_config() -> (Vec<&'static str>, Vec<PathBuf>) {
|
|
|
|
|
(vec!["PKG_CONFIG"], library.include_paths)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-#[cfg(not(feature = "pkg-config"))]
|
|
|
|
|
-fn pkg_config() -> (Vec<&'static str>, Vec<PathBuf>) {
|
|
|
|
|
- unimplemented!()
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-#[cfg(not(feature = "legacy"))]
|
|
|
|
|
-fn set_legacy(_config: &mut cc::Build) {}
|
|
|
|
|
-
|
|
|
|
@ -65,6 +62,19 @@ index 83f2dc2..2336d61 100644
|
|
|
|
|
-#[cfg(not(feature = "zstdmt"))]
|
|
|
|
|
-fn enable_threading(_config: &mut cc::Build) {}
|
|
|
|
|
-
|
|
|
|
|
-/// This function would find the first flag in `flags` that is supported
|
|
|
|
|
-/// and add that to `config`.
|
|
|
|
|
-#[allow(dead_code)]
|
|
|
|
|
-fn flag_if_supported_with_fallbacks(config: &mut cc::Build, flags: &[&str]) {
|
|
|
|
|
- let option = flags
|
|
|
|
|
- .iter()
|
|
|
|
|
- .find(|flag| config.is_flag_supported(flag).unwrap_or_default());
|
|
|
|
|
-
|
|
|
|
|
- if let Some(flag) = option {
|
|
|
|
|
- config.flag(flag);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-fn compile_zstd() {
|
|
|
|
|
- let mut config = cc::Build::new();
|
|
|
|
|
-
|
|
|
|
@ -78,56 +88,91 @@ index 83f2dc2..2336d61 100644
|
|
|
|
|
- #[cfg(feature = "legacy")]
|
|
|
|
|
- "zstd/lib/legacy",
|
|
|
|
|
- ] {
|
|
|
|
|
- for entry in fs::read_dir(dir).unwrap() {
|
|
|
|
|
- let path = entry.unwrap().path();
|
|
|
|
|
- // Skip xxhash*.c files: since we are using the "PRIVATE API"
|
|
|
|
|
- // mode, it will be inlined in the headers.
|
|
|
|
|
- if path
|
|
|
|
|
- .file_name()
|
|
|
|
|
- .and_then(|p| p.to_str())
|
|
|
|
|
- .map_or(false, |p| p.contains("xxhash"))
|
|
|
|
|
- {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- if path.extension() == Some(OsStr::new("c")) {
|
|
|
|
|
- config.file(path);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- let mut entries: Vec<_> = fs::read_dir(dir)
|
|
|
|
|
- .unwrap()
|
|
|
|
|
- .map(Result::unwrap)
|
|
|
|
|
- .filter_map(|entry| {
|
|
|
|
|
- let filename = entry.file_name();
|
|
|
|
|
-
|
|
|
|
|
- if Path::new(&filename).extension() == Some(OsStr::new("c"))
|
|
|
|
|
- // Skip xxhash*.c files: since we are using the "PRIVATE API"
|
|
|
|
|
- // mode, it will be inlined in the headers.
|
|
|
|
|
- && !filename.to_string_lossy().contains("xxhash")
|
|
|
|
|
- {
|
|
|
|
|
- Some(entry.path())
|
|
|
|
|
- } else {
|
|
|
|
|
- None
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .collect();
|
|
|
|
|
- entries.sort();
|
|
|
|
|
-
|
|
|
|
|
- config.files(entries);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Either include ASM files, or disable ASM entirely.
|
|
|
|
|
- // Also disable it on windows, apparently it doesn't do well with these .S files at the moment.
|
|
|
|
|
- if cfg!(any(target_os = "windows", feature = "no_asm")) {
|
|
|
|
|
- if cfg!(feature = "no_asm") || std::env::var("CARGO_CFG_WINDOWS").is_ok() {
|
|
|
|
|
- config.define("ZSTD_DISABLE_ASM", Some(""));
|
|
|
|
|
- } else {
|
|
|
|
|
- config.file("zstd/lib/decompress/huf_decompress_amd64.S");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let is_wasm_unknown_unknown = env::var("TARGET").ok() == Some("wasm32-unknown-unknown".into());
|
|
|
|
|
- let is_wasm = env::var("TARGET")
|
|
|
|
|
- .map_or(false, |target| target.starts_with("wasm32-"));
|
|
|
|
|
-
|
|
|
|
|
- if is_wasm_unknown_unknown {
|
|
|
|
|
- println!("cargo:rerun-if-changed=wasm-shim/stdlib.h");
|
|
|
|
|
- println!("cargo:rerun-if-changed=wasm-shim/string.h");
|
|
|
|
|
- if is_wasm {
|
|
|
|
|
- cargo_print(&"rerun-if-changed=wasm-shim/stdlib.h");
|
|
|
|
|
- cargo_print(&"rerun-if-changed=wasm-shim/string.h");
|
|
|
|
|
-
|
|
|
|
|
- config.include("wasm-shim/");
|
|
|
|
|
- config.define("XXH_STATIC_ASSERT", Some("0"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Some extra parameters
|
|
|
|
|
- config.opt_level(3);
|
|
|
|
|
- config.include("zstd/lib/");
|
|
|
|
|
- config.include("zstd/lib/common");
|
|
|
|
|
- config.warnings(false);
|
|
|
|
|
-
|
|
|
|
|
- config.define("ZSTD_LIB_DEPRECATED", Some("0"));
|
|
|
|
|
-
|
|
|
|
|
- config
|
|
|
|
|
- .flag_if_supported("-ffunction-sections")
|
|
|
|
|
- .flag_if_supported("-fdata-sections")
|
|
|
|
|
- .flag_if_supported("-fmerge-all-constants");
|
|
|
|
|
-
|
|
|
|
|
- if cfg!(feature = "fat-lto") {
|
|
|
|
|
- config.flag_if_supported("-flto");
|
|
|
|
|
- } else if cfg!(feature = "thin-lto") {
|
|
|
|
|
- flag_if_supported_with_fallbacks(
|
|
|
|
|
- &mut config,
|
|
|
|
|
- &["-flto=thin", "-flto"],
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- #[cfg(feature = "thin")]
|
|
|
|
|
- {
|
|
|
|
|
- config.define("HUF_FORCE_DECOMPRESS_X1", Some("1"));
|
|
|
|
|
- config.define("ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT", Some("1"));
|
|
|
|
|
- config.define("ZSTD_NO_INLINE ", Some("1"));
|
|
|
|
|
- config.flag_if_supported("-flto=thin");
|
|
|
|
|
- config.flag_if_supported("-Oz");
|
|
|
|
|
- // Here we try to build a lib as thin/small as possible.
|
|
|
|
|
- // We cannot use ZSTD_LIB_MINIFY since it is only
|
|
|
|
|
- // used in Makefile to define other options.
|
|
|
|
|
-
|
|
|
|
|
- config
|
|
|
|
|
- .define("HUF_FORCE_DECOMPRESS_X1", Some("1"))
|
|
|
|
|
- .define("ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT", Some("1"))
|
|
|
|
|
- .define("ZSTD_NO_INLINE", Some("1"))
|
|
|
|
|
- // removes the error messages that are
|
|
|
|
|
- // otherwise returned by ZSTD_getErrorName
|
|
|
|
|
- .define("ZSTD_STRIP_ERROR_STRINGS", Some("1"));
|
|
|
|
|
-
|
|
|
|
|
- // Disable use of BMI2 instructions since it involves runtime checking
|
|
|
|
|
- // of the feature and fallback if no BMI2 instruction is detected.
|
|
|
|
|
- config.define("DYNAMIC_BMI2", Some("0"));
|
|
|
|
|
-
|
|
|
|
|
- // Disable support for all legacy formats
|
|
|
|
|
- #[cfg(not(feature = "legacy"))]
|
|
|
|
|
- config.define("ZSTD_LEGACY_SUPPORT", Some("0"));
|
|
|
|
|
-
|
|
|
|
|
- config.opt_level_str("z");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Hide symbols from resulting library,
|
|
|
|
@ -152,7 +197,7 @@ index 83f2dc2..2336d61 100644
|
|
|
|
|
- * 7+: events at every position (*very* verbose)
|
|
|
|
|
- */
|
|
|
|
|
- #[cfg(feature = "debug")]
|
|
|
|
|
- if !is_wasm_unknown_unknown {
|
|
|
|
|
- if !is_wasm {
|
|
|
|
|
- config.define("DEBUGLEVEL", Some("5"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
@ -172,20 +217,28 @@ index 83f2dc2..2336d61 100644
|
|
|
|
|
- .unwrap();
|
|
|
|
|
- #[cfg(feature = "zdict_builder")]
|
|
|
|
|
- fs::copy(src.join("zdict.h"), include.join("zdict.h")).unwrap();
|
|
|
|
|
- println!("cargo:root={}", dst.display());
|
|
|
|
|
- cargo_print(&format_args!("root={}", dst.display()));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/// Print a line for cargo.
|
|
|
|
|
///
|
|
|
|
|
/// If non-cargo is set, do not print anything.
|
|
|
|
|
@@ -242,32 +54,8 @@ fn cargo_print(content: &dyn fmt::Display) {
|
|
|
|
|
fn main() {
|
|
|
|
|
cargo_print(&"rerun-if-env-changed=ZSTD_SYS_USE_PKG_CONFIG");
|
|
|
|
|
|
|
|
|
|
- let target_arch =
|
|
|
|
|
- std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
|
|
|
|
|
- let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
|
|
|
|
-
|
|
|
|
|
- if target_arch == "wasm32" || target_os == "hermit" {
|
|
|
|
|
- println!("cargo:rustc-cfg=feature=\"std\"");
|
|
|
|
|
- cargo_print(&"rustc-cfg=feature=\"std\"");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // println!("cargo:rustc-link-lib=zstd");
|
|
|
|
|
- let (defs, headerpaths) = if cfg!(feature = "pkg-config") {
|
|
|
|
|
// println!("cargo:rustc-link-lib=zstd");
|
|
|
|
|
- let (defs, headerpaths) = if cfg!(feature = "pkg-config")
|
|
|
|
|
- || env::var_os("ZSTD_SYS_USE_PKG_CONFIG").is_some()
|
|
|
|
|
- {
|
|
|
|
|
- pkg_config()
|
|
|
|
|
- } else {
|
|
|
|
|
- if !Path::new("zstd/lib").exists() {
|
|
|
|
@ -193,7 +246,7 @@ index 83f2dc2..2336d61 100644
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let manifest_dir = PathBuf::from(
|
|
|
|
|
- env::var("CARGO_MANIFEST_DIR")
|
|
|
|
|
- env::var_os("CARGO_MANIFEST_DIR")
|
|
|
|
|
- .expect("Manifest dir is always set by cargo"),
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
@ -205,5 +258,5 @@ index 83f2dc2..2336d61 100644
|
|
|
|
|
let includes: Vec<_> = headerpaths
|
|
|
|
|
.iter()
|
|
|
|
|
--
|
|
|
|
|
2.37.1
|
|
|
|
|
2.39.2
|
|
|
|
|
|
|
|
|
|