spiro-sys 0.1.1

Rust bindings for libspiro
Documentation
/// Build libspiro binding for Rust.
extern crate cc;

#[cfg(feature = "build-bindgen")]
fn do_bindgen() {
    extern crate bindgen;
    // Based on `bindgen` manual.
    let bindings = bindgen::Builder::default()
        .header("wrapper.h")
        // Tell cargo to invalidate the built crate whenever any of the
        // included header files changed.
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .derive_partialeq(true)
        .derive_debug(true)
        .derive_copy(true)
        .derive_default(true)
        // This function doesn't exist! Struct must be created.
        .blacklist_function("new_bezctx")
        // Avoids silly warnings about case of types. They're from C...
        .raw_line("#![allow(non_camel_case_types, non_snake_case)]")
        .generate()
        .expect("Unable to generate bindings");

    let out_path = std::path::PathBuf::from("src");
    let out_file = out_path.join("lib.rs");
    bindings
        .write_to_file(out_file.clone())
        .expect("Couldn't write bindings!");

    // Windows sanity - use \n even on Windows.
    #[cfg(target_family = "windows")]
    {
        extern crate dos2unix;

        dos2unix::Dos2Unix::convert(&out_file.into_os_string().into_string().unwrap(), false);
    }
}

fn main() {
    cc::Build::new()
        // We aren't using libspiro's autotools build, so I wrote a generic spiro-config.h which
        // will work on all the systems I care about.
        .include(".") // for spiro-config.h
        .file("libspiro/bezctx.c")
        .file("libspiro/spiro.c")
        .file("libspiro/spiroentrypoints.c")
        .static_flag(true)
        .shared_flag(true)
        .static_crt(true)
        .compile("libspiro.a");

    println!("cargo:rerun-if-changed=wrapper.h");

    // Link built library. "lib" and ".a" are added back by Cargo.
    println!("cargo:rustc-link-lib=static=spiro");

    #[cfg(feature = "build-bindgen")]
    do_bindgen();
}