Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Add force_system_lib feature
Browse files Browse the repository at this point in the history
This feature ensure that libfontconfig won't build local copy of
Fontconfig and errors out if the system one is missing.

Fixes #55.
  • Loading branch information
kchibisov committed May 30, 2020
1 parent 3d042f6 commit 9d61e32
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ freetype-sys = "0.12.0"

[build-dependencies]
pkg-config = "0.3"

[features]
default = []
force_system_lib = []
46 changes: 39 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,37 @@

extern crate pkg_config;

use std::process::Command;
use std::env;
use std::process::Command;

fn main() {
let target = env::var("TARGET").unwrap();

if !target.contains("android") {
// If the system version of fontconfig isgat least 2.11.1, use it.
if let Ok(lib) = pkg_config::Config::new().atleast_version("2.11.1").find("fontconfig") {
println!("cargo:incdir={}", lib.include_paths[0].clone().into_os_string().into_string().unwrap());
return;
// If the system version of fontconfig is at least 2.11.1, use it.
#[allow(clippy::single_match)]
match pkg_config::Config::new()
.atleast_version("2.11.1")
.find("fontconfig")
{
Ok(lib) => {
println!(
"cargo:incdir={}",
lib.include_paths[0]
.clone()
.into_os_string()
.into_string()
.unwrap()
);

return;
}
#[cfg(feature = "force_system_lib")]
Err(error) => {
panic!("{}", error);
}
#[cfg(not(feature = "force_system_lib"))]
_ => (),
}
}

Expand All @@ -23,7 +44,18 @@ fn main() {
.status()
.unwrap()
.success());
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());

println!(
"cargo:rustc-link-search=native={}",
env::var("OUT_DIR").unwrap()
);
println!("cargo:rustc-link-lib=static=fontconfig");
println!("cargo:incdir={}", env::current_dir().unwrap().into_os_string().into_string().unwrap());
println!(
"cargo:incdir={}",
env::current_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap()
);
}

0 comments on commit 9d61e32

Please sign in to comment.