Skip to content
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

fontconfig: add option to use system directories #23288

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

johningve
Copy link
Contributor

@johningve johningve commented Mar 27, 2024

The fontconfig package currently tries to load fonts from some directory within the conan package directory. This results in the following error when this directory is not present:

Fontconfig error: Cannot load default config file: No such file: (null)

This commit adds an option system_dirs to use system directories instead.

Fixes #5782

Specify library name and version: fontconfig/2.13.93+


The fontconfig package currently tries to load fonts from some directory
within the conan package directory. This results in the following error
when this directory is not present:

```
Fontconfig error: Cannot load default config file: No such file: (null)
```

This commit adds an option `system_dirs` to use system directories
instead.

Fixes conan-io#5782
Copy link
Contributor

@valgur valgur left a comment

Choose a reason for hiding this comment

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

This fixes what seems like an important oversight. Thanks!

Should use project_options instead, though.

Comment on lines 96 to 100
if self.settings.os in ("Linux", "FreeBSD") and self.options.get_safe("system_dirs", False):
self._replace_configuration_string(build_script, "CONFIGDIR", "fc_configdir", "'/etc/fonts/conf.d'")
self._replace_configuration_string(build_script, "FC_CACHEDIR", "fc_cachedir", "'/var/cache/fontconfig'")
self._replace_configuration_string(build_script, "FC_TEMPLATEDIR", "fc_templatedir", "'/usr/share/fontconfig/conf.avail'")
self._replace_configuration_string(build_script, "FONTCONFIG_PATH", "fc_baseconfigdir", "'/etc/fonts'")
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to accomplish the same without patching simply via project_options in generate(), I think:

tc.project_options["fc_configdir"] = "/etc/fonts/conf.d"
tc.project_options["fc_cachedir"] = "/var/cache/fontconfig"
tc.project_options["fc_templatedir"] = "/usr/share/fontconfig/conf.avail"
tc.project_options["fc_baseconfigdir"] = "/etc/fonts"

Also, you should probably override xml-dir as well? https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/meson_options.txt?ref_type=heads#L32-45

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought I had tried that previously, but you are right, it works on Conan 2.

Unfortunately, on Conan 1, Meson attempts to install something to /usr and fails. Looks like it is due to missing this change: conan-io/conan#15706

@valgur
Copy link
Contributor

valgur commented Mar 27, 2024

Could setting either of these options get the best of both worlds without introducing a recipe option, maybe?
https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/meson_options.txt?ref_type=heads#L25-29

@conan-center-bot

This comment has been minimized.

@johningve
Copy link
Contributor Author

Incidentally I noticed that the paths get different defaults on Conan 2 compared to Conan 1 (that is, when system_dirs=False). The Paths on Conan 2 are almost correct for a Linux system. Though the Template and XML directory paths are wrong.

Conan 2:

  Defaults
    Hinting                    : slight
    Font directories           : /usr/share/fonts, /usr/local/share/fonts
    Additional font directories:

  Paths
    Cache directory            : /var/cache/fontconfig
    Template directory         : /share/fontconfig/conf.avail
    Base config directory      : /etc/fonts
    Config directory           : /etc/fonts/conf.d
    XML directory              : /share/xml/fontconfig

Conan 1:

  Defaults
    Hinting                    : slight
    Font directories           : /usr/share/fonts, /usr/local/share/fonts
    Additional font directories:

  Paths
    Cache directory            : /home/johnio/.conan/data/fontconfig/2.14.2/_/_/package/91934fc8bcc809a17bd34af66d8491f41cb49e99/var/cache/fontconfig
    Template directory         : /home/johnio/.conan/data/fontconfig/2.14.2/_/_/package/91934fc8bcc809a17bd34af66d8491f41cb49e99/share/fontconfig/conf.avail
    Base config directory      : /home/johnio/.conan/data/fontconfig/2.14.2/_/_/package/91934fc8bcc809a17bd34af66d8491f41cb49e99/etc/fonts
    Config directory           : /home/johnio/.conan/data/fontconfig/2.14.2/_/_/package/91934fc8bcc809a17bd34af66d8491f41cb49e99/etc/fonts/conf.d
    XML directory              : /home/johnio/.conan/data/fontconfig/2.14.2/_/_/package/91934fc8bcc809a17bd34af66d8491f41cb49e99/share/xml/fontconfig

@johningve
Copy link
Contributor Author

Could setting either of these options get the best of both worlds without introducing a recipe option, maybe? https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/meson_options.txt?ref_type=heads#L25-29

Looks like those options are used to specify the location of fonts, not the config/cache directories.

@uilianries uilianries self-assigned this Jun 5, 2024
@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Copy link
Member

@uilianries uilianries left a comment

Choose a reason for hiding this comment

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

@johningve Thank you for your suggestion of fixing that case. I would not go for adding a new option only change an environment variable, it's too much. Conan offers mechanisms to do it without touching the recipe. Please, read #5782 (comment) and check if fits your case.

I see a fragility here as you are hardcoding system paths that we can not guarantee. Conan only knows its own cache, outside of that is risky. Still, in case that option is not enough, we could add a Conan configuration to handle those variables, they fit better because are not part of the package ID.

@conan-center-bot
Copy link
Collaborator

Conan v1 pipeline ✔️

All green in build 3 (3c07a89676a2b768c5eaf831ffa8b8e70fdd8875):

  • fontconfig/2.15.0:
    All packages built successfully! (All logs)

  • fontconfig/2.14.2:
    All packages built successfully! (All logs)

  • fontconfig/2.13.93:
    All packages built successfully! (All logs)


Conan v2 pipeline ✔️

Note: Conan v2 builds are now mandatory. Please read our discussion about it.

All green in build 3 (3c07a89676a2b768c5eaf831ffa8b8e70fdd8875):

  • fontconfig/2.15.0:
    All packages built successfully! (All logs)

  • fontconfig/2.14.2:
    All packages built successfully! (All logs)

  • fontconfig/2.13.93:
    All packages built successfully! (All logs)

@johningve
Copy link
Contributor Author

@johningve Thank you for your suggestion of fixing that case. I would not go for adding a new option only change an environment variable, it's too much. Conan offers mechanisms to do it without touching the recipe. Please, read #5782 (comment) and check if fits your case.

It is not about changing an environment variable, that is a workaround to this issue. What this is about is changing the location where fontconfig will look for fonts by default. I want to be able to include fontconfig in my application and have it work without the user having to worry about environment variables.

I see a fragility here as you are hardcoding system paths that we can not guarantee. Conan only knows its own cache, outside of that is risky. Still, in case that option is not enough, we could add a Conan configuration to handle those variables, they fit better because are not part of the package ID.

I would say that at least on Linux, these paths are well known and relied upon. I get that Conan doesn't want to rely upon the outside too much, but the purpose of fontconfig is to enable applications to find and use the fonts available on the local system.

@paulharris
Copy link
Contributor

I would ask, at which point would anyone want fontconfig to use the configuration within conan's cache?

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.

[package] fontconfig/2.13.93: How to use with sysconfdir set on build machine
5 participants