From 2158f5aadde3b0f961f001a71815243c5df2c534 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 8 Jun 2021 05:41:27 +0800 Subject: [PATCH] *: introduce static features (#78) static features will require building static library from source. Signed-off-by: Jay Lee --- Cargo.toml | 2 ++ bzip2-sys/Cargo.toml | 4 ++++ bzip2-sys/build.rs | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 21f0c3f2..38f81bfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,5 @@ tokio-core = "0.1" [features] tokio = ["tokio-io", "futures"] +# Enable this feature if you want to have a statically linked bzip2 +static = ["bzip2-sys/static"] diff --git a/bzip2-sys/Cargo.toml b/bzip2-sys/Cargo.toml index f82edc09..34e88c75 100644 --- a/bzip2-sys/Cargo.toml +++ b/bzip2-sys/Cargo.toml @@ -24,3 +24,7 @@ libc = "0.2" [build-dependencies] pkg-config = "0.3.9" cc = "1.0" + +[features] +# Enable this feature if you want to have a statically linked bzip2 +static = [] diff --git a/bzip2-sys/build.rs b/bzip2-sys/build.rs index adea7a1d..feb004ca 100644 --- a/bzip2-sys/build.rs +++ b/bzip2-sys/build.rs @@ -12,7 +12,8 @@ fn main() { if target.contains("windows") { cfg.define("_WIN32", None); cfg.define("BZ_EXPORT", None); - } else { + } else if !cfg!(feature = "static") { + // pkg-config doesn't guarantee static link if pkg_config::Config::new() .cargo_metadata(true) .probe("bzip2")