11extern crate bindgen;
22extern crate cc;
33extern crate embed_resource;
4+ extern crate pkg_config;
45
56use bindgen:: Builder as BindgenBuilder ;
67
@@ -9,6 +10,13 @@ use std::path::{Path, PathBuf};
910use std:: process:: Command ;
1011
1112fn 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+
1220 // Fetch the submodule if needed
1321 if cfg ! ( feature = "fetch" ) {
1422 // Init or update the submodule with libui if needed
@@ -34,6 +42,7 @@ fn main() {
3442 . header ( "wrapper.h" )
3543 . opaque_type ( "max_align_t" ) // For some reason this ends up too large
3644 //.rustified_enum(".*")
45+ . trust_clang_mangling ( false ) // clang sometimes wants to treat these functions as C++
3746 . generate ( )
3847 . expect ( "Unable to generate bindings" ) ;
3948
@@ -42,17 +51,12 @@ fn main() {
4251 . write_to_file ( out_path. join ( "bindings.rs" ) )
4352 . expect ( "Couldn't write bindings" ) ;
4453
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-
5154 // Build libui if needed. Otherwise, assume it's in lib/
5255 if cfg ! ( feature = "build" ) {
5356 let mut base_config = cc:: Build :: new ( ) ;
5457 let src_base = env:: var ( "SRC_BASE" ) . unwrap_or ( "libui" . to_string ( ) ) ;
5558
59+ // Add source files that are common to all platforms
5660 base_config. include ( format ! ( "{}{}" , src_base, "/common" ) ) ;
5761
5862 base_config. file ( format ! ( "{}{}" , src_base, "/common/attribute.c" ) ) ;
@@ -158,10 +162,68 @@ fn main() {
158162 link ( "oleacc" , false ) ;
159163 link ( "uuid" , false ) ;
160164 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" ) ) ;
161217 }
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`.
162223 base_config. compile ( "libui.a" ) ;
163224 } 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/`
165227 let mut dst = env:: current_dir ( ) . expect ( "Unable to retrieve current directory location." ) ;
166228 dst. push ( "lib" ) ;
167229
0 commit comments