Skip to content

Commit 88500a3

Browse files
committed
ui-sys: remove cmake dependency for unix
This manually compiles libui for the unix platform, following the pattern of how the windows build was performed. This adds a dependency on pkg_config in order to find the include paths. Finally, a bug was encountered as part of the Unix build of bindgen. When using clang <= 3.8, it cannot be relied on to determine whether a symbol is C or C++. In order to disable name mangling, we must set `trust_clang_mangling(false)`. Signed-off-by: Sean Cross <[email protected]>
1 parent 836d844 commit 88500a3

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

ui-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ libc = "0.2"
5151
bindgen = "0.31"
5252
cc = "1.0"
5353
embed-resource = "1.3"
54+
pkg-config = "0.3"

ui-sys/build.rs

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate bindgen;
22
extern crate cc;
33
extern crate embed_resource;
4+
extern crate pkg_config;
45

56
use bindgen::Builder as BindgenBuilder;
67

@@ -9,6 +10,13 @@ use std::path::{Path, PathBuf};
910
use std::process::Command;
1011

1112
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+
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

Comments
 (0)