forked from NoXF/libwebp-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
76 lines (66 loc) · 2.15 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
extern crate cc;
extern crate glob;
use std::env;
use std::path::PathBuf;
fn main() {
let manifest_dir =
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
let vendor = manifest_dir.join("vendor");
if !vendor.join("src").exists() {
panic!(
"{} dir is missing files. Try running: `git submodule update --init --recursive`",
vendor.display()
);
}
let mut cc = cc::Build::new();
let mut sharpyuv_build = cc::Build::new();
setup_build(&mut cc, &vendor);
setup_build(&mut sharpyuv_build, &vendor);
for f in glob::glob("vendor/src/**/*.c")
.expect("glob vender/src failed")
.flatten()
{
cc.file(manifest_dir.join(f));
}
for f in glob::glob("vendor/sharpyuv/**/*.c")
.expect("glob vender/src failed")
.flatten()
{
sharpyuv_build.file(manifest_dir.join(f));
}
sharpyuv_build.compile("sharpyuv");
cc.compile("webpsys");
}
fn setup_build(build: &mut cc::Build, include_dir: &PathBuf) {
build.include(include_dir);
build.define("NDEBUG", Some("1"));
build.define("_THREAD_SAFE", Some("1"));
if !build.get_compiler().is_like_msvc() {
build.flag("-fvisibility=hidden").flag("-Wall");
} else {
build.flag("-D_CRT_SECURE_NO_WARNINGS");
}
if let Ok(target_cpu) = env::var("TARGET_CPU") {
build.flag_if_supported(&format!("-march={}", target_cpu));
}
let target = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH");
match target.as_str() {
"x86_64" | "i686" => {
build.define("WEBP_HAVE_SSE2", Some("1"));
if cfg!(feature = "sse41") {
build.define("WEBP_HAVE_SSE41", Some("1"));
build.flag_if_supported("-msse4.1");
}
if cfg!(feature = "avx2") {
build.define("WEBP_HAVE_AVX2", Some("1"));
build.flag_if_supported("-mavx2");
}
}
"aarch64" => {
if cfg!(feature = "neon") {
build.define("WEBP_HAVE_NEON", Some("1"));
}
}
_ => {}
};
}