Skip to content

Commit 859e178

Browse files
committed
Granularize ui-sys building.
It's now possible to pull and build (default), build from the current sources without pulling (--features="build"), or not build at all, in which case a copy of `libui.so` must exist in ui-sys/lib or be available in a standard shared library search location. Closes #8
1 parent 56bf1f2 commit 859e178

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ fn main() {
8989
}
9090
```
9191

92+
## Building ui-sys
93+
94+
`ui-sys` includes `libui` as a sub-module and allows it to be built on-the-fly with the
95+
default features `fetch` and `build. With `fetch disabled, it will simply build the
96+
existing sources without updating them, and with `build` disabled it will build nothing,
97+
assuming either a system or local (in `./lib/`) version of `libui` is available.
98+
99+
Note that _most of the time_, building `libui` on the fly is what you want. It does however
100+
require a copy of cmake, essential build tools, et cetera.
101+
92102
## Testing Note
93103
Travis does not connect video devices to their testing environments, so the tests cannot be run. Therefore, the "tests" only check compilation.
94104

ui-sys/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/

ui-sys/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
name = "ui-sys"
33
version = "0.1.2"
44
authors = ["Leo Tindall <[email protected]>", "Patrick Walton <[email protected]>"]
5-
build = "build.rs"
65
license = "MIT"
76
description = "Native bindings to the minimalist, cross-platform, widget set `libui`"
87

@@ -28,6 +27,9 @@ keywords = ["windows", "gtk", "gui", "user_interface", "macos"]
2827
# they must match exactly.
2928
categories = ["gui", "os::macos-apis", "os::unix-apis", "os::windows-apis"]
3029

30+
links = "ui"
31+
build = "build.rs"
32+
3133
[badges]
3234
# Travis CI: `repository` in format "<user>/<project>" is required.
3335
# `branch` is optional; default is `master`
@@ -41,6 +43,12 @@ is-it-maintained-open-issues = { repository = "LeoTindall/libui-rs" }
4143

4244
maintenance = { status = "actively-developed" }
4345

46+
[features]
47+
default = ["fetch", "build"]
48+
49+
fetch = []
50+
build = []
51+
4452
[dependencies]
4553
libc = "0.2"
4654

ui-sys/build.rs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,52 @@ use std::path::Path;
66
use std::process::Command;
77

88
fn main() {
9-
// Update the submodule with libui if needed
10-
if !Path::new("libui/.git").exists() {
11-
Command::new("git").args(&["version"]).status().expect("Git does not appear to be installed. Git is required to build ui-sys; install Git or build ui-sys independently. Error");
12-
Command::new("git").args(&["submodule", "update", "--init"]).status().expect("Unable to update Git submodules. Error");
13-
} else {
14-
Command::new("git").args(&["submodule", "update", "--recursive"]).status().expect("Unable to update Git submodules. Error");
9+
// Fetch the submodule if needed
10+
if cfg!(feature = "fetch") {
11+
// Init or update the submodule with libui if needed
12+
if !Path::new("libui/.git").exists() {
13+
Command::new("git")
14+
.args(&["version"])
15+
.status()
16+
.expect("Git does not appear to be installed. Error");
17+
Command::new("git")
18+
.args(&["submodule", "update", "--init"])
19+
.status()
20+
.expect("Unable to init libui submodule. Error");
21+
} else {
22+
Command::new("git")
23+
.args(&["submodule", "update", "--recursive"])
24+
.status()
25+
.expect("Unable to update libui submodule. Error");
26+
}
1527
}
1628

17-
let target = env::var("TARGET").unwrap();
18-
let msvc = target.contains("msvc");
29+
// Build libui if needed. Otherwise, assume it's in lib/
30+
let mut dst;
31+
let mut msvc = false;
32+
if cfg!(feature = "build") {
33+
dst = Config::new("libui").build_target("").build();
34+
// Deterimine if we're building for MSVC
35+
let target = env::var("TARGET").unwrap();
36+
msvc = target.contains("msvc");
1937

20-
let dst = Config::new("libui")
21-
.build_target("")
22-
.build();
38+
let mut postfix = Path::new("build").join("out");
39+
if msvc {
40+
postfix = postfix.join("Release");
41+
}
42+
dst = dst.join(&postfix);
43+
} else {
44+
dst = env::current_dir()
45+
.expect("Unable to retrieve current directory location.");
46+
dst.push("lib");
47+
}
48+
println!("cargo:rustc-link-search=native={}", dst.display());
2349

24-
let mut postfix = Path::new("build").join("out");
2550
let libname;
26-
if msvc {
27-
postfix = postfix.join("Release");
51+
if msvc {
2852
libname = "libui";
2953
} else {
3054
libname = "ui";
3155
}
32-
let dst = dst.join(&postfix);
33-
3456
println!("cargo:rustc-link-lib={}", libname);
35-
println!("cargo:rustc-link-search=native={}", dst.display());
3657
}

0 commit comments

Comments
 (0)