1
1
extern crate bindgen;
2
2
extern crate cc;
3
3
extern crate embed_resource;
4
+ extern crate pkg_config;
4
5
5
6
use bindgen:: Builder as BindgenBuilder ;
6
7
@@ -9,6 +10,13 @@ use std::path::{Path, PathBuf};
9
10
use std:: process:: Command ;
10
11
11
12
fn main ( ) {
13
+ // Deterimine build platform
14
+ let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
15
+ let target_triple = env:: var ( "TARGET" ) . unwrap ( ) ;
16
+ let msvc = target_triple. contains ( "msvc" ) ;
17
+ let apple = target_triple. contains ( "apple" ) ;
18
+ let unix = cfg ! ( target_family = "unix" ) && !apple;
19
+
12
20
// Fetch the submodule if needed
13
21
if cfg ! ( feature = "fetch" ) {
14
22
// Init or update the submodule with libui if needed
@@ -34,6 +42,7 @@ fn main() {
34
42
. header ( "wrapper.h" )
35
43
. opaque_type ( "max_align_t" ) // For some reason this ends up too large
36
44
//.rustified_enum(".*")
45
+ . trust_clang_mangling ( false ) // clang sometimes wants to treat these functions as C++
37
46
. generate ( )
38
47
. expect ( "Unable to generate bindings" ) ;
39
48
@@ -42,17 +51,12 @@ fn main() {
42
51
. write_to_file ( out_path. join ( "bindings.rs" ) )
43
52
. expect ( "Couldn't write bindings" ) ;
44
53
45
- // Deterimine build platform
46
- let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
47
- let target_triple = env:: var ( "TARGET" ) . unwrap ( ) ;
48
- let msvc = target_triple. contains ( "msvc" ) ;
49
- let apple = target_triple. contains ( "apple" ) ;
50
-
51
54
// Build libui if needed. Otherwise, assume it's in lib/
52
55
if cfg ! ( feature = "build" ) {
53
56
let mut base_config = cc:: Build :: new ( ) ;
54
57
let src_base = env:: var ( "SRC_BASE" ) . unwrap_or ( "libui" . to_string ( ) ) ;
55
58
59
+ // Add source files that are common to all platforms
56
60
base_config. include ( format ! ( "{}{}" , src_base, "/common" ) ) ;
57
61
58
62
base_config. file ( format ! ( "{}{}" , src_base, "/common/attribute.c" ) ) ;
@@ -158,10 +162,68 @@ fn main() {
158
162
link ( "oleacc" , false ) ;
159
163
link ( "uuid" , false ) ;
160
164
link ( "windowscodecs" , false ) ;
165
+ } else if unix {
166
+ base_config. include ( format ! ( "{}{}" , src_base, "/unix" ) ) ;
167
+
168
+ let pkg_cfg = pkg_config:: Config :: new ( ) . probe ( "gtk+-3.0" ) . unwrap ( ) ;
169
+ for inc in pkg_cfg. include_paths {
170
+ base_config. include ( inc) ;
171
+ }
172
+
173
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/alloc.c" ) ) ;
174
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/area.c" ) ) ;
175
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/attrstr.c" ) ) ;
176
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/box.c" ) ) ;
177
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/button.c" ) ) ;
178
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/cellrendererbutton.c" ) ) ;
179
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/checkbox.c" ) ) ;
180
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/child.c" ) ) ;
181
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/colorbutton.c" ) ) ;
182
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/combobox.c" ) ) ;
183
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/control.c" ) ) ;
184
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/datetimepicker.c" ) ) ;
185
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/debug.c" ) ) ;
186
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/draw.c" ) ) ;
187
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/drawmatrix.c" ) ) ;
188
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/drawpath.c" ) ) ;
189
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/drawtext.c" ) ) ;
190
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/editablecombo.c" ) ) ;
191
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/entry.c" ) ) ;
192
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/fontbutton.c" ) ) ;
193
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/fontmatch.c" ) ) ;
194
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/form.c" ) ) ;
195
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/future.c" ) ) ;
196
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/graphemes.c" ) ) ;
197
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/grid.c" ) ) ;
198
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/group.c" ) ) ;
199
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/image.c" ) ) ;
200
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/label.c" ) ) ;
201
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/main.c" ) ) ;
202
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/menu.c" ) ) ;
203
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/multilineentry.c" ) ) ;
204
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/opentype.c" ) ) ;
205
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/progressbar.c" ) ) ;
206
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/radiobuttons.c" ) ) ;
207
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/separator.c" ) ) ;
208
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/slider.c" ) ) ;
209
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/spinbox.c" ) ) ;
210
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/stddialogs.c" ) ) ;
211
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/tab.c" ) ) ;
212
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/table.c" ) ) ;
213
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/tablemodel.c" ) ) ;
214
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/text.c" ) ) ;
215
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/util.c" ) ) ;
216
+ base_config. file ( format ! ( "{}{}" , src_base, "/unix/window.c" ) ) ;
161
217
}
218
+
219
+ // Link everything together into `libui.a`. This will get linked
220
+ // together because of the `links="ui"` flag in the `Cargo.toml` file,
221
+ // and because the `.compile()` function emits
222
+ // `cargo:rustc-link-lib=static=ui`.
162
223
base_config. compile ( "libui.a" ) ;
163
224
} else {
164
- // If we're not building the library, then assume it's pre-built and exists in `lib/`
225
+ // If we're not building the library, then assume it's pre-built and
226
+ // exists in `lib/`
165
227
let mut dst = env:: current_dir ( ) . expect ( "Unable to retrieve current directory location." ) ;
166
228
dst. push ( "lib" ) ;
167
229
0 commit comments