Debian Codegraph @

lib/BUILD

raw
1 # Copyright (c) the JPEG XL Project Authors. All rights reserved.
2 #
3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file.
5
6 load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
7 load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
8
9 # Load sources/headers/tests lists.
10 load(
11 "jxl_lists.bzl",
12 "libjxl_base_sources",
13 "libjxl_cms_sources",
14 "libjxl_codec_apng_sources",
15 "libjxl_codec_exr_sources",
16 "libjxl_codec_gif_sources",
17 "libjxl_codec_jpegli_sources",
18 "libjxl_codec_jpg_sources",
19 "libjxl_codec_jxl_sources",
20 "libjxl_codec_npy_sources",
21 "libjxl_codec_pgx_sources",
22 "libjxl_codec_pnm_sources",
23 "libjxl_dec_box_sources",
24 "libjxl_dec_jpeg_sources",
25 "libjxl_dec_sources",
26 "libjxl_enc_sources",
27 "libjxl_extras_for_tools_sources",
28 "libjxl_extras_sources",
29 # "libjxl_gbench_sources",
30 # "libjxl_jpegli_lib_version",
31 "libjxl_jpegli_libjpeg_helper_files",
32 "libjxl_jpegli_sources",
33 "libjxl_jpegli_testlib_files",
34 "libjxl_jpegli_tests",
35 "libjxl_major_version",
36 "libjxl_minor_version",
37 "libjxl_patch_version",
38 "libjxl_public_headers",
39 "libjxl_testlib_files",
40 "libjxl_tests",
41 "libjxl_threads_public_headers",
42 "libjxl_threads_sources",
43 )
44 load(
45 "jxl_vars.bzl",
46 "libjxl_deps_brotli",
47 "libjxl_deps_exr",
48 "libjxl_deps_gif",
49 "libjxl_deps_gtest",
50 "libjxl_deps_hwy",
51 "libjxl_deps_hwy_nanobenchmark",
52 "libjxl_deps_hwy_test_util",
53 "libjxl_deps_jpeg",
54 "libjxl_deps_png",
55 "libjxl_deps_runfiles",
56 "libjxl_deps_skcms",
57 # "libjxl_deps_testdata",
58 # "libjxl_deps_webp",
59 "libjxl_root_package",
60 "libjxl_test_shards",
61 "libjxl_test_timeouts",
62 )
63
64 DEFAULT_VISIBILITY = ["//:__subpackages__"]
65
66 DEFAULT_COMPATIBILITY = []
67
68 INCLUDES_DIR = "include"
69
70 package(
71 default_visibility = DEFAULT_VISIBILITY,
72 )
73
74 licenses(["notice"])
75
76 exports_files(["LICENSE"])
77
78 EXPORT_TEMPLATE = """
79 #ifndef @_EXPORT_H
80 #define @_EXPORT_H
81
82 #define @_EXPORT
83 #define @_NO_EXPORT
84
85 #ifndef @_DEPRECATED
86 # define @_DEPRECATED __attribute__ ((__deprecated__))
87 #endif
88
89 #endif
90 """
91
92 JXL_EXPORT_H = INCLUDES_DIR + "/jxl/jxl_export.h"
93
94 genrule(
95 name = "create_jxl_export",
96 outs = [JXL_EXPORT_H],
97 cmd = "echo '" + EXPORT_TEMPLATE.replace("@", "JXL") + "' > $@",
98 compatible_with = DEFAULT_COMPATIBILITY,
99 )
100
101 JXL_CMS_EXPORT_H = INCLUDES_DIR + "/jxl/jxl_cms_export.h"
102
103 genrule(
104 name = "create_jxl_cms_export",
105 outs = [JXL_CMS_EXPORT_H],
106 cmd = "echo '" + EXPORT_TEMPLATE.replace("@", "JXL_CMS") + "' > $@",
107 compatible_with = DEFAULT_COMPATIBILITY,
108 )
109
110 JXL_THREADS_EXPORT_H = INCLUDES_DIR + "/jxl/jxl_threads_export.h"
111
112 genrule(
113 name = "create_jxl_threads_export",
114 outs = [JXL_THREADS_EXPORT_H],
115 cmd = "echo '" + EXPORT_TEMPLATE.replace("@", "JXL_THREADS") + "' > $@",
116 compatible_with = DEFAULT_COMPATIBILITY,
117 )
118
119 JXL_VERSION_H = INCLUDES_DIR + "/jxl/version.h"
120
121 expand_template(
122 name = "expand_jxl_version",
123 out = JXL_VERSION_H,
124 compatible_with = DEFAULT_COMPATIBILITY,
125 substitutions = {
126 "@JPEGXL_MAJOR_VERSION@": str(libjxl_major_version),
127 "@JPEGXL_MINOR_VERSION@": str(libjxl_minor_version),
128 "@JPEGXL_PATCH_VERSION@": str(libjxl_patch_version),
129 },
130 template = "jxl/version.h.in",
131 )
132
133 cc_library(
134 name = "jxl_version",
135 hdrs = [JXL_VERSION_H],
136 compatible_with = DEFAULT_COMPATIBILITY,
137 strip_include_prefix = INCLUDES_DIR,
138 )
139
140 JPEGLI_JCONFIG_H = INCLUDES_DIR + "/jpegli/jconfig.h"
141
142 JPEGLI_JMORECFG_H = INCLUDES_DIR + "/jpegli/jmorecfg.h"
143
144 JPEGLI_JPEGLIB_H = INCLUDES_DIR + "/jpegli/jpeglib.h"
145
146 copy_file(
147 name = "expand_jconfig",
148 src = "@libjpeg_turbo//:jconfig.h",
149 out = JPEGLI_JCONFIG_H,
150 compatible_with = DEFAULT_COMPATIBILITY,
151 )
152
153 copy_file(
154 name = "copy_jmorecfg",
155 src = "@libjpeg_turbo//:jmorecfg.h",
156 out = JPEGLI_JMORECFG_H,
157 compatible_with = DEFAULT_COMPATIBILITY,
158 )
159
160 copy_file(
161 name = "copy_jpeglib",
162 src = "@libjpeg_turbo//:jpeglib.h",
163 out = JPEGLI_JPEGLIB_H,
164 compatible_with = DEFAULT_COMPATIBILITY,
165 )
166
167 cc_library(
168 name = "includes",
169 hdrs = libjxl_public_headers + [
170 JXL_EXPORT_H,
171 JXL_CMS_EXPORT_H,
172 ],
173 compatible_with = DEFAULT_COMPATIBILITY,
174 strip_include_prefix = INCLUDES_DIR,
175 deps = [":jxl_version"],
176 )
177
178 cc_library(
179 name = "libjpeg_includes",
180 hdrs = [
181 JPEGLI_JCONFIG_H,
182 JPEGLI_JMORECFG_H,
183 JPEGLI_JPEGLIB_H,
184 ],
185 compatible_with = DEFAULT_COMPATIBILITY,
186 strip_include_prefix = INCLUDES_DIR + "/jpegli",
187 )
188
189 cc_library(
190 name = "base",
191 srcs = [path for path in libjxl_base_sources if path.endswith(".cc")],
192 hdrs = [path for path in libjxl_base_sources if path.endswith(".h")],
193 compatible_with = DEFAULT_COMPATIBILITY,
194 deps = [
195 ":includes",
196 ] + libjxl_deps_hwy,
197 )
198
199 cc_library(
200 name = "jpegxl",
201 srcs = libjxl_dec_sources + libjxl_dec_box_sources + libjxl_dec_jpeg_sources + libjxl_enc_sources + libjxl_cms_sources,
202 compatible_with = DEFAULT_COMPATIBILITY,
203 defines = [
204 "JPEGXL_ENABLE_SKCMS=1",
205 ],
206 deps = [
207 ":base",
208 ":includes",
209 ] + libjxl_deps_brotli + libjxl_deps_hwy + libjxl_deps_skcms,
210 )
211
212 cc_library(
213 name = "jpegxl_private",
214 hdrs = [
215 path
216 for path in libjxl_dec_sources + libjxl_dec_box_sources + libjxl_dec_jpeg_sources + libjxl_enc_sources + libjxl_cms_sources
217 if path.endswith(".h") and not path.endswith("-inl.h")
218 ],
219 compatible_with = DEFAULT_COMPATIBILITY,
220 deps = [":jpegxl"],
221 )
222
223 cc_library(
224 name = "jpegxl_threads",
225 srcs = libjxl_threads_sources,
226 hdrs = libjxl_threads_public_headers + [JXL_THREADS_EXPORT_H],
227 compatible_with = DEFAULT_COMPATIBILITY,
228 strip_include_prefix = INCLUDES_DIR,
229 deps = [
230 ":base",
231 ":includes",
232 ],
233 )
234
235 CODEC_FILES = libjxl_codec_apng_sources + libjxl_codec_exr_sources + libjxl_codec_gif_sources + libjxl_codec_jpegli_sources + libjxl_codec_jpg_sources + libjxl_codec_jxl_sources + libjxl_codec_npy_sources + libjxl_codec_pgx_sources + libjxl_codec_pnm_sources
236
237 CODEC_SRCS = [path for path in CODEC_FILES if path.endswith(".cc")]
238
239 CODEC_HDRS = [path for path in CODEC_FILES if path.endswith(".h")]
240
241 cc_library(
242 name = "jpegli",
243 srcs = libjxl_jpegli_sources,
244 hdrs = [
245 "jpegli/common_internal.h", # TODO(eustas): should not be here
246 ],
247 compatible_with = DEFAULT_COMPATIBILITY,
248 deps = [
249 ":jpegxl_private",
250 ":libjpeg_includes",
251 ] + libjxl_deps_hwy,
252 )
253
254 # TODO(eustas): build codecs separately?
255 cc_library(
256 name = "jpegxl_extras",
257 srcs = libjxl_extras_sources + libjxl_extras_for_tools_sources + CODEC_SRCS,
258 hdrs = CODEC_HDRS,
259 compatible_with = DEFAULT_COMPATIBILITY,
260 defines = [
261 "JPEGXL_ENABLE_APNG=1",
262 "JPEGXL_ENABLE_EXR=1",
263 "JPEGXL_ENABLE_GIF=1",
264 "JPEGXL_ENABLE_JPEG=1",
265 "JPEGXL_ENABLE_JPEGLI=1",
266 ],
267 deps = [
268 ":jpegli",
269 ":jpegxl_private",
270 ":jpegxl_threads",
271 ":jxl_version",
272 ] + libjxl_deps_exr + libjxl_deps_gif + libjxl_deps_jpeg + libjxl_deps_png,
273 )
274
275 TESTLIB_FILES = libjxl_testlib_files + libjxl_jpegli_testlib_files + libjxl_jpegli_libjpeg_helper_files
276
277 cc_library(
278 name = "test_utils",
279 testonly = 1,
280 srcs = [path for path in TESTLIB_FILES if not path.endswith(".h")],
281 hdrs = [path for path in TESTLIB_FILES if path.endswith(".h")],
282 compatible_with = DEFAULT_COMPATIBILITY,
283 defines = [
284 'JPEGXL_ROOT_PACKAGE=\'"' + libjxl_root_package + '"\'',
285 ],
286 deps = [
287 ":jpegli",
288 ":jpegxl_extras",
289 ":jpegxl_private",
290 ] + libjxl_deps_runfiles,
291 )
292
293 TESTS = [path.partition(".")[0] for path in libjxl_tests + libjxl_jpegli_tests]
294
295 [
296 cc_test(
297 name = test,
298 timeout = libjxl_test_timeouts.get(test, "moderate"),
299 srcs = [
300 test + ".cc",
301 "jpegli/testing.h",
302 "jxl/testing.h",
303 ],
304 data = ["//:testdata"],
305 shard_count = libjxl_test_shards.get(test, 1),
306 deps = [
307 ":jpegxl_extras",
308 ":jpegxl_private",
309 ":jpegxl_threads",
310 ":test_utils",
311 ] + libjxl_deps_gtest + libjxl_deps_hwy_test_util + libjxl_deps_hwy_nanobenchmark,
312 )
313 for test in TESTS
314 ]