Skip to content

add dlopen Cargo feature using dlib to load fontconfig at runtime #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2022

Conversation

Be-ing
Copy link
Contributor

@Be-ing Be-ing commented Feb 14, 2022

Fixes #11

I modernized the code a bit along the way.

@Be-ing Be-ing force-pushed the dlopen branch 8 times, most recently from bada199 to 0b9008c Compare February 15, 2022 20:51
Be-ing added a commit to Be-ing/font-kit that referenced this pull request Feb 15, 2022
instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if
fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work
well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because
fontconfig has a lot of C dependencies, which makes it difficult to
cross compile the vendored copy of fontconfig:

$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm
-lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2
-lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig
at runtime instead of linking it at build time. This is exposed in
font-kit with the new source-fontconfig-dlopen feature, which is
disabled by default. This feature makes it considerably easier to cross
compile by avoiding the need to cross compile fontconfig and all its
dependencies.
Be-ing added a commit to Be-ing/font-kit that referenced this pull request Feb 16, 2022
instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if
fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work
well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because
fontconfig has a lot of C dependencies, which makes it difficult to
cross compile the vendored copy of fontconfig:

$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm
-lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2
-lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig
at runtime instead of linking it at build time. This is exposed in
font-kit with the new source-fontconfig-dlopen feature, which is
disabled by default. This feature makes it considerably easier to cross
compile by avoiding the need to cross compile fontconfig and all its
dependencies.
Be-ing added a commit to Be-ing/font-kit that referenced this pull request Feb 16, 2022
instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if
fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work
well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because
fontconfig has a lot of C dependencies, which makes it difficult to
cross compile the vendored copy of fontconfig:

$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm
-lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2
-lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig
at runtime instead of linking it at build time. This is exposed in
font-kit with the new source-fontconfig-dlopen feature, which is
disabled by default. The feature can be enabled by setting the
RUST_FONTCONFIG_DLOPEN environment variable to avoid needing to
propagate the Cargo feature all the way through downstream
Cargo.toml's. This feature makes it considerably easier to cross
compile by avoiding the need to cross compile fontconfig and all its
dependencies.
@Be-ing
Copy link
Contributor Author

Be-ing commented Feb 16, 2022

I added build.rs's so setting the RUST_FONTCONFIG_DLOPEN environment variable enables the dlopen feature. This allows people building downstream applications to control whether it is linked or dlopen'ed without needing to pass the Cargo feature all the way down the stack of Cargo.toml's. Refer to discussion here.

Copy link
Contributor

@wezm wezm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall seems ok, a few things to fix up. I'd probably want sign off from the Slint folks that they will accept slint-ui/slint#956 so that we have a concrete use case before merging.

.travis.yml Outdated
@@ -13,7 +13,7 @@ rust:
- nightly
- beta
- stable
- 1.38.0
- 1.43.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to need additional CI builds to check that it works with and without the dlopen feature enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the beta and nightly CI jobs? If it works with stable, why wouldn't it work with beta and nightly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that sometimes incompatibilities are introduced in newer versions and this might catch that. However, that requires a CI cron job, which hasn't been set up so may as well remove them and speed up the build.

@@ -27,6 +27,11 @@ name = "fontconfig_sys"

[dependencies]
const-cstr = "0.3"
dlib = "0.5.0"
lazy_static = "1.4.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to allow using any lazy_static version in the >1.4 series so this version requirement can be 1.4. Having said that there's ongoing work (See rust-lang/rfcs#2788 and rust-lang/rust#74465) to integrate once_cell into Rust so I would prefer to use that instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Be-ing Be-ing force-pushed the dlopen branch 8 times, most recently from 5029ed8 to 5a966c9 Compare February 17, 2022 20:39
@Be-ing
Copy link
Contributor Author

Be-ing commented Feb 17, 2022

I find it confusing how fontconfig-sys has a fontconfig module within it. It is easy to confuse with the fontconfig safe wrapper crate. Currently the imports in the fontconfig safe wrapper's lib.rs are:

use crate::fontconfig_sys::fontconfig as sys;
use crate::fontconfig_sys::ffi_dispatch;

#[cfg(feature = "dlopen")]
use sys::{LIB, LIB_RESULT};
#[cfg(not(feature = "dlopen"))]
use sys::*;

I'd like to change this to:

use crate::fontconfig_sys as sys;
use crate::fontconfig_sys::ffi_dispatch;

#[cfg(feature = "dlopen")]
use sys::{LIB, LIB_RESULT};
#[cfg(not(feature = "dlopen"))]
use sys::*;

by moving the contents of fontconfig-sys/src/fontconfig.rs into fontconfig-sys/src/lib.rs. What do you think about this?

It was confusing to have a fontconfig crate which depends on the
fontconfig-sys crate which in turn has a module called fontconfig.
This simplifies the paths so fontconfig-sys does not have any
submodules; everything is in its lib.rs now. So import paths change
from

use fontconfig_sys::fontconfig::*

to

use fontconfig_sys::*
@wezm
Copy link
Contributor

wezm commented Feb 17, 2022

by moving the contents of fontconfig-sys/src/fontconfig.rs into fontconfig-sys/src/lib.rs. What do you think about this?

Seems fine, I think that structure was just inherited from the original project it was forked from.

@Be-ing
Copy link
Contributor Author

Be-ing commented Feb 18, 2022

I'd probably want sign off from the Slint folks that they will accept slint-ui/slint#956 so that we have a concrete use case before merging.

I have been discussing this with them and got the impression that they intend to merge slint-ui/slint#956 after this PR is merged. @tronical, @ogoffart, can one of you confirm this?

Be-ing added a commit to Be-ing/font-kit that referenced this pull request Feb 18, 2022
instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if
fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work
well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because
fontconfig has a lot of C dependencies, which makes it difficult to
cross compile the vendored copy of fontconfig:

$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm
-lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2
-lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig
at runtime instead of linking it at build time. This is exposed in
font-kit with the new source-fontconfig-dlopen feature, which is
disabled by default. The feature can be enabled by setting the
RUST_FONTCONFIG_DLOPEN environment variable to avoid needing to
propagate the Cargo feature all the way through downstream
Cargo.toml's. This feature makes it considerably easier to cross
compile by avoiding the need to cross compile fontconfig and all its
dependencies.
@tronical
Copy link

I think switching Slint over to use yeslogic's fontconfig crate would be an improvement. I love you how folks are actively maintaining it and responding to feedback.

@wezm wezm merged commit 0f7c93f into yeslogic:master Feb 21, 2022
@Be-ing
Copy link
Contributor Author

Be-ing commented Feb 21, 2022

Thanks for reviewing! Could you publish a new release to crates.io?

@wezm
Copy link
Contributor

wezm commented Feb 22, 2022

Thanks for reviewing! Could you publish a new release to crates.io?

Yes, once I have #13 passing on CI

@wezm
Copy link
Contributor

wezm commented Feb 22, 2022

New crates have been published.

Be-ing added a commit to Be-ing/font-kit that referenced this pull request Feb 22, 2022
instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if
fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work
well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because
fontconfig has a lot of C dependencies, which makes it difficult to
cross compile the vendored copy of fontconfig:

$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm
-lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2
-lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig
at runtime instead of linking it at build time. This is exposed in
font-kit with the new source-fontconfig-dlopen feature, which is
disabled by default. The feature can be enabled by setting the
RUST_FONTCONFIG_DLOPEN environment variable to avoid needing to
propagate the Cargo feature all the way through downstream
Cargo.toml's. This feature makes it considerably easier to cross
compile by avoiding the need to cross compile fontconfig and all its
dependencies.
bors-servo added a commit to servo/font-kit that referenced this pull request Mar 27, 2022
switch to yeslogic-fontconfig-sys instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because fontconfig has a lot of C dependencies, which makes it difficult to cross compile the vendored copy of fontconfig:

```
$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm -lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2 -lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm
```

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig at runtime instead of linking it at build time. This is exposed in font-kit with the new source-fontconfig-dlopen feature, which is disabled by default. This feature makes it considerably easier to cross compile by avoiding the need to cross compile fontconfig and all its dependencies.
Be-ing added a commit to Be-ing/font-kit that referenced this pull request Mar 28, 2022
instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if
fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work
well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because
fontconfig has a lot of C dependencies, which makes it difficult to
cross compile the vendored copy of fontconfig:

$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm
-lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2
-lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig
at runtime instead of linking it at build time. This is exposed in
font-kit with the new source-fontconfig-dlopen feature, which is
disabled by default. The feature can be enabled by setting the
RUST_FONTCONFIG_DLOPEN environment variable to avoid needing to
propagate the Cargo feature all the way through downstream
Cargo.toml's. This feature makes it considerably easier to cross
compile by avoiding the need to cross compile fontconfig and all its
dependencies.
bors-servo added a commit to servo/font-kit that referenced this pull request Mar 28, 2022
switch to yeslogic-fontconfig-sys instead of servo-fontconfig

servo-fontconfig statically links a vendored fontconfig library if fontconfig is not found by pkgconfig. Using a vendored fontconfig
library instead of the system fontconfig library doesn't actually work well though:
slint-ui/slint#88
Building a vendored copy of fontconfig is also problematic because fontconfig has a lot of C dependencies, which makes it difficult to cross compile the vendored copy of fontconfig:

```
$ pkg-config fontconfig --static --libs
-lfontconfig -lfreetype -lz -lbz2 -lpng16 -lm -lm -lz -lharfbuzz -lm -lglib-2.0 -lm -lpcre -lsysprof-capture-4 -pthread -lgraphite2 -lbrotlidec -lbrotlicommon -lxml2 -lz -llzma -lm
```

Instead of using a vendored copy, with
yeslogic/fontconfig-rs#12
yeslogic-fontconfig-sys will have a Cargo feature to dlopen fontconfig at runtime instead of linking it at build time. This is exposed in font-kit with the new source-fontconfig-dlopen feature, which is disabled by default. This feature makes it considerably easier to cross compile by avoiding the need to cross compile fontconfig and all its dependencies.
@Be-ing Be-ing deleted the dlopen branch April 5, 2022 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use dlib for easier cross compiling
3 participants