-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
67 lines (60 loc) · 2.23 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;
use bindgen::EnumVariation;
use std::env;
use std::path::PathBuf;
use EnumVariation::NewType;
extern crate simple_logger;
fn main() {
simple_logger::init_by_env();
let is_test = env::var("CARGO_CFG_TEST").is_ok();
let target = if is_test {
println!("cargo:rustc-cfg=TARGET[=\"x86_64-pc-windows-msvc\"]");
"thumbv7em-none-eabihf".into()
} else {
env::var("TARGET").unwrap()
};
let config_dir = env::var("RT_CONFIG_DIR").unwrap_or("./".to_owned());
let rt_thread_root = PathBuf::from(env::var_os("RTT_ROOT").unwrap_or("rt-thread".into()));
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
.use_core()
// The input header we would like to generate
// bindings for.
.header("rt-thread/include/rtthread.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.default_enum_style(NewType { is_bitfield: false })
.ctypes_prefix("cty")
.detect_include_paths(false)
.clang_args(vec![
"-ffreestanding",
"-target",
&target,
"-isystem",
&config_dir,
"-isystem",
rt_thread_root.join("include").to_str().unwrap(),
"-isystem",
rt_thread_root.join("components/finsh").to_str().unwrap(),
"-isystem",
rt_thread_root
.join("components/libc/compilers/minilibc")
.to_str()
.unwrap(),
"-DRT_USING_MINILIBC",
])
.blacklist_item("rt_v.*printf")
.blacklist_item(".*va_list.*")
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}