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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
use std::path::PathBuf;
use errors::Result;
use cpp_method::CppMethod;
use cpp_data::CppData;
pub type CppFfiGeneratorFilterFn = Fn(&CppMethod) -> Result<bool>;
struct CppFfiGeneratorFilter(Box<CppFfiGeneratorFilterFn>);
impl ::std::fmt::Debug for CppFfiGeneratorFilter {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> {
write!(f, "CppFfiGeneratorFilter")
}
}
pub type CppDataFilterFn = Fn(&mut CppData) -> Result<()>;
struct CppDataFilter(Box<CppDataFilterFn>);
impl ::std::fmt::Debug for CppDataFilter {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> {
write!(f, "CppDataFilter")
}
}
#[derive(Default, Debug)]
pub struct Config {
linked_libs: Vec<String>,
lib_paths: Vec<PathBuf>,
linked_frameworks: Vec<String>,
framework_paths: Vec<PathBuf>,
include_paths: Vec<PathBuf>,
target_include_paths: Vec<PathBuf>,
include_directives: Vec<PathBuf>,
cpp_parser_flags: Vec<String>,
cpp_compiler_flags: Vec<String>,
cpp_parser_blocked_names: Vec<String>,
cpp_ffi_generator_filters: Vec<CppFfiGeneratorFilter>,
cpp_data_filters: Vec<CppDataFilter>,
}
impl Config {
pub fn new() -> Config {
Config::default()
}
pub fn add_linked_lib<P: Into<String>>(&mut self, lib: P) {
self.linked_libs.push(lib.into());
}
pub fn add_linked_framework<P: Into<String>>(&mut self, lib: P) {
self.linked_frameworks.push(lib.into());
}
pub fn add_cpp_parser_blocked_name<P: Into<String>>(&mut self, lib: P) {
self.cpp_parser_blocked_names.push(lib.into());
}
pub fn add_cpp_parser_blocked_names<Item, Iter>(&mut self, items: Iter)
where Item: Into<String>,
Iter: IntoIterator<Item = Item>
{
for item in items {
self.cpp_parser_blocked_names.push(item.into());
}
}
pub fn add_cpp_parser_flag<P: Into<String>>(&mut self, lib: P) {
self.cpp_parser_flags.push(lib.into());
}
pub fn add_cpp_parser_flags<Item, Iter>(&mut self, items: Iter)
where Item: Into<String>,
Iter: IntoIterator<Item = Item>
{
for item in items {
self.cpp_parser_flags.push(item.into());
}
}
pub fn add_cpp_compiler_flag<P: Into<String>>(&mut self, lib: P) {
self.cpp_compiler_flags.push(lib.into());
}
pub fn add_cpp_compiler_flags<Item, Iter>(&mut self, items: Iter)
where Item: Into<String>,
Iter: IntoIterator<Item = Item>
{
for item in items {
self.cpp_compiler_flags.push(item.into());
}
}
pub fn add_include_path<P: Into<PathBuf>>(&mut self, path: P) {
self.include_paths.push(path.into());
}
pub fn add_lib_path<P: Into<PathBuf>>(&mut self, path: P) {
self.lib_paths.push(path.into());
}
pub fn add_framework_path<P: Into<PathBuf>>(&mut self, path: P) {
self.framework_paths.push(path.into());
}
pub fn add_target_include_path<P: Into<PathBuf>>(&mut self, path: P) {
self.target_include_paths.push(path.into());
}
pub fn add_include_directive<P: Into<PathBuf>>(&mut self, path: P) {
self.include_directives.push(path.into());
}
pub fn add_cpp_ffi_generator_filter(&mut self, f: Box<CppFfiGeneratorFilterFn>) {
self.cpp_ffi_generator_filters.push(CppFfiGeneratorFilter(f));
}
pub fn add_cpp_data_filter(&mut self, f: Box<CppDataFilterFn>) {
self.cpp_data_filters.push(CppDataFilter(f));
}
pub fn exec(self) -> Result<()> {
::launcher::run_from_build_script(self)
}
pub fn linked_libs(&self) -> &[String] {
&self.linked_libs
}
pub fn linked_frameworks(&self) -> &[String] {
&self.linked_frameworks
}
pub fn cpp_parser_blocked_names(&self) -> &[String] {
&self.cpp_parser_blocked_names
}
pub fn cpp_parser_flags(&self) -> &[String] {
&self.cpp_parser_flags
}
pub fn cpp_compiler_flags(&self) -> &[String] {
&self.cpp_compiler_flags
}
pub fn include_paths(&self) -> &[PathBuf] {
&self.include_paths
}
pub fn lib_paths(&self) -> &[PathBuf] {
&self.lib_paths
}
pub fn framework_paths(&self) -> &[PathBuf] {
&self.framework_paths
}
pub fn target_include_paths(&self) -> &[PathBuf] {
&self.target_include_paths
}
pub fn include_directives(&self) -> &[PathBuf] {
&self.include_directives
}
pub fn cpp_ffi_generator_filters(&self) -> Vec<&Box<CppFfiGeneratorFilterFn>> {
self.cpp_ffi_generator_filters.iter().map(|x| &x.0).collect()
}
pub fn cpp_data_filters(&self) -> Vec<&Box<CppDataFilterFn>> {
self.cpp_data_filters.iter().map(|x| &x.0).collect()
}
}