Skip to content

Commit a4e26f6

Browse files
committed
add dlopen Cargo feature using dlib to load fontconfig at runtime
Fixes #11
1 parent d1ea5fc commit a4e26f6

File tree

9 files changed

+455
-401
lines changed

9 files changed

+455
-401
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rust:
1313
- nightly
1414
- beta
1515
- stable
16-
- 1.38.0
16+
- 1.46.0
1717

1818
jobs:
1919
allow_failures:
@@ -24,3 +24,4 @@ before_install:
2424

2525
script:
2626
- cargo test
27+
- RUST_FONTCONFIG_DLOPEN=on cargo test

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
members = [
33
"fontconfig-sys",
44
"fontconfig"
5-
]
5+
]

fontconfig-sys/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "yeslogic-fontconfig-sys"
3-
version = "2.11.2"
3+
version = "3.0.0"
4+
edition = "2018"
5+
rust-version = "1.46"
46
authors = [
57
"Austin Bonander <[email protected]>",
68
"The Servo Project Developers",
@@ -16,7 +18,6 @@ homepage = "https://github.com/yeslogic/fontconfig-rs"
1618
documentation = "https://docs.rs/crate/yeslogic-fontconfig-sys"
1719
repository = "https://github.com/yeslogic/fontconfig-rs"
1820

19-
build = "build.rs"
2021
links = "fontconfig"
2122

2223
[badges]
@@ -27,6 +28,13 @@ name = "fontconfig_sys"
2728

2829
[dependencies]
2930
const-cstr = "0.3"
31+
dlib = "0.5.0"
32+
# This cannot be optional because build.rs can't conditionally enable it
33+
# when the RUST_FONTCONFIG_DLOPEN environment variable is set.
34+
lazy_static = "1.4.0"
35+
36+
[features]
37+
dlopen = []
3038

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

fontconfig-sys/build.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
extern crate pkg_config;
2-
31
fn main() {
4-
pkg_config::find_library("fontconfig").unwrap();
2+
let dlopen = std::env::var("RUST_FONTCONFIG_DLOPEN").is_ok();
3+
if dlopen {
4+
println!("cargo:rustc-cfg=feature=\"dlopen\"");
5+
}
6+
if !(dlopen || cfg!(feature = "dlopen")) {
7+
pkg_config::find_library("fontconfig").unwrap();
8+
}
59
}

0 commit comments

Comments
 (0)