linuxplotrustfedorarust-cargo

failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`


I am trying to learn how to plot in Rust and found a guide that is using plotters (if anyone knows a better plotting library let me know.)

https://plotters-rs.github.io/book/intro/getting_started.html

Anyways, I am on Fedora 37 and running into an issue using the example shown in the Getting started section of this guide.

The code is:

/*
Example of plotting in Rust
*/

use plotters::prelude::*;

fn main() {
    
    let root_drawing_area = BitMapBackend::new("0.1.png", (1024, 768))
        .into_drawing_area();

    root_drawing_area.fill(&WHITE).unwrap();

    let mut chart = ChartBuilder::on(&root_drawing_area)
        .build_cartesian_2d(-3.14..3.14, -1.2..1.2)
        .unwrap();

    chart.draw_series(LineSeries::new(
        (-314..314).map(|x| x as f64 / 100.0)
        .map(|x| (x, x.sin())), &RED))
        .unwrap();

}

In my cargo.toml file I've added the dependency using cargo add plotters

But when I run the code with cargo build I get this error:

Compiling yeslogic-fontconfig-sys v3.2.0
error: failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`

Caused by:
  process didn't exit successfully: `/home/usr/Dev/RustyKrab/plotting/plot_example/target/debug/build/yeslogic-fontconfig-sys-3bf9e95194fbfdbd/build-script-build` (exit status: 101)

And goes on for stdout

--- 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

and stderr

--- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "`\"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\nPackage 'fontconfig', required by 'virtual:world', not found\n"', /home/usr/.cargo/registry/src/github.com-1ecc6299db9ec823/yeslogic-fontconfig-sys-3.2.0/build.rs:8:48

With the last line of the error being note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. I've tried running RUST_BACKTRACE=1 alacritty but simply just doesn't work.

How can I work around this so I can use plotters in Rust?

Note: I've installed fontconfig with sudo dnf install fontconfig


Solution

  • @john-kugelman answers this in the comments of the question. To resolve my error here I would have to install the development tools for fontconfig using:

    sudo dnf install fontconfig-devel