54 lines
No EOL
1.5 KiB
Rust
54 lines
No EOL
1.5 KiB
Rust
use std::env;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-changed=wrapper.cpp");
|
|
println!("cargo:rerun-if-changed=wrapper.h");
|
|
|
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
|
|
if pkg_config::Config::new()
|
|
.atleast_version("0.2.0")
|
|
.probe("marisa")
|
|
.is_ok()
|
|
{
|
|
println!("cargo:rustc-link-lib=static=marisa");
|
|
} else {
|
|
println!("cargo:rustc-link-lib=static=marisa");
|
|
println!("cargo:rustc-link-search=native=/usr/local/lib");
|
|
println!("cargo:rustc-link-search=native=/usr/lib");
|
|
}
|
|
|
|
let mut build = cc::Build::new();
|
|
build
|
|
.cpp(true)
|
|
.file("wrapper.cpp")
|
|
.flag_if_supported("-std=c++17");
|
|
|
|
if let Ok(cpath) = env::var("CPATH") {
|
|
for path in cpath.split(':') {
|
|
if !path.is_empty() {
|
|
build.include(path);
|
|
}
|
|
}
|
|
}
|
|
|
|
build
|
|
.include("/usr/local/include")
|
|
.include("/usr/include");
|
|
|
|
build.compile("marisa_wrapper");
|
|
|
|
let bindings = bindgen::Builder::default()
|
|
.header("wrapper.h")
|
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
|
.rust_target(bindgen::RustTarget::Stable_1_47)
|
|
.generate_inline_functions(false)
|
|
.generate_comments(false)
|
|
.generate()
|
|
.expect("Unable to generate bindings");
|
|
|
|
bindings
|
|
.write_to_file(out_path.join("bindings.rs"))
|
|
.expect("Couldn't write bindings!");
|
|
} |