-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
executable file
·71 lines (59 loc) · 1.85 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
67
68
69
70
71
use cc::Build;
use std::collections::HashMap;
use std::{env, path::PathBuf};
use walkdir::{DirEntry, WalkDir};
fn main() {
let h = env::current_dir().unwrap().join("mmkv/Core");
let is_release = env::var("PROFILE")
.unwrap_or(String::from("DEBUG"))
.eq("release");
println!("cargo:rustc-link-search={:?}", &h);
println!("cargo:rustc-link-lib=static=clang_rt.builtins");
println!("cargo:rerun-if-changed=wrapper.cpp");
let v = env::var("TARGET").unwrap();
let target = HashMap::from([
(
"aarch64-unknown-linux-ohos",
("aarch64-linux-ohos/c++", "aarch64-linux-ohos"),
),
(
"armv7-unknown-linux-ohos",
("arm-linux-ohos/c++/a7_softfp_neon-vfpv4", "arm-linux-ohos"),
),
(
"x86_64-unknown-linux-ohos",
("x86_64-linux-ohos/c++", "x86_64-linux-ohos"),
),
]);
let t = target.get(&v.as_str()).unwrap();
fn is_cpp_file(entry: &DirEntry) -> bool {
entry.file_type().is_file()
&& entry
.path()
.extension()
.map_or(false, |e| e == "cpp" || e == "S")
}
let cpp_files: Vec<PathBuf> = WalkDir::new(&h)
.into_iter()
.filter_map(|e| e.ok())
.filter(is_cpp_file)
.map(|i| i.into_path())
.collect();
let mut builder = Build::new();
if v.as_str() == "aarch64-unknown-linux-ohos" {
builder
.asm_flag("-x")
.asm_flag("assembler-with-cpp")
.asm_flag("-march=armv8-a+crypto");
}
builder
.define("MMKV_EMBED_ZLIB", "1")
.file("wrapper.cpp")
.files(cpp_files)
.debug(!is_release)
.cpp(true)
.include(&h)
.cpp_link_stdlib("c++_static")
.compile("native_mmkv");
napi_build_ohos::setup();
}