slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

Cannot find default fonts in GNU Guix. #4077

Closed jeandudey closed 11 months ago

jeandudey commented 11 months ago

I'm using Slint with Rust 1.70 on GNU Guix.

When trying to run examples/todo/rust it panics on startup because Slint is not able to find the DejaVu fonts on the system (installed).

This error can be reproduced on a GNU Guix system as follows:

guix shell --pure font-dejavu \
                  fontconfig \
                  gcc-toolchain \
                  wayland \
                  libx11 \
                  libxcursor \
                  libxi \
                  libxkbcommon \
                  pkg-config \
                  rust \
                  rust:cargo -- \
                  cargo run --manifest-path examples/todo/rust/Cargo.toml

And shows the following output:

warning: Could not find a Qt installation. The Qt backend will not be functional. See https://github.com/slint-ui/slint/blob/master/docs/install_qt.md for more info
warning:     Failed to execute qmake. Make sure \'qmake\' is in your path!\nentity not found
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/todo`
thread 'main' panicked at 'Unable to determine default font. Failed to locate font for family DejaVu Sans', internal/common/sharedfontdb.rs:151:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The XDG_DATA_DIRS environment variables inside of the guix shell:

...
declare -x XDG_DATA_DIRS="/gnu/store/3722lq2qa7wwqpzphn22xngvfbd3ci5p-profile/share"

Which contains the DejaVu fonts at /gnu/store/3722lq2qa7wwqpzphn22xngvfbd3ci5p-profile/share/fonts/truetype:

DejaVuMathTeXGyre.ttf
DejaVuSans-Bold.ttf
DejaVuSans-BoldOblique.ttf
DejaVuSans-ExtraLight.ttf
DejaVuSans-Oblique.ttf
DejaVuSans.ttf
DejaVuSansCondensed-Bold.ttf
DejaVuSansCondensed-BoldOblique.ttf
DejaVuSansCondensed-Oblique.ttf
DejaVuSansCondensed.ttf
DejaVuSansMono-Bold.ttf
DejaVuSansMono-BoldOblique.ttf
DejaVuSansMono-Oblique.ttf
DejaVuSansMono.ttf
DejaVuSerif-Bold.ttf
DejaVuSerif-BoldItalic.ttf
DejaVuSerif-Italic.ttf
DejaVuSerif.ttf
DejaVuSerifCondensed-Bold.ttf
DejaVuSerifCondensed-BoldItalic.ttf
DejaVuSerifCondensed-Italic.ttf
DejaVuSerifCondensed.ttf
fonts.dir
fonts.scale

When running with export SLINT_DEFAULT_FONT=/gnu/store/3722lq2qa7wwqpzphn22xngvfbd3ci5p-profile/share/fonts it works fine though.

hunger commented 11 months ago

Thanks for reporting your issue. Looks like one of our dependencies does not respect XDG_DATA_DIRS then.

Does font-config know about that font? Does it show up in fc-list?

jeandudey commented 11 months ago

@hunger Yes it shows:

guix shell --pure fontconfig font-dejavu -- fc-list ``` /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerifCondensed-BoldItalic.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansMono-Oblique.ttf: DejaVu Sans Mono:style=Oblique /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerifCondensed-Bold.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold,Bold /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuMathTeXGyre.ttf: DejaVu Math TeX Gyre:style=Regular /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansMono-BoldOblique.ttf: DejaVu Sans Mono:style=Bold Oblique /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerif-BoldItalic.ttf: DejaVu Serif:style=Bold Italic /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerifCondensed.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerif-Italic.ttf: DejaVu Serif:style=Italic /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerif.ttf: DejaVu Serif:style=Book /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerifCondensed-Italic.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Italic,Italic /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerif.ttf: DejaVu Serif:style=Book /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansMono-Oblique.ttf: DejaVu Sans Mono:style=Oblique /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerif-Italic.ttf: DejaVu Serif:style=Italic /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansMono-BoldOblique.ttf: DejaVu Sans Mono:style=Bold Oblique /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSans.ttf: DejaVu Sans:style=Book /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique /home/jeandudey/.local/share/fonts/DejaVuSans.ttf: DejaVu Sans:style=Book /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerifCondensed-BoldItalic.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerifCondensed-Italic.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Italic,Italic /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSerif-BoldItalic.ttf: DejaVu Serif:style=Bold Italic /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerifCondensed-Bold.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold,Bold /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSans.ttf: DejaVu Sans:style=Book /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSerifCondensed.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuMathTeXGyre.ttf: DejaVu Math TeX Gyre:style=Regular /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book /gnu/store/zan3d655r50cv5gxvj2l5yybwhy6x3n4-font-dejavu-2.37/share/fonts/truetype/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique /gnu/store/6rhgxhywaf9ycvpwj9lfn08l5hv49ws8-profile/share/fonts/truetype/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold ```
hunger commented 11 months ago

Thanks! That's unfortunately all I can do, I'll leave this for the guys that know that part of the codebase on Friday. Sorry for the delay.

tronical commented 11 months ago

I can't run the command unfortunately :-(. Somehow it picks a really old version 1.60 of cargo/rust for me, which fails to parse our Cargo.toml files. If I remove the --pure and pick up my local rust/cargo, I get linking errors.

I was able to create an interactive guix-shell though to inspect the environment. I'm afraid our hands are a little tied here: At the heart of the problem is that while libfontconfig is built to look in Guix specific places for fonts, we're not using fontconfig directly but we're merely looking in standard locations such as /etc/fonts/fonts.conf and a few other places. The code in question is here:

https://github.com/RazrFalcon/fontdb/blob/c3274d016cad92fac744d76a91e4554fe51c5745/src/lib.rs#L425

If Guix was setting XDG_CONFIG_HOME then we'd find the right fonts.conf perhaps. Alternatively, perhaps you could point FONTCONFIG_FILE in your environment to the Guix path? (for me that's for example /gnu/store/1vxl2hcqdpr4n359addyq0iai3bd2cr7-fontconfig-2.13.94/etc/fonts/fonts.conf, but obviously that's not a generic path :)

On second thought, I think this is best fixed in Guix if the fontconfig package would set the FONTCONFIG_FILE environment variable (documented upstream at https://www.freedesktop.org/software/fontconfig/fontconfig-user.html )

jeandudey commented 10 months ago

@tronical

Somehow it picks a really old version 1.60 of cargo/rust for me, which fails to parse our Cargo.toml files.

After installing Guix you should update it to latest version, e.g.: guix pull and it will update your user's Guix to latest commit which has Rust 1.73.0 at the time of writing.

If Guix was setting XDG_CONFIG_HOME then we'd find the right fonts.conf perhaps. Alternatively, perhaps you could point FONTCONFIG_FILE in your environment to the Guix path? (for me that's for example /gnu/store/1vxl2hcqdpr4n359addyq0iai3bd2cr7-fontconfig-2.13.94/etc/fonts/fonts.conf, but obviously that's not a generic path :)

Guix only set environment variables when packages that use them are specified, for example:

guix shell font-dejavu --search-paths --pure

Yields nothing as no program in the shell needs to find the dejavu font, however it will be still available on the profile.

On the other hand, when programs that depend on fontconfig are specified (or fontconfig itself):

$ guix shell font-dejavu fontconfig --search-paths --pure
[env] $ export
export PATH="/gnu/store/6qy21kvk0dz8zsjpv79r94ky0yn0l66j-profile/bin"
export XDG_DATA_DIRS="/gnu/store/6qy21kvk0dz8zsjpv79r94ky0yn0l66j-profile/share"

So, Guix's version of fontconfig relies on XDG_DATA_DIRS to find fonts.

That environment variable is also used by Flatpak's so in theory if user point's XDG_DATA_DIRS to their Flatpak install location they will also not find Flatpak fonts too. Not that a lot of people distribute fonts with Flatpak but just that it is not only a Guix problem 👀 .

An example of this:

export XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.local/share/flatpak/exports/share"
export XDG_DATA_DIRS="$XDG_DATA_DIRS:/var/lib/flatpak/exports/share"

As of fontconfig 2.13.94 it supports this environment variable:

https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/src/fccfg.c?ref_type=heads#L2592

On second thought, I think this is best fixed in Guix if the fontconfig package would set the FONTCONFIG_FILE environment variable (documented upstream at https://www.freedesktop.org/software/fontconfig/fontconfig-user.html )

I don't think that's an option since there's multiple profiles in a Guix system, including the system profile, the user's one, home's one and others. Instead all of those are aggregated on XDG_DATA_DIRS.

tronical commented 10 months ago

Thanks for the explanations. This makes sense to me. I do agree with your analysis and I think that fontdb ideally should support XDG_DATA_DIRS then.