extern crate cc; extern crate pkg_config; extern crate bindgen; use cc::Build; use pkg_config::Library; use std::env; use std::path::PathBuf; fn main() { let geany: Library = pkg_config::probe_library("geany").unwrap(); let mut build = Build::new(); add_pkg_config(&mut build, &geany); build.file("plugin.c") .flag("-DGTK") .flag("-pthread") .compile("foo"); write_bindings(&geany); } // https://github.com/alexcrichton/cc-rs/issues/147#issue-216395683 fn add_pkg_config(build: &mut Build, pkg: &Library) { for p in pkg.include_paths.iter() { build.include(p); } for p in pkg.link_paths.iter() { build.flag(&format!("-L{:?}", p)); } for p in pkg.libs.iter() { build.flag(&format!("-l{}", p)); } for p in pkg.framework_paths.iter() { build.flag(&format!("-F{:?}", p)); } for p in pkg.frameworks.iter() { build.flag(&format!("-framework {}", p)); } } fn write_bindings(pkg: &Library) { let mut bindings_builder = bindgen::Builder::default() .header("wrapper.h") .clang_arg("-DGTK"); for p in pkg.include_paths.iter() { bindings_builder = bindings_builder.clang_arg(format!("-I{}", p.to_str().unwrap())); } let bindings = bindings_builder.generate() .expect("Unable to generate bindings"); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); }