-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
211 lines (197 loc) · 6.49 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
extern crate napi_build;
use std::env;
use std::path;
use std::process;
fn main() {
println!("cargo:rerun-if-env-changed=SKIA_DIR");
println!("cargo:rerun-if-env-changed=SKIA_LIB_DIR");
println!("cargo:rerun-if-changed=skia-c/skia_c.cpp");
println!("cargo:rerun-if-changed=skia-c/skia_c.hpp");
let compile_target = env::var("TARGET").expect("TARGET");
let compile_target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS");
let compile_target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV");
let compile_target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH");
match compile_target_os.as_str() {
"windows" => {
env::set_var("CC", "clang-cl");
env::set_var("CXX", "clang-cl");
}
_ => {
env::set_var("CC", "clang");
env::set_var("CXX", "clang++");
}
}
let skia_dir = env::var("SKIA_DIR").unwrap_or_else(|_| "./skia".to_owned());
let skia_path = path::Path::new(&skia_dir);
let skia_lib_dir = env::var("SKIA_LIB_DIR").unwrap_or_else(|_| "./skia/out/Static".to_owned());
let mut build = cc::Build::new();
build.cpp(true).file("skia-c/skia_c.cpp");
match compile_target.as_str() {
"aarch64-unknown-linux-musl" => {
let gcc_version = String::from_utf8(
process::Command::new("ls")
.arg("/aarch64-linux-musl-cross/aarch64-linux-musl/include/c++")
.output()
.unwrap()
.stdout,
)
.unwrap();
let gcc_version_trim = gcc_version.trim();
build
.flag("--sysroot=/aarch64-linux-musl-cross/aarch64-linux-musl")
.flag("--gcc-toolchain=aarch64-linux-musl-gcc")
.include("/aarch64-linux-musl-cross/aarch64-linux-musl/include")
.include(format!(
"/aarch64-linux-musl-cross/aarch64-linux-musl/include/c++/{}",
gcc_version_trim
))
.include(format!(
"/aarch64-linux-musl-cross/aarch64-linux-musl/include/c++/{}/aarch64-linux-musl",
gcc_version_trim
));
}
"armv7-unknown-linux-gnueabihf" => {
build
.flag("--sysroot=/usr/arm-linux-gnueabihf")
.flag("--gcc-toolchain=arm-linux-gnueabihf-gcc")
.include("/usr/arm-linux-gnueabihf/include/c++/7")
.include("/usr/arm-linux-gnueabihf/include/c++/7/arm-linux-gnueabihf");
}
"x86_64-unknown-linux-musl" => {
let gcc_version = String::from_utf8(
process::Command::new("ls")
.arg("/usr/include/c++")
.output()
.unwrap()
.stdout,
)
.unwrap();
let gcc_version_trim = gcc_version.trim();
build
.static_flag(true)
.include("/usr/include")
.include(format!("/usr/include/c++/{}", gcc_version_trim))
.include(format!(
"/usr/include/c++/{}/x86_64-alpine-linux-musl",
gcc_version_trim
));
}
"aarch64-apple-darwin" => {
build.target("arm64-apple-macos");
}
"aarch64-linux-android" => {
let nkd_home = env::var("ANDROID_NDK_LATEST_HOME").unwrap();
env::set_var(
"CC",
format!(
"{}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang",
nkd_home
)
.as_str(),
);
env::set_var(
"CXX",
format!(
"{}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++",
nkd_home
)
.as_str(),
);
build
.include(
format!(
"{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
nkd_home
)
.as_str(),
)
.include(
format!(
"{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1",
nkd_home
)
.as_str(),
)
.include(
format!(
"{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android",
nkd_home
)
.as_str(),
)
.archiver(
format!(
"{}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar",
nkd_home
)
.as_str(),
);
}
_ => {}
}
if compile_target_os != "windows" {
build
.flag("-std=c++17")
.flag("-fPIC")
.flag("-fno-exceptions")
.flag("-fno-rtti")
.flag("-fstrict-aliasing")
.flag("-fvisibility=hidden")
.flag("-fvisibility-inlines-hidden")
.flag("-fdata-sections")
.flag("-ffunction-sections")
.flag("-Wno-unused-function")
.flag("-Wno-unused-parameter");
}
match compile_target_os.as_str() {
"windows" => {
build
.flag("/std:c++17")
.flag("-Wno-unused-function")
.flag("-Wno-unused-parameter")
.static_crt(true);
}
"linux" => {
if compile_target_env != "gnu"
|| (compile_target_arch != "x86_64" && compile_target_arch != "aarch64")
{
build.cpp_set_stdlib("stdc++");
} else {
build
.cpp_set_stdlib("c++")
.flag("-static")
.include("/usr/lib/llvm-14/include/c++/v1");
println!("cargo:rustc-link-lib=static=c++");
if compile_target_arch == "aarch64" {
build
.include("/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/usr/include")
.flag("--sysroot=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot");
println!("cargo:rustc-link-search=/usr/aarch64-unknown-linux-gnu/lib/llvm-14/lib");
println!("cargo:rustc-link-search=/usr/aarch64-unknown-linux-gnu/lib");
println!("cargo:rustc-link-search=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/lib");
println!("cargo:rustc-link-search=/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5");
} else {
println!("cargo:rustc-link-search=/usr/lib/llvm-14/lib");
}
}
}
"macos" => {
build.cpp_set_stdlib("c++");
println!("cargo:rustc-link-lib=c++");
println!("cargo:rustc-link-lib=framework=ApplicationServices");
}
_ => {}
}
let out_dir = env::var("OUT_DIR").unwrap();
build
.include("./skia-c")
.include(skia_path)
// https://github.com/rust-lang/rust/pull/93901#issuecomment-1119360260
.cargo_metadata(false)
.out_dir(&out_dir)
.compile("skiac");
println!("cargo:rustc-link-search={}", skia_lib_dir);
println!("cargo:rustc-link-search={}", &out_dir);
println!("cargo:rustc-link-lib=skshaper");
napi_build::setup();
}