yacexits/build.rs

47 lines
1.1 KiB
Rust

/*
* Copyright (c) 2023 YAC
* SPDX-License-Identifier: FSFAP
*
* Copying and distribution of this file, with or without modification, are
* permitted in any medium without royalty provided the copyright notice and
* this notice are preserved. This file is offered as-is, without any warranty.
*/
extern crate bindgen;
use std::env;
use std::path::{ Path, PathBuf };
fn main() {
let mut header = String::new();
let home = match env::var("HOME") {
Ok(val) => val,
Err(error) => {
eprintln!("{}", error);
"/home/include/".to_string()
},
};
for file in [
format!("{}/include/sysexits.h", home),
"/usr/local/include/sysexits.h".to_string(),
"/usr/include/sysexits.h".to_string()
] {
if Path::new(&file).is_file() {
header = file;
break;
}
}
let bindings = bindgen::Builder::default()
.header(&header)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.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!");
}