Skip to content

Commit 22e359a

Browse files
authored
add environment variable to force usage of pkg-config (#175)
* add environment variable to force usage of pkg-config * add pkg-config feature * don't print rerun cargo instruction with non-cargo feature
1 parent 55cb654 commit 22e359a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

zstd-safe/zstd-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ default-features = false
5454
features = ["runtime", "which-rustfmt"]
5555

5656
[build-dependencies.pkg-config]
57-
optional = true
5857
version = "0.3"
5958

6059
[build-dependencies.cc]
@@ -71,6 +70,7 @@ debug = [] # Enable zstd debug logs
7170
experimental = [] # Expose experimental ZSTD API
7271
legacy = [] # Enable legacy ZSTD support (for versions < zstd-0.8)
7372
non-cargo = [] # Silence cargo-specific build flags
73+
pkg-config = []
7474
std = [] # Use std types instead of libc in bindgen
7575
zstdmt = [] # Enable multi-thread support (with pthread)
7676
thin = [] # Optimize binary by size

zstd-safe/zstd-sys/build.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ fn generate_bindings(defs: Vec<&str>, headerpaths: Vec<PathBuf>) {
3838
#[cfg(not(feature = "bindgen"))]
3939
fn generate_bindings(_: Vec<&str>, _: Vec<PathBuf>) {}
4040

41-
#[cfg(feature = "pkg-config")]
4241
fn pkg_config() -> (Vec<&'static str>, Vec<PathBuf>) {
4342
let library = pkg_config::Config::new()
4443
.statik(true)
@@ -48,11 +47,6 @@ fn pkg_config() -> (Vec<&'static str>, Vec<PathBuf>) {
4847
(vec!["PKG_CONFIG"], library.include_paths)
4948
}
5049

51-
#[cfg(not(feature = "pkg-config"))]
52-
fn pkg_config() -> (Vec<&'static str>, Vec<PathBuf>) {
53-
unimplemented!()
54-
}
55-
5650
#[cfg(not(feature = "legacy"))]
5751
fn set_legacy(_config: &mut cc::Build) {}
5852

@@ -217,6 +211,9 @@ fn compile_zstd() {
217211
}
218212

219213
fn main() {
214+
#[cfg(not(feature = "non-cargo"))]
215+
println!("cargo:rerun-if-env-changed=ZSTD_SYS_USE_PKG_CONFIG");
216+
220217
let target_arch =
221218
std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
222219
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
@@ -226,7 +223,9 @@ fn main() {
226223
}
227224

228225
// println!("cargo:rustc-link-lib=zstd");
229-
let (defs, headerpaths) = if cfg!(feature = "pkg-config") {
226+
let (defs, headerpaths) = if cfg!(feature = "pkg-config")
227+
|| env::var_os("ZSTD_SYS_USE_PKG_CONFIG").is_some()
228+
{
230229
pkg_config()
231230
} else {
232231
if !Path::new("zstd/lib").exists() {

0 commit comments

Comments
 (0)