Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to build/compile `yeslogic-fontconfig-sys vX.X.X` with Rust on Ubuntu system

I'm failing to build/compile anything where the yeslogic-fontconfig-sys crate is involved (using Ubuntu with Rust). This happens i.e. by using crates like plotters or cargo install inlyne:

For example building an project with the dependency plotters:

 >> cargo build
   Compiling yeslogic-fontconfig-sys v3.2.0
   Compiling png v0.17.9
   Compiling serde v1.0.171
   Compiling num-rational v0.4.1
error: failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`

Caused by:
  process didn't exit successfully: `pathTo/Projectrust_bench/target/debug/build/yeslogic-fontconfig-sys-aadd5f5fe0e3d3ca/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=RUST_FONTCONFIG_DLOPEN
  cargo:rerun-if-env-changed=FONTCONFIG_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=FONTCONFIG_STATIC
  cargo:rerun-if-env-changed=FONTCONFIG_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "`PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=\"1\" PKG_CONFIG_ALLOW_SYSTEM_LIBS=\"1\" \"pkg-config\" \"--libs\" \"--cflags\" \"fontconfig\"` did not exit successfully: exit status: 1\nerror: could not find system library 'fontconfig' required by the 'yeslogic-fontconfig-sys' crate\n\n--- stderr\nPackage fontconfig was not found in the pkg-config search path.\nPerhaps you should add the directory containing `fontconfig.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'fontconfig' found\n"', /home/metamorph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yeslogic-fontconfig-sys-3.2.0/build.rs:8:48
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

After some research, there seemed to be a system dependency problem: the fontconfig package (missing) or pkg-config (configuration issue).

I tried much of the advice available online, installing the necessary dependencies on the Ubuntu system, like:

sudo apt install libfontconfig1-dev pkg-config fontconfig libfontconfig-dev

But none of them worked; building or compiling the project again failed.

If I do pkg-configpkg-config:

 >> pkg-configpkg-config --variable=libdir fontconfig
Package fontconfig was not found in the pkg-config search path.
Perhaps you should add the directory containing `fontconfig.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fontconfig' found

Any idea of how to get it working is highly appreciated.

like image 941
Michael Avatar asked Sep 13 '25 21:09

Michael


2 Answers

I found a solution!

The PKG_CONFIG_PATH environment variable was not set. The environment variable needs the path to the directory containing the fontconfig.pc file.

I found the fontconfig.pc file in /usr/lib/x86_64-linux-gnu/pkgconfig. By making it available/exporting it like

export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH

everything (plotters, installing inlyne) did compile and run successfully.

pkg-config runs successfully too:

 >> pkg-config --variable=libdir fontconfig
/usr/lib/x86_64-linux-gnu
like image 76
Michael Avatar answered Sep 16 '25 13:09

Michael


I also hit the same issue when building on AWS Ubuntu runners.

I enabled the "fontconfig-dlopen" feature in my Cargo.toml.

plotters = { version = "0.3.7", features = ["ab_glyph", "fontconfig-dlopen"] }

This makes the build less dependent on the OS

like image 21
Jeffrey Fagerberg Avatar answered Sep 16 '25 12:09

Jeffrey Fagerberg