1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() {
// chafa-dyn: Use pkg-config to find chafa and emit link flags
#[cfg(feature = "chafa-dyn")]
{
pkg_config::Config::new()
// https://github.com/hpjansson/chafa/commit/b1ddce829798a81db54572261e6864ebab171631
// 1.8.0 added chafa_canvas_get_char_at()
.atleast_version("1.8.0")
.probe("chafa")
.expect(
"Failed to find chafa via pkg-config. Install libchafa-dev or set PKG_CONFIG_PATH. Needs version >= 1.8.0.",
);
}
// chafa-static: Static linking only (no fallback)
#[cfg(feature = "chafa-static")]
{
let lib = pkg_config::Config::new()
.statik(true)
.probe("chafa")
.expect(
"Failed to find chafa via pkg-config. Install libchafa-dev or set PKG_CONFIG_PATH.",
);
// Find the static library
for path in &lib.link_paths {
let static_lib = path.join("libchafa.a");
if static_lib.exists() {
// Use this path for static linking
println!("cargo:rustc-link-search=native={}", path.display());
println!("cargo:rustc-link-lib=static=chafa");
// Also link dependencies that pkg-config found
for link_path in &lib.link_paths {
if link_path != path {
println!("cargo:rustc-link-search=native={}", link_path.display());
}
}
// Link glib and its dependencies statically
println!("cargo:rustc-link-lib=static=glib-2.0");
println!("cargo:rustc-link-lib=static=sysprof-capture-4");
println!("cargo:rustc-link-lib=pcre2-8");
println!("cargo:rustc-link-lib=m");
return;
}
}
// No static lib found - this is an error for chafa-static
panic!(
"chafa-static feature requires libchafa.a but it was not found in {:?}. \
Either build chafa with --enable-static or use chafa-dyn for dynamic linking.",
lib.link_paths
);
}
}