-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
57 lines (51 loc) · 1.92 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
55
56
57
use std::env;
// This code is adapted from pkg-config-rs
// (https://github.com/rust-lang/pkg-config-rs).
fn infer_static(name: &str) -> bool {
#[allow(clippy::if_same_then_else, clippy::needless_bool)]
if env::var(format!("{}_STATIC", name.to_uppercase())).is_ok() {
true
} else if env::var(format!("{}_DYNAMIC", name.to_uppercase())).is_ok() {
false
} else if env::var("PKG_CONFIG_ALL_STATIC").is_ok() {
true
} else if env::var("PKG_CONFIG_ALL_DYNAMIC").is_ok() {
false
} else {
false
}
}
fn main() {
// Gather build time info
built::write_built_file().expect("Failed to acquire build-time information");
//
// Link to shared or static CFITSIO
//
// Check if we have this environment variable
// If we do, then we will link to cfitsio statically
// But if so, you need to have:
// 1. libcfitsio.a in your LD_LIBRARY_PATH or PATH
// AND
// 2. libcfitsio.a needs to have been built with the following ./configure statement:
// ./configure --disable-curl --prefix=/usr/local --enable-reentrant
if env::var("MWALIB_LINK_STATIC_CFITSIO") == Ok("1".to_string()) || infer_static("cfitsio") {
println!("cargo:rustc-link-lib=static=cfitsio");
}
// Only do this if we're not on docs.rs (doesn't like writing files outside
// of OUT_DIR).
match env::var("DOCS_RS").as_deref() {
Ok("1") => (),
_ => {
let mut config: cbindgen::Config = cbindgen::Config::default();
config.cpp_compat = true;
config.pragma_once = true;
cbindgen::Builder::new()
.with_config(config)
.with_crate(env::var("CARGO_MANIFEST_DIR").unwrap())
.with_language(cbindgen::Language::C)
.generate()
.expect("Unable to generate bindings")
.write_to_file("include/mwalib.h");
}
}
}