Created
June 15, 2019 14:50
-
-
Save Denommus/50e5e3b650937d410d1eb84e6b9c5c77 to your computer and use it in GitHub Desktop.
I'm so proud of this build file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate bindgen; | |
extern crate cmake; | |
extern crate filetime; | |
use std::env; | |
use std::fs; | |
use filetime::FileTime; | |
fn generate_bindings(out_dir: &str) { | |
let ode_dir = format!("{}/build", out_dir); | |
let bindings = bindgen::Builder::default() | |
.header("ode/include/ode/ode.h") | |
.clang_arg("-I./ode/include") | |
.clang_arg(format!("-I{}/include", ode_dir)) | |
.blacklist_type("_bindgen_ty_1") | |
.blacklist_type("max_align_t") | |
.generate() | |
.expect("Unable to generate bindings"); | |
bindings.write_to_file(format!("{}/ffi.rs", out_dir)) | |
.expect("Couldn't write file"); | |
} | |
fn compile_cmake() { | |
cmake::Config::new("ode") | |
.build_target("") | |
.build(); | |
} | |
fn exec_if_newer(inpath: &str, outpath: &str, build: &Fn()) { | |
match fs::metadata(outpath) { | |
Ok(metadata) => { | |
let outtime = FileTime::from_last_modification_time(&metadata); | |
let intime = FileTime::from_last_modification_time(&fs::metadata(inpath) | |
.expect(&format!("Path {} not found", inpath))); | |
if outtime < intime { | |
build(); | |
} | |
}, | |
_ => { build(); } | |
} | |
} | |
fn main() { | |
let out_dir = env::var("OUT_DIR").unwrap(); | |
exec_if_newer("ode", &format!("{}/build", out_dir), &compile_cmake); | |
exec_if_newer("ode", &format!("{}/ffi.rs", out_dir), &|| generate_bindings(&out_dir)); | |
println!("cargo:rustc-link-search={}/build", out_dir); | |
println!("cargo:rustc-link-lib=ode"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment