forked from bvibber/jpegxr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
125 lines (118 loc) · 4.72 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
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=jxrlib/");
println!("cargo:rerun-if-changed=src/fakelibc/");
let src = &[
// SRC_SYS
"jxrlib/image/sys/adapthuff.c",
"jxrlib/image/sys/image.c",
"jxrlib/image/sys/strcodec.c",
"jxrlib/image/sys/strPredQuant.c",
"jxrlib/image/sys/strTransform.c",
"jxrlib/image/sys/perfTimerANSI.c",
// SRC_DEC
"jxrlib/image/decode/decode.c",
"jxrlib/image/decode/postprocess.c",
"jxrlib/image/decode/segdec.c",
"jxrlib/image/decode/strdec.c",
"jxrlib/image/decode/strInvTransform.c",
"jxrlib/image/decode/strPredQuantDec.c",
"jxrlib/image/decode/JXRTranscode.c",
// SRC_ENC
"jxrlib/image/encode/encode.c",
"jxrlib/image/encode/segenc.c",
"jxrlib/image/encode/strenc.c",
"jxrlib/image/encode/strFwdTransform.c",
"jxrlib/image/encode/strPredQuantEnc.c",
//
// glue lib
"jxrlib/jxrgluelib/JXRGlue.c",
"jxrlib/jxrgluelib/JXRGlueJxr.c",
"jxrlib/jxrgluelib/JXRGluePFC.c",
"jxrlib/jxrgluelib/JXRMeta.c",
// "test" lib (contains tif encoding)
// Most of these are unused, but the Windows linker errors
// if we don't include them.
"jxrlib/jxrtestlib/JXRTest.c",
"jxrlib/jxrtestlib/JXRTestBmp.c",
"jxrlib/jxrtestlib/JXRTestHdr.c",
"jxrlib/jxrtestlib/JXRTestPnm.c",
"jxrlib/jxrtestlib/JXRTestTif.c",
"jxrlib/jxrtestlib/JXRTestYUV.c",
];
let mut build = cc::Build::new();
build
.files(src)
.include("jxrlib")
.include("jxrlib/common/include")
.include("jxrlib/image/sys")
.include("jxrlib/jxrgluelib")
.include("jxrlib/jxrtestlib")
.define("__ANSI__", None)
.define("DISABLE_PERF_MEASUREMENT", None)
// quiet the build on mac with clang
.flag_if_supported("-Wno-constant-conversion")
.flag_if_supported("-Wno-unused-const-variable")
.flag_if_supported("-Wno-deprecated-declarations")
.flag_if_supported("-Wno-comment")
.flag_if_supported("-Wno-unused-value")
.flag_if_supported("-Wno-unused-function")
.flag_if_supported("-Wno-unknown-pragmas")
.flag_if_supported("-Wno-extra-tokens")
.flag_if_supported("-Wno-missing-field-initializers")
.flag_if_supported("-Wno-shift-negative-value")
.flag_if_supported("-Wno-dangling-else")
.flag_if_supported("-Wno-sign-compare")
// quiet the build on linux with gcc
.flag_if_supported("-Wno-strict-aliasing")
.flag_if_supported("-Wno-implicit-fallthrough")
.flag_if_supported("-Wno-old-style-declaration")
.flag_if_supported("-Wno-endif-labels")
.flag_if_supported("-Wno-parentheses")
.flag_if_supported("-Wno-misleading-indentation")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-incompatible-pointer-types")
.opt_level(2);
let target = std::env::var("TARGET").unwrap();
if target == "wasm32-unknown-unknown" {
// relying on our fake libc fragment
build
//.define("MALLOC_PREFIX", "vp6_custom_")
.flag("-isystem")
.flag("src/fakelibc")
.file("src/fakelibc/impl.c")
.file("src/fakelibc/qsort.c");
}
build
// Suppress all warnings - comment this out in local development
.flag("-w")
.compile("jpegxr");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut clang_args = vec![
"-D__ANSI__",
"-DDISABLE_PERF_MEASUREMENT",
"-Ijxrlib/jxrgluelib",
"-Ijxrlib/common/include",
"-Ijxrlib/image/sys",
];
if target == "wasm32-unknown-unknown" {
// We need to manually specify the visibility
// See https://github.com/rust-lang/rust-bindgen/issues/1941
clang_args.extend(&["-isystem", "src/fakelibc"]);
}
bindgen::Builder::default()
.header("jxrlib/jxrgluelib/JXRGlue.h")
.header("jxrlib/jxrtestlib/JXRTest.h")
.allowlist_function("^(WMP|PK|PixelFormatLookup|GetPixelFormatFromHash|GetImageEncodeIID|GetImageDecodeIID|FreeDescMetadata|Ruffle).*")
.allowlist_var("^(WMP|PK|LOOKUP|GUID_PK|IID).*")
.allowlist_type("^(WMP|PK|ERR|BITDEPTH|BD_|BITDEPTH_BITS|COLORFORMAT).*")
.clang_args(clang_args)
.derive_eq(true)
.size_t_is_usize(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Error building libjpegxr bindings")
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}