-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
67 lines (54 loc) · 2.2 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
58
59
60
61
62
63
64
65
66
67
extern crate bindgen;
extern crate pkg_config;
use std::env;
use std::path::PathBuf;
fn main() {
let srslte_dir = {
let dir = env::var("SRSLTE_DIR").expect(
"Please set environment variable SRSLTE_DIR to point at the built version of srslte",
);
let p = PathBuf::from(dir);
assert!(
p.is_dir() && p.exists(),
"The given SRSLTE_DIR is not a valid directory"
);
p
};
let bindings_out = PathBuf::from(env::var("OUT_DIR").unwrap()).join("srslte_bindings.rs");
let libdir = srslte_dir.join("lib/");
let include_dir = srslte_dir.join("include/");
let main_header = include_dir.join("srslte/srslte.h");
let rf_header = include_dir.join("srslte/phy/rf/rf.h");
//if the header does not exist assume we need to rebuild
let bindings = bindgen::Builder::default()
.header(format!("{}", main_header.display()))
.header(format!("{}", rf_header.display()))
.clang_arg(format!("-I{}", include_dir.display()))
.blacklist_type("FP_NORMAL")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.constified_enum_module("*")
.generate()
.expect("Unable to generate bindings");
//spit the bindings into a file
bindings
.write_to_file(bindings_out)
.expect("Couldn't write bindings!");
// add the bindings dir to the linker path
println!("cargo:rustc-link-search=native={}", libdir.display());
// link volk of installed (assumes srslte is built with it)
if pkg_config::probe_library("volk").is_ok() {
println!("cargo:rustc-flags=-l dylib=volk");
}
// binding linking doesnt work, must do it this way
println!("cargo:rustc-flags=-l dylib=srslte_phy");
// link fftw3/f (as demanded by phy)
pkg_config::probe_library("fftw3").expect("Failed to find fftw3; is it installed?");
pkg_config::probe_library("fftw3f").expect("Failed to find fftw3; is it installed?");
println!("cargo:rustc-flags=-l dylib=srslte_common");
if cfg!(feature = "srslte_rf") {
println!("cargo:rustc-flags=-l dylib=srslte_rf");
}
}