rkvm/rkvm-input/build.rs

52 lines
1.4 KiB
Rust
Raw Permalink Normal View History

2020-09-16 18:04:18 +02:00
use bindgen::{Builder, CargoCallbacks};
use cc::Build;
2021-01-11 21:47:14 +01:00
use pkg_config::Config;
2020-09-16 18:04:18 +02:00
use std::env;
use std::path::PathBuf;
const RKVM_HAVE_ABS_PROFILE: &[u8] = b"RKVM_HAVE_ABS_PROFILE";
2020-09-16 18:04:18 +02:00
fn main() {
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
"windows" => return,
"linux" => {}
_ => panic!("Unsupported target OS"),
}
2020-10-25 18:35:50 +01:00
println!("cargo:rerun-if-changed=glue/glue.h");
println!("cargo:rerun-if-changed=glue/check.h");
2020-09-16 18:04:18 +02:00
2021-01-11 21:47:14 +01:00
let library = Config::new()
2021-01-31 13:39:37 +01:00
.atleast_version("1.9.0")
2021-01-11 21:47:14 +01:00
.probe("libevdev")
.unwrap();
2021-01-11 21:47:14 +01:00
let args = library
.include_paths
.iter()
.map(|path| format!("-I{}", path.as_os_str().to_str().unwrap()));
2020-09-16 18:04:18 +02:00
let bindings = Builder::default()
2020-10-25 18:35:50 +01:00
.header("glue/glue.h")
2021-01-11 21:47:14 +01:00
.clang_args(args)
2020-09-16 18:04:18 +02:00
.parse_callbacks(Box::new(CargoCallbacks))
.generate()
.unwrap();
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
2020-10-25 18:35:50 +01:00
bindings.write_to_file(out_path.join("glue.rs")).unwrap();
// Check for RKVM_ABS_PROFILE, which was added in v6.1-rc1.
let expanded = Build::new()
.file("glue/check.h")
.includes(library.include_paths)
.expand();
if expanded
.windows(RKVM_HAVE_ABS_PROFILE.len())
.any(|window| window == RKVM_HAVE_ABS_PROFILE)
{
println!("cargo:rustc-cfg=have_abs_profile");
}
2020-09-16 18:04:18 +02:00
}