fcft-sys 0.1.0

Raw bindings to fcft: font loading and glyph rasterisation library
Documentation
fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    // Emit the link directives for libfcft.
    let fcft = pkg_config::Config::new()
        .atleast_version("3.0.0")
        .probe("fcft")
        .expect("fcft >= 3.0 should be installed and discoverable via pkg-config (fcft-dev)");

    // fcft's output is pixman images, and the API exposes these.
    // Bind related functions so consumers can consume output.
    let pixman = pkg_config::probe_library("pixman-1")
        .expect("pixman-1 should be installed and discoverable via pkg-config (pixman-dev)");

    let clang_args = fcft
        .include_paths
        .iter()
        .chain(pixman.include_paths.iter())
        .map(|p| format!("-I{}", p.display()))
        .chain(
            fcft.defines
                .iter()
                .chain(pixman.defines.iter())
                .map(|(k, v)| match v {
                    Some(v) => format!("-D{k}={v}"),
                    None => format!("-D{k}"),
                }),
        );

    let bindings = bindgen::Builder::default()
        .header_contents("wrapper.h", "#include <fcft/fcft.h>\n")
        .clang_args(clang_args)
        .allowlist_function("fcft_.*")
        .allowlist_type("fcft_.*")
        .allowlist_var("FCFT_.*")
        // Deprecated and slated for removal upstream.
        .blocklist_function("fcft_set_scaling_filter")
        .blocklist_function("fcft_set_emoji_presentation")
        // Minimal pixman surface needed to composite glyphs into a buffer.
        .allowlist_function("pixman_image_get_format")
        .allowlist_function("pixman_image_get_data")
        .allowlist_function("pixman_image_get_stride")
        .allowlist_function("pixman_image_get_width")
        .allowlist_function("pixman_image_get_height")
        .allowlist_function("pixman_image_create_bits_no_clear")
        .allowlist_function("pixman_image_create_solid_fill")
        .allowlist_function("pixman_image_composite32")
        .allowlist_function("pixman_image_unref")
        .allowlist_function("pixman_image_set_component_alpha")
        .generate()
        .expect("bindgen should generate bindings for <fcft/fcft.h>");

    let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out.join("bindings.rs"))
        .expect("bindings should be written to OUT_DIR");
}