forked from ArchLeaders/roead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
66 lines (64 loc) · 2.22 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::path::Path;
use std::env;
#[cfg(feature = "yaz0")]
fn build_zlib() {
let target = env::var("TARGET").unwrap();
let mut cmake = std::process::Command::new("cmake");
cmake.current_dir("lib/zlib-ng");
if target.contains("aarch64-apple-darwin") {
cmake.arg("-DCMAKE_OSX_ARCHITECTURES=arm64");
} else if target.contains("x86_64-apple-darwin") {
cmake.arg("-DCMAKE_OSX_ARCHITECTURES=x86_64");
} else {
//Not OSX
}
cmake.arg(".")
.output()
.expect("Failed to build zlib. Is CMake installed?");
std::process::Command::new("cmake")
.current_dir("lib/zlib-ng")
.arg("--build")
.arg(".")
.output()
.expect("Failed to build zlib");
}
#[cfg(feature = "yaz0")]
fn main() {
build_zlib();
let mut builder = cxx_build::bridge("src/yaz0.rs");
builder
.file("src/yaz0.cpp")
.flag("-w")
.flag_if_supported("-std=c++17")
.include("src/include")
.include("lib/nonstd")
.include("lib/zlib-ng")
.flag_if_supported("-static");
if cfg!(windows) {
builder
.flag_if_supported("/std:c++17")
.flag_if_supported("/W4")
.flag_if_supported("/wd4244")
.flag_if_supported("/wd4127")
.flag_if_supported("/Zc:__cplusplus");
println!("cargo:rustc-link-search=native=lib/zlib-ng/Debug");
println!("cargo:rustc-link-search=native=lib/zlib-ng/Release");
println!("cargo:rustc-link-lib=static=zlibd");
} else {
builder
.flag_if_supported("-fcolor-diagnostics")
.flag_if_supported("-Wall")
.flag_if_supported("-Wextra")
.flag_if_supported("-fno-plt");
println!("cargo:rustc-link-lib=static=zlib");
}
builder.compile("roead");
println!("cargo:rerun-if-changed=src/include/oead");
println!("cargo:rerun-if-changed=src/yaz0.rs");
println!("cargo:rerun-if-changed=src/yaz0.cpp");
println!("cargo:rerun-if-changed=src/include/oead/yaz0.h");
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rustc-link-search=native={}", Path::new(&dir).join("lib/zlib-ng").display());
}
#[cfg(not(feature = "yaz0"))]
fn main() {}