Skip to content

Commit 4fdb5dc

Browse files
committed
Simplify build script by using cmake-rs
also adds capability to compile a static libui.a
1 parent 1d2c4e8 commit 4fdb5dc

File tree

2 files changed

+36
-45
lines changed

2 files changed

+36
-45
lines changed

ui-sys/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ui-sys"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Patrick Walton <[email protected]>"]
55
build = "build.rs"
66
license = "MIT/Apache 2.0"
@@ -10,5 +10,4 @@ description = "Native bindings to the minimalist, cross-platform, widget set `li
1010
libc = "0.2"
1111

1212
[build-dependencies]
13-
make-cmd = "0.1"
14-
13+
cmake = "0.1"

ui-sys/build.rs

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,44 @@
1-
extern crate make_cmd;
1+
extern crate cmake;
22

33
use std::env;
4-
use std::path::{Path, PathBuf};
4+
use std::path::Path;
55
use std::process::Command;
6-
use std::fs::{self, File};
7-
use std::io::Write;
6+
use cmake::Config;
87

98
fn main() {
109
println!("cargo:rerun-if-changed=libui");
11-
if !Path::new("libui/.git").exists() {
12-
Command::new("git").args(&["submodule", "update", "--init"]).status().expect("Could not update libui submodule");
13-
}
14-
15-
let cwd = env::current_dir().unwrap();
16-
17-
let libui_path = cwd.join("libui");
18-
env::set_current_dir(&libui_path).expect("Could not change dir");
19-
20-
// Run CMake
21-
//let cmake_cache_path = (&libui_path).join("CMakeCache.txt");
22-
//if cmake_cache_path.exists() {
23-
// fs::remove_file(cmake_cache_path).expect("Could not remove cmake cache");
24-
//}
25-
Command::new("cmake").arg(".").output().expect("cmake failed");
26-
27-
// Run Make
28-
let libui_out_path = (&libui_path).join("out");
29-
if ! libui_out_path.exists() {
30-
println!("Creating out dir");
31-
fs::create_dir(&libui_out_path).expect("Could not create out dir");
32-
}
33-
make_cmd::gnu_make().status().expect("Make failed");
34-
35-
// Copy the output to the build folder
36-
let out_dir = env::var("OUT_DIR").unwrap();
37-
let out_path = Path::new(&out_dir);
38-
for entry in fs::read_dir(&libui_out_path).unwrap() {
39-
let entry = entry.expect("IO error while reading");
40-
let name = entry.file_name();
41-
let target = out_path.join(name);
42-
fs::copy(&entry.path(), &target).expect("Could not copy file");
43-
println!("Copying file from {} to {}", entry.path().display(), target.display());
10+
init_git_submodule();
11+
12+
let mut cfg = Config::new("libui");
13+
if static_library() {
14+
cfg.define("BUILD_SHARED_LIBS", "OFF");
4415
}
45-
16+
let mut dst = cfg.build_target("all").build();
17+
18+
dst.push("build");
19+
dst.push("out");
20+
21+
// Without explicit notion of Appkit,
22+
// compilation of static binary fails
23+
#[cfg(target_os="macos")]
24+
println!("cargo:rustc-link-lib=framework=Appkit");
4625

47-
// Configure cargo
48-
println!("cargo:rustc-link-lib=dylib=ui");
49-
println!("cargo:rustc-link-search={}", out_dir);
50-
//panic!();
26+
println!("cargo:rustc-link-search=native={}", dst.display());
27+
println!("cargo:rustc-link-lib=ui");
5128
}
5229

30+
fn static_library() -> bool {
31+
// env::var_os("STATIC")
32+
// .map(|v| v.to_str() == Some("1"))
33+
// .unwrap_or(false)
34+
true
35+
}
36+
37+
fn init_git_submodule() {
38+
if !Path::new("libui/.git").exists() {
39+
let cwd = env::current_dir().unwrap();
40+
env::set_current_dir(&cwd.parent().unwrap()).expect("Could not change dir");
41+
Command::new("git").args(&["submodule", "update", "--init"]).status().expect("Could not update libui submodule");
42+
env::set_current_dir(&cwd).expect("Could not change dir");
43+
}
44+
}

0 commit comments

Comments
 (0)