-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
121 lines (102 loc) · 5.35 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::ffi::OsStr;
// look up an environment variable and prefix its value to a given path
pub fn with_dir(dir : &str, path : &str) -> String {
let dir_os_string = OsStr::new(dir);
let path_os_string = OsStr::new(path);
let full_path = PathBuf::from(env::var(dir_os_string).unwrap());
String::from(full_path.join(path_os_string).to_str().unwrap())
}
// look up an environment variable and prefix its value to a given path,
// resulting in an include "-IPATH"
pub fn with_include(dir : &str, path : &str) -> String {
let dir_os_string = OsStr::new(dir);
let path_os_string = OsStr::new(path);
let full_path = PathBuf::from(env::var(dir_os_string).unwrap());
let joined_path = String::from(full_path.join(path_os_string).to_str().unwrap());
let mut include = "-I".to_string();
include.push_str(&joined_path);
include
}
// look up an environment variable and turn its value into an include "-I"
pub fn as_include(dir : &str) -> String {
let dir_os_string = OsStr::new(dir);
let full_path = PathBuf::from(env::var(dir_os_string).unwrap());
let mut include = "-I".to_string();
include.push_str(&full_path.to_str().unwrap());
println!("{}", include.as_str());
include
}
fn main() {
let bindings = bindgen::Builder::default()
// CFE Mission Includes
.header(with_dir("CFS_MISSION", "build/mission_inc/cfe_mission_cfg.h"))
// CFE Platform Includes
.header(with_dir("CFE_FSW", "platform_inc/cpu1/cfe_msgids.h"))
.header(with_dir("CFE_FSW", "platform_inc/cpu1/cfe_platform_cfg.h"))
// CFE Includes
.header(with_dir("CFE_CORE_SRC", "inc/ccsds.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_error.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_es_events.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_es.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_es_msg.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_es_perfids.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_evs_events.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_evs.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_evs_msg.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_fs.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_sb_events.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_sb.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_sb_msg.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_tbl_events.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_tbl_filedef.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_tbl.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_tbl_msg.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_time_events.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_time.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_time_msg.h"))
.header(with_dir("CFE_CORE_SRC", "inc/cfe_version.h"))
.header(with_dir("CFE_CORE_SRC", "inc/network_includes.h"))
// PSP Includes
.header(with_dir("PSP_DIR", "fsw/inc/cfe_psp_configdata.h"))
.header(with_dir("PSP_DIR", "fsw/inc/cfe_psp.h"))
.header(with_dir("PSP_DIR", "fsw/pc-linux/inc/cfe_psp_config.h"))
.header(with_dir("PSP_DIR", "fsw/pc-linux/inc/psp_version.h"))
// OSAL Includes
.header(with_dir("OSAL_DIR", "src/os/inc/common_types.h"))
.header(with_dir("OSAL_DIR", "src/os/inc/osapi.h"))
.header(with_dir("OSAL_DIR", "src/os/inc/osapi-os-core.h"))
.header(with_dir("OSAL_DIR", "src/os/inc/osapi-os-filesys.h"))
.header(with_dir("OSAL_DIR", "src/os/inc/osapi-os-loader.h"))
.header(with_dir("OSAL_DIR", "src/os/inc/osapi-os-net.h"))
.header(with_dir("OSAL_DIR", "src/os/inc/osapi-os-timer.h"))
.header(with_dir("OSAL_DIR", "src/os/inc/osapi-version.h"))
// Clang Arguments
// Include Path CFE
.clang_arg(with_include("CFE_CORE_SRC", "fsw/cfe-core/src/inc"))
.clang_arg(as_include("CFS_MISSION_INC"))
.clang_arg(with_include("CFS_MISSION", "build/mission_inc"))
.clang_arg(with_include("CFE_CORE_SRC", "fsw/platform_inc/cpu1"))
.clang_arg(with_include("CFS_MISSION", "build/cpu1/inc"))
// Include Path PSP
.clang_arg(with_include("PSP_DIR", "fsw/inc"))
.clang_arg(with_include("PSP_DIR", "fsw/pc-linux/inc"))
// Include Path OSAL
.clang_arg(with_include("OSAL_DIR", "src/os/inc"))
.clang_arg(with_include("OSAL_DIR", "src/bsp/pc-linux/config"))
// Define operating system for network_includes.h in CFE
.clang_arg("-D_LINUX_OS_")
// This should generate functions from macros with arguments, but
// does not. I'm not sure what is wrong here.
.generate_inline_functions(true)
.generate()
.expect("Unable to generate bindings!");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
// write out bindings to the source directory, where they are re-exported.
//bindings.write_to_file("src/bindings.rs").expect("Couldn't write bindings");
bindings.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings");
}