1
0
mirror of https://github.com/bspeice/aeron-rs synced 2024-11-12 11:08:08 -05:00
aeron-rs/aeron_driver-sys/build.rs

69 lines
1.7 KiB
Rust
Raw Normal View History

use cmake::Config;
use std::env;
use std::fs::canonicalize;
2019-09-19 23:06:37 -04:00
use std::path::{Path, PathBuf};
pub enum LinkType {
Dynamic,
2019-09-19 23:06:37 -04:00
Static,
}
impl LinkType {
fn detect() -> LinkType {
if cfg!(feature = "static") {
LinkType::Static
} else {
LinkType::Dynamic
}
}
fn link_lib(&self) -> &'static str {
match self {
LinkType::Dynamic => "dylib=",
2019-09-19 23:06:37 -04:00
LinkType::Static => "static=",
}
}
fn target_name(&self) -> &'static str {
match self {
LinkType::Dynamic => "aeron_driver",
2019-09-19 23:06:37 -04:00
LinkType::Static => "aeron_driver_static",
}
}
}
pub fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=bindings.h");
let aeron_path = canonicalize(Path::new("./aeron")).unwrap();
let header_path = aeron_path.join("aeron-driver/src/main/c");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let link_type = LinkType::detect();
2019-09-19 23:06:37 -04:00
println!(
"cargo:rustc-link-lib={}{}",
link_type.link_lib(),
link_type.target_name()
);
let lib_dir = Config::new(&aeron_path)
.build_target(link_type.target_name())
.build();
2019-09-19 23:06:37 -04:00
println!(
"cargo:rustc-link-search=native={}",
lib_dir.join("build/lib").display()
);
println!("cargo:include={}", header_path.display());
let bindings = bindgen::Builder::default()
.clang_arg(&format!("-I{}", header_path.display()))
.header("bindings.h")
.generate()
.expect("Unable to generate aeron_driver bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
2019-09-19 23:06:37 -04:00
}