From e897ccdfe226c305a4fdeab1fbc69df046006935 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Wed, 15 Nov 2023 11:23:12 -0500 Subject: [PATCH 1/4] Use the system liblz4 if found via pkg-config Compare to: https://github.com/alexcrichton/bzip2-rs/pull/58/files --- lz4-sys/Cargo.toml | 1 + lz4-sys/build.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lz4-sys/Cargo.toml b/lz4-sys/Cargo.toml index 72fdff265..dd1d13aca 100644 --- a/lz4-sys/Cargo.toml +++ b/lz4-sys/Cargo.toml @@ -13,3 +13,4 @@ libc = "0.2" [build-dependencies] cc = "1.1" +pkg-config = "0.3.9" diff --git a/lz4-sys/build.rs b/lz4-sys/build.rs index 025b7083c..4cf5ea473 100644 --- a/lz4-sys/build.rs +++ b/lz4-sys/build.rs @@ -15,6 +15,17 @@ fn main() { } fn run() -> Result<(), Box> { + let target = get_from_env("TARGET")?; + + if !target.contains("windows") + && pkg_config::Config::new() + .cargo_metadata(true) + .probe("liblz4") + .is_ok() + { + return Ok(()); + } + let mut compiler = cc::Build::new(); compiler .file("liblz4/lib/lz4.c") @@ -24,7 +35,6 @@ fn run() -> Result<(), Box> { // We always compile the C with optimization, because otherwise it is 20x slower. .opt_level(3); - let target = get_from_env("TARGET")?; if target.contains("windows") { if target == "i686-pc-windows-gnu" { // Disable auto-vectorization for 32-bit MinGW target. From 016f73dd4b86b4d1cb07ba6b073e70e29955e8b8 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Wed, 15 Nov 2023 11:25:24 -0500 Subject: [PATCH 2/4] Introduce static features Compare to: https://github.com/alexcrichton/bzip2-rs/pull/78 --- Cargo.toml | 4 ++++ lz4-sys/Cargo.toml | 4 ++++ lz4-sys/build.rs | 1 + 3 files changed, 9 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 5eae413fa..3b681ca3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,7 @@ lz4-sys = { path = "lz4-sys", version = "1.11.0" } [dev-dependencies] rand = ">=0.7, <=0.8" + +[features] +# Enable this feature if you want to have a statically linked liblz4 +static = ["lz4-sys/static"] diff --git a/lz4-sys/Cargo.toml b/lz4-sys/Cargo.toml index dd1d13aca..4b233ddb5 100644 --- a/lz4-sys/Cargo.toml +++ b/lz4-sys/Cargo.toml @@ -14,3 +14,7 @@ libc = "0.2" [build-dependencies] cc = "1.1" pkg-config = "0.3.9" + +[features] +# Enable this feature if you want to have a statically linked liblz4 +static = [] diff --git a/lz4-sys/build.rs b/lz4-sys/build.rs index 4cf5ea473..30af11e60 100644 --- a/lz4-sys/build.rs +++ b/lz4-sys/build.rs @@ -18,6 +18,7 @@ fn run() -> Result<(), Box> { let target = get_from_env("TARGET")?; if !target.contains("windows") + && !cfg!(feature = "static") && pkg_config::Config::new() .cargo_metadata(true) .probe("liblz4") From 028457329fbad53904c9cd6b5e105083415481f2 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Wed, 29 Nov 2023 09:50:16 -0500 Subject: [PATCH 3/4] Ask pkg_config not to print system libs Suggested in Fedora Linux package review: https://bugzilla.redhat.com/show_bug.cgi?id=2249863#c2 --- lz4-sys/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lz4-sys/build.rs b/lz4-sys/build.rs index 30af11e60..c8e68b3e4 100644 --- a/lz4-sys/build.rs +++ b/lz4-sys/build.rs @@ -20,6 +20,7 @@ fn run() -> Result<(), Box> { if !target.contains("windows") && !cfg!(feature = "static") && pkg_config::Config::new() + .print_system_libs(false) .cargo_metadata(true) .probe("liblz4") .is_ok() From 766997247c8ce9602a940bc44ad422fbe461f270 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Wed, 29 Nov 2023 09:51:55 -0500 Subject: [PATCH 4/4] Revert "Introduce static features" This reverts commit c9b6db548b4b3d5acf80f99c940e2831c50b24a1. Suggested in Fedora Linux package review: https://bugzilla.redhat.com/show_bug.cgi?id=2249863#c4 --- Cargo.toml | 4 ---- lz4-sys/Cargo.toml | 4 ---- lz4-sys/build.rs | 1 - 3 files changed, 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b681ca3c..5eae413fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,3 @@ lz4-sys = { path = "lz4-sys", version = "1.11.0" } [dev-dependencies] rand = ">=0.7, <=0.8" - -[features] -# Enable this feature if you want to have a statically linked liblz4 -static = ["lz4-sys/static"] diff --git a/lz4-sys/Cargo.toml b/lz4-sys/Cargo.toml index 4b233ddb5..dd1d13aca 100644 --- a/lz4-sys/Cargo.toml +++ b/lz4-sys/Cargo.toml @@ -14,7 +14,3 @@ libc = "0.2" [build-dependencies] cc = "1.1" pkg-config = "0.3.9" - -[features] -# Enable this feature if you want to have a statically linked liblz4 -static = [] diff --git a/lz4-sys/build.rs b/lz4-sys/build.rs index c8e68b3e4..885b6311c 100644 --- a/lz4-sys/build.rs +++ b/lz4-sys/build.rs @@ -18,7 +18,6 @@ fn run() -> Result<(), Box> { let target = get_from_env("TARGET")?; if !target.contains("windows") - && !cfg!(feature = "static") && pkg_config::Config::new() .print_system_libs(false) .cargo_metadata(true)