plotters
plotters copied to clipboard
fontconfig can't find the default font after compilation
Describe the bug
I am not able to run the first bitmap example because fontconfig doesn't work :

To Reproduce here is a nix expression I used:
{ pkgs ? import <nixpkgs> {} }:
let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
pkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
channel = pkgs.rustChannelOf {
date = "2021-11-01";
channel = "nightly";
};
rust = (channel.rust.override {
targets = [ "wasm32-unknown-unknown" ];
extensions = ["rust-src" "rust-analysis"];
});
in
with pkgs;
pkgs.mkShell {
name = "rust-env";
buildInputs = [
pkg-config
freetype
cmake
expat
rust
];
shellHook =
let fonts = makeFontsConf { fontDirectories = [ open-sans freefont_ttf fira fira-mono ]; };
in ''
export FONTCONFIG_FILE=${fonts}
fc-cache -f
'';
}
Version Information Here is my Cargo.toml:
[package]
name = "simu_elec"
version = "0.1.0"
edition = "2021"
[dependencies.plotters]
version="0.3.1"
default-features=false
features = ["bitmap_backend", "line_series"]
description element and domain attribute were added in fontconfig-2.12.91 (changelog). The error looks like an older fontconfig has tried to load fonts.conf's for newer version.
I'm not really sure how nix works, but maybe, an older fontconfig installed by nix tried to read the /etc/fonts/conf.d/*.confs for newer fontconfig installed by the system-wide package manager (like apt or dnf)?
I just went down the rabbit hole of getting plotters to build on nixos and did not come across this issue. I came across a different issue, however, which is documented in https://discourse.nixos.org/t/cargo-fails-to-build-plotters-due-to-missing-usr-bin-file/17543/5. A flake + lockfile with the fix, using cargo2nix, can be found here: https://github.com/stites/dev-shells/blob/main/rust-ml/flake.nix#L41-L55
@rambip is this still a problem for you? if so, can you try adding pkgs.fontconfig to your nativeBuildInputs and not target wasm (for the moment)? I am happy to try to help work on this issue if it is nix-specific.
edit, 03/2023: I migrated to crane and everything is still working. Don't forget to include the following in your shell: https://github.com/stites/dev-shells/blob/main/rust-ml/flake.nix#L70-L71