2020-09-16 18:04:18 +02:00
|
|
|
use bindgen::{Builder, CargoCallbacks};
|
2023-08-30 09:55:04 +02:00
|
|
|
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;
|
|
|
|
|
2023-08-30 09:55:04 +02:00
|
|
|
const RKVM_HAVE_ABS_PROFILE: &[u8] = b"RKVM_HAVE_ABS_PROFILE";
|
|
|
|
|
2020-09-16 18:04:18 +02:00
|
|
|
fn main() {
|
2020-11-13 18:46:12 +01:00
|
|
|
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");
|
2023-08-30 09:55:04 +02:00
|
|
|
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();
|
2023-08-30 09:55:04 +02:00
|
|
|
|
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();
|
2023-08-30 09:55:04 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|