-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
54 lines (46 loc) · 1.9 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// #[cfg(feature = "foldcomp")]
// extern crate bindgen;
#[cfg(feature = "foldcomp")]
extern crate cmake;
// commented out together with bindgen
//use std::env;
//use std::path::PathBuf;
fn main() {
#[cfg(feature = "foldcomp")]
{
let dst = cmake::Config::new("lib/foldcomp")
.define("BUILD_FFI", "ON")
.build_target("foldcomp_ffi")
.build();
println!("cargo:rustc-link-search=native={}/build", dst.display());
println!("cargo:rustc-link-lib=static=foldcomp_ffi");
// println!("cargo:rustc-link-lib=c++"); // TODO: FIXME
// Determine the platform and link the appropriate C++ standard library
if cfg!(target_os = "windows") {
println!("cargo:rustc-link-lib=dylib=foldcomp_ffi");
println!("cargo:rustc-link-lib=dylib=msvcrt");
} else if cfg!(target_os = "macos") {
println!("cargo:rustc-link-lib=static=foldcomp_ffi");
println!("cargo:rustc-link-lib=dylib=c++");
} else if cfg!(target_os = "linux") {
// Detect the C++ compiler used by CMake and link the appropriate standard library
let cxx_compiler = std::env::var("CXX").unwrap_or_else(|_| "c++".to_string());
if cxx_compiler.contains("clang") {
println!("cargo:rustc-link-lib=static=foldcomp_ffi");
println!("cargo:rustc-link-lib=dylib=c++");
} else {
println!("cargo:rustc-link-lib=static=foldcomp_ffi");
println!("cargo:rustc-link-lib=dylib=stdc++");
}
}
// Generate bindings. If regeneration is needed, uncomment the following code
// let bindings = bindgen::Builder::default()
// .header("lib/foldcomp/foldcompffi.h")
// .generate()
// .expect("Unable to generate bindings");
// let out_path = PathBuf::from("lib/foldcomp");
// bindings
// .write_to_file(out_path.join("bindings.rs"))
// .expect("Couldn't write bindings!");
}
}