Skip to content

Commit eaca61a

Browse files
committed
feat: Simplify build sript (tested on linux and mac os)
1 parent 1474133 commit eaca61a

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

ui-sys/build.rs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
11
extern crate cmake;
2+
use cmake::Config;
23

34
use std::env;
45
use std::path::Path;
56
use std::process::Command;
6-
use cmake::Config;
77

88
fn main() {
9-
println!("cargo:rerun-if-changed=libui");
10-
init_git_submodule();
11-
12-
let mut cfg = Config::new("libui");
13-
if static_library() {
14-
cfg.define("BUILD_SHARED_LIBS", "OFF");
9+
if !Path::new("libui/.git").exists() {
10+
Command::new("git").args(&["submodule", "update", "--init"]).status().unwrap();
1511
}
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");
2512

26-
println!("cargo:rustc-link-search=native={}", dst.display());
27-
println!("cargo:rustc-link-lib=ui");
28-
}
13+
let target = env::var("TARGET").unwrap();
14+
let msvc = target.contains("msvc");
2915

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-
}
16+
let dst = Config::new("libui")
17+
.build_target("")
18+
.build();
3619

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");
20+
let mut postfix = Path::new("build").join("out");
21+
let libname;
22+
if msvc {
23+
postfix = postfix.join("Release");
24+
libname = "libui";
25+
} else {
26+
libname = "ui";
4327
}
28+
let dst = dst.join(&postfix);
29+
30+
println!("cargo:rustc-link-lib={}", libname);
31+
println!("cargo:rustc-link-search=native={}", dst.display());
4432
}

0 commit comments

Comments
 (0)