diff --git a/Cargo.toml b/Cargo.toml index e851b23..ffabfb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ jpegxl-rs = { version = "0.8.3", default-features = false, features = ["threads" [features] # Enables parallel processing support by enabling the "rayon" feature of jpeg-decoder. vendored = ["jpegxl-rs/vendored"] +dynamic = [] diff --git a/build.rs b/build.rs index 8926864..90b989d 100644 --- a/build.rs +++ b/build.rs @@ -1,24 +1,46 @@ use std::env; +fn dynamic_link() { + println!("cargo:rustc-link-lib=jxl"); + println!("cargo:rustc-link-lib=jxl_threads"); + + println!("cargo:rustc-link-lib=hwy"); + if let Ok(path) = env::var("DEP_HWY_LIB") { + println!("cargo:rustc-link-search=native={}", path); + } + + println!("cargo:rustc-link-lib:+whole-archive=brotlidec"); + println!("cargo:rustc-link-lib=brotlienc"); + println!("cargo:rustc-link-lib=brotlicommon"); + if let Ok(path) = env::var("DEP_BROTLI_LIB") { + println!("cargo:rustc-link-search=native={}", path); + } +} + +fn static_link() { + println!("cargo:rustc-link-lib=static=jxl"); + println!("cargo:rustc-link-lib=static=jxl_threads"); + + println!("cargo:rustc-link-lib=static=hwy"); + if let Ok(path) = env::var("DEP_HWY_LIB") { + println!("cargo:rustc-link-search=native={}", path); + } + + println!("cargo:rustc-link-lib=static:+whole-archive=brotlidec-static"); + println!("cargo:rustc-link-lib=static=brotlienc-static"); + println!("cargo:rustc-link-lib=static=brotlicommon-static"); + if let Ok(path) = env::var("DEP_BROTLI_LIB") { + println!("cargo:rustc-link-search=native={}", path); + } +} + fn main() { // Static link libjxl - #[cfg(not(feature = "vendored"))] - { - println!("cargo:rustc-link-lib=static=jxl"); - println!("cargo:rustc-link-lib=static=jxl_threads"); - - println!("cargo:rustc-link-lib=static=hwy"); - if let Ok(path) = env::var("DEP_HWY_LIB") { - println!("cargo:rustc-link-search=native={}", path); - } - - println!("cargo:rustc-link-lib=static:+whole-archive=brotlidec-static"); - println!("cargo:rustc-link-lib=static=brotlienc-static"); - println!("cargo:rustc-link-lib=static=brotlicommon-static"); - if let Ok(path) = env::var("DEP_BROTLI_LIB") { - println!("cargo:rustc-link-search=native={}", path); - } - } + #[cfg(all(not(feature = "vendored"), not(feature = "dynamic")))] + static_link(); + + #[cfg(all(not(feature = "vendored"), feature = "dynamic"))] + dynamic_link(); // Dynamic link c++ // TODO: Support MSVC and use Cargo @@ -28,6 +50,6 @@ fn main() { // Linux and Windows should all use GNU toolchain "linux" | "windows" => println!("cargo:rustc-link-lib=stdc++"), "macos" => println!("cargo:rustc-link-lib=c++"), - _ => panic!("Not implemented c++ link on {}", platform) + _ => panic!("Not implemented c++ link on {}", platform), } -} \ No newline at end of file +}