-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
161 lines (142 loc) · 5.54 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
use std::path::PathBuf;
use glob::glob;
use rustflags::Flag;
pub enum Arch {
X64,
Arm,
}
fn main() {
let kdu_root = std::env::var("KDU_ROOT")
.map(PathBuf::from)
.unwrap_or(PathBuf::from("kakadu"));
let target = std::env::var("TARGET").expect("target env var not set");
let arch = match target.as_str() {
"x86_64-unknown-linux-gnu" | "x86_64-apple-darwin" => Arch::X64,
"aarch64-unknown-linux-gnu" | "aarch64-apple-darwin" => Arch::Arm,
_ => panic!("unsupported target {target}"),
};
let kdu_coresys_sources = &[
"coresys/kernels/kernels.cpp",
"coresys/fast_coding/fbc_encoder.cpp",
"coresys/fast_coding/fbc_encoder_tools.cpp",
"coresys/fast_coding/fbc_decoder.cpp",
"coresys/fast_coding/fbc_common.cpp",
"coresys/fast_coding/fbc_decoder_tools.cpp",
"coresys/roi/roi.cpp",
"coresys/threads/kdu_threads.cpp",
"coresys/parameters/params.cpp",
"coresys/transform/neon_multi_transform_local.cpp",
"coresys/transform/analysis2.cpp",
"coresys/transform/transform.cpp",
"coresys/transform/colour.cpp",
"coresys/transform/neon_synthesis2.cpp",
"coresys/transform/avx2_colour_local.cpp",
"coresys/transform/synthesis2.cpp",
"coresys/transform/neon_analysis2.cpp",
"coresys/transform/transform2.cpp",
"coresys/transform/multi_transform.cpp",
"coresys/transform/neon_dwt_local.cpp",
"coresys/transform/fusion.cpp",
"coresys/transform/synthesis.cpp",
"coresys/transform/neon_colour_local.cpp",
"coresys/transform/avx2_analysis2.cpp",
"coresys/transform/analysis.cpp",
"coresys/transform/sse4_multi_transform_local.cpp",
"coresys/transform/avx2_dwt_local.cpp",
"coresys/transform/avx2_synthesis2.cpp",
"coresys/transform/ssse3_colour_local.cpp",
"coresys/transform/ssse3_dwt_local.cpp",
"coresys/transform/avx_colour_local.cpp",
"coresys/coding/block_coding_common.cpp",
"coresys/coding/mq_decoder.cpp",
"coresys/coding/avx_coder_local.cpp",
"coresys/coding/encoder.cpp",
"coresys/coding/decoder.cpp",
"coresys/coding/cplex_analysis.cpp",
"coresys/coding/avx2_coder_local.cpp",
"coresys/coding/block_decoder.cpp",
"coresys/coding/neon_coder_local.cpp",
"coresys/coding/ssse3_coder_local.cpp",
"coresys/coding/mq_encoder.cpp",
"coresys/coding/block_encoder.cpp",
"coresys/shared/core_local.cpp",
"coresys/messaging/messaging.cpp",
"coresys/compressed/compressed.cpp",
"coresys/compressed/blocks.cpp",
"coresys/compressed/codestream.cpp",
"coresys/common/kdu_arch.cpp",
"apps/jp2/jp2.cpp",
"apps/jp2/jpx.cpp",
"apps/compressed_io/file_io.cpp",
"apps/client_server/kdu_client_window.cpp",
"apps/support/kdu_stripe_decompressor.cpp",
"apps/support/ssse3_stripe_transfer.cpp",
"apps/support/avx2_region_decompressor.cpp",
"apps/support/kdu_stream_decompressor.cpp",
"apps/support/neon_stripe_transfer.cpp",
"apps/support/supp_local.cpp",
"apps/support/kdu_stripe_compressor.cpp",
"apps/support/kdu_region_decompressor.cpp",
"apps/support/ssse3_region_decompressor.cpp",
"apps/support/sse4_region_decompressor.cpp",
"apps/support/avx2_stripe_transfer.cpp",
"apps/support/neon_region_decompressor.cpp",
];
let kdu_includes = &[
"coresys/common",
"coresys/shared",
"apps/support",
"apps/jp2",
"apps/compressed_io",
];
let mut build = cxx_build::bridge("src/lib.rs");
build.compiler("clang++");
build.std("c++20");
build.flag("-Wno-everything");
build.files(kdu_coresys_sources.map(|path| kdu_root.join(path)));
build.includes(kdu_includes.map(|path| kdu_root.join(path)));
build.define("KDU_SIMD_OPTIMIZATIONS", None);
// If not present, no overrides.
let _ = build.try_flags_from_environment("KDU_CXXFLAGS");
// Enable fused multiply-add, and enable fast-math to make sure code benefits from it.
build.flag("-ffast-math");
build.static_crt(true);
build.static_flag(true);
for flag in rustflags::from_env() {
match flag {
Flag::Codegen { opt, value: Some(cpu) } if opt == "target-cpu" => {
if cpu == "native" {
build.flag("-march=native");
} else {
build.flag(format!("-mcpu={}", cpu));
}
}
Flag::Codegen { opt, .. } if opt == "linker-plugin-lto" => {
build.flag("-flto");
}
_ => continue,
}
}
match arch {
Arch::X64 => {
build.flag("-mavx2");
build.flag("-mfma");
build.define("KDU_X86_INTRINSICS", None);
}
Arch::Arm => {
build.define("KDU_NEON_INTRINSICS", None);
}
}
let source_files = glob("src/*.cc").expect("failed to get sources");
let headers = glob("src/*.h").expect("failed to get headers");
let all = source_files.chain(headers).filter_map(|file| file.ok());
for file in all {
if file.extension().is_some_and(|ext| ext == "cc") {
build.file(&file);
}
let source_path = file.to_string_lossy();
println!("cargo::rerun-if-changed={source_path}");
}
println!("cargo::rerun-if-changed=src/lib.rs");
build.compile("kaduceus");
}