Skip to content

Commit

Permalink
add dynamic link
Browse files Browse the repository at this point in the history
  • Loading branch information
Isotr0py committed Dec 20, 2023
1 parent 1f516f7 commit 38158ae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
60 changes: 41 additions & 19 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
}
}
}

0 comments on commit 38158ae

Please sign in to comment.