Skip to content

Commit

Permalink
Use the system liblz4 if found via pkg-config
Browse files Browse the repository at this point in the history
  • Loading branch information
musicinmybrain committed Sep 13, 2024
1 parent 1030e3d commit e897ccd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lz4-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ libc = "0.2"

[build-dependencies]
cc = "1.1"
pkg-config = "0.3.9"
12 changes: 11 additions & 1 deletion lz4-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ fn main() {
}

fn run() -> Result<(), Box<dyn Error>> {
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")
Expand All @@ -24,7 +35,6 @@ fn run() -> Result<(), Box<dyn Error>> {
// 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.
Expand Down

0 comments on commit e897ccd

Please sign in to comment.