Debian Codegraph @

src/lib/core/highway/BUILD

raw
1 load("@rules_license//rules:license.bzl", "license")
2 load("@bazel_skylib//lib:selects.bzl", "selects")
3
4 load("@rules_cc//cc:defs.bzl", "cc_test")
5 package(
6 default_applicable_licenses = ["//:license"],
7 default_visibility = ["//visibility:public"],
8 )
9
10 license(
11 name = "license",
12 package_name = "highway",
13 )
14
15 licenses(["notice"])
16
17 exports_files(["LICENSE"])
18
19 # Detect compiler:
20 config_setting(
21 name = "compiler_clang",
22 flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"},
23 )
24
25 config_setting(
26 name = "compiler_clangcl",
27 flag_values = {"@bazel_tools//tools/cpp:compiler": "lexan"},
28 )
29
30 config_setting(
31 name = "compiler_msvc_actual",
32 flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc"},
33 )
34
35 # The above is insufficient for Bazel on Windows, which does not seem to
36 # detect/set a compiler flag. This workaround prevents compile errors due to
37 # passing clang-only warning flags to MSVC.
38 config_setting(
39 name = "compiler_msvc_cpu",
40 values = {
41 "cpu": "x64_windows",
42 },
43 )
44
45 selects.config_setting_group(
46 name = "compiler_msvc",
47 match_any = [
48 ":compiler_msvc_actual",
49 ":compiler_msvc_cpu",
50 ],
51 )
52
53 config_setting(
54 name = "compiler_emscripten",
55 values = {"cpu": "wasm32"},
56 )
57
58 # See https://github.com/bazelbuild/bazel/issues/12707
59 config_setting(
60 name = "compiler_gcc_bug",
61 flag_values = {
62 "@bazel_tools//tools/cpp:compiler": "compiler",
63 },
64 )
65
66 config_setting(
67 name = "compiler_gcc_actual",
68 flag_values = {
69 "@bazel_tools//tools/cpp:compiler": "gcc",
70 },
71 )
72
73 selects.config_setting_group(
74 name = "compiler_gcc",
75 match_any = [
76 ":compiler_gcc_bug",
77 ":compiler_gcc_actual",
78 ],
79 )
80
81 # Additional warnings for Clang OR GCC (skip for MSVC)
82 CLANG_GCC_COPTS = [
83 "-Wunused-parameter",
84 "-Wunused-variable",
85 "-Wextra-semi",
86 "-Wunreachable-code",
87 ]
88
89 # Warnings supported by Clang and Clang-cl
90 CLANG_OR_CLANGCL_OPTS = CLANG_GCC_COPTS + [
91 "-Wfloat-overflow-conversion",
92 "-Wfloat-zero-conversion",
93 "-Wfor-loop-analysis",
94 "-Wgnu-redeclared-enum",
95 "-Winfinite-recursion",
96 "-Wliteral-conversion",
97 "-Wno-c++98-compat",
98 "-Wno-unused-command-line-argument",
99 "-Wprivate-header",
100 "-Wself-assign",
101 "-Wstring-conversion",
102 "-Wtautological-overlap-compare",
103 "-Wthread-safety-analysis",
104 "-Wundefined-func-template",
105 "-Wunused-comparison",
106 ]
107
108 # Warnings only supported by Clang, but not Clang-cl
109 CLANG_ONLY_COPTS = CLANG_OR_CLANGCL_OPTS + [
110 # Do not treat the third_party headers as system headers when building
111 # highway - the errors are pertinent.
112 "--no-system-header-prefix=third_party/highway",
113 ]
114
115 COPTS = select({
116 ":compiler_msvc": [],
117 ":compiler_gcc": CLANG_GCC_COPTS,
118 ":compiler_clangcl": CLANG_OR_CLANGCL_OPTS,
119 # Default to clang because compiler detection only works in Bazel
120 "//conditions:default": CLANG_ONLY_COPTS,
121 }) + select({
122 "@platforms//cpu:riscv64": [
123 "-march=rv64gcv1p0",
124 "-menable-experimental-extensions",
125 ],
126 "//conditions:default": [
127 ],
128 })
129
130 DEFINES = select({
131 ":compiler_msvc": ["HWY_SHARED_DEFINE"],
132 ":compiler_clangcl": ["HWY_SHARED_DEFINE"],
133 "//conditions:default": [],
134 })
135
136 # Unused on Bazel builds, where this is not defined/known; Copybara replaces
137 # usages with an empty list.
138 COMPAT = [
139 "//buildenv/target:non_prod", # includes mobile/vendor.
140 ]
141
142 # WARNING: changing flags such as HWY_DISABLED_TARGETS may break users without
143 # failing integration tests, if the machine running tests does not support the
144 # newly enabled instruction set, or the failure is only caught by sanitizers
145 # which do not run in CI.
146
147 cc_library(
148 name = "hwy",
149 srcs = [
150 "hwy/aligned_allocator.cc",
151 "hwy/per_target.cc",
152 "hwy/print.cc",
153 "hwy/targets.cc",
154 ],
155 # Normal headers with include guards
156 hdrs = [
157 "hwy/aligned_allocator.h",
158 "hwy/base.h",
159 "hwy/cache_control.h",
160 "hwy/detect_compiler_arch.h", # private
161 "hwy/print.h",
162 ],
163 compatible_with = [],
164 copts = COPTS,
165 defines = DEFINES,
166 local_defines = ["hwy_EXPORTS"],
167 textual_hdrs = [
168 # These are textual because config macros influence them:
169 "hwy/detect_targets.h", # private
170 "hwy/targets.h",
171 # This .cc file #includes itself through foreach_target.h
172 "hwy/per_target.cc",
173 # End of list
174 "hwy/highway.h", # public
175 "hwy/foreach_target.h", # public
176 "hwy/per_target.h", # public
177 "hwy/print-inl.h", # public
178 "hwy/highway_export.h", # public
179 "hwy/ops/arm_neon-inl.h",
180 "hwy/ops/arm_sve-inl.h",
181 "hwy/ops/emu128-inl.h",
182 "hwy/ops/generic_ops-inl.h",
183 "hwy/ops/scalar-inl.h",
184 "hwy/ops/set_macros-inl.h",
185 "hwy/ops/shared-inl.h",
186 "hwy/ops/x86_128-inl.h",
187 "hwy/ops/x86_256-inl.h",
188 "hwy/ops/x86_512-inl.h",
189 # Select avoids recompiling native arch if only non-native changed
190 ] + select({
191 ":compiler_emscripten": [
192 "hwy/ops/wasm_128-inl.h",
193 "hwy/ops/wasm_256-inl.h",
194 ],
195 "//conditions:default": [],
196 }) + select({
197 "@platforms//cpu:riscv64": ["hwy/ops/rvv-inl.h"],
198 "//conditions:default": [],
199 }),
200 )
201
202 cc_library(
203 name = "algo",
204 compatible_with = [],
205 copts = COPTS,
206 textual_hdrs = [
207 "hwy/contrib/algo/copy-inl.h",
208 "hwy/contrib/algo/find-inl.h",
209 "hwy/contrib/algo/transform-inl.h",
210 ],
211 deps = [
212 ":hwy",
213 ],
214 )
215
216 cc_library(
217 name = "bit_pack",
218 compatible_with = [],
219 copts = COPTS,
220 textual_hdrs = [
221 "hwy/contrib/bit_pack/bit_pack-inl.h",
222 ],
223 deps = [
224 ":hwy",
225 ],
226 )
227
228 cc_library(
229 name = "dot",
230 compatible_with = [],
231 copts = COPTS,
232 textual_hdrs = [
233 "hwy/contrib/dot/dot-inl.h",
234 ],
235 deps = [
236 ":hwy",
237 ],
238 )
239
240 cc_library(
241 name = "image",
242 srcs = [
243 "hwy/contrib/image/image.cc",
244 ],
245 hdrs = [
246 "hwy/contrib/image/image.h",
247 ],
248 compatible_with = [],
249 copts = COPTS,
250 local_defines = ["hwy_contrib_EXPORTS"],
251 deps = [
252 ":hwy",
253 ],
254 )
255
256 cc_library(
257 name = "math",
258 compatible_with = [],
259 copts = COPTS,
260 textual_hdrs = [
261 "hwy/contrib/math/math-inl.h",
262 ],
263 deps = [
264 ":hwy",
265 ],
266 )
267
268 # Everything required for tests that use Highway.
269 cc_library(
270 name = "hwy_test_util",
271 srcs = ["hwy/tests/test_util.cc"],
272 hdrs = ["hwy/tests/test_util.h"],
273 compatible_with = [],
274 copts = COPTS,
275 local_defines = ["hwy_test_EXPORTS"],
276 textual_hdrs = [
277 "hwy/tests/test_util-inl.h",
278 "hwy/tests/hwy_gtest.h",
279 ],
280 # Must not depend on a gtest variant, which can conflict with the
281 # GUNIT_INTERNAL_BUILD_MODE defined by the test.
282 deps = [
283 ":hwy",
284 ],
285 )
286
287 cc_library(
288 name = "nanobenchmark",
289 srcs = ["hwy/nanobenchmark.cc"],
290 hdrs = ["hwy/nanobenchmark.h"],
291 compatible_with = [],
292 copts = COPTS,
293 local_defines = ["hwy_EXPORTS"],
294 deps = [":hwy"],
295 )
296
297 cc_binary(
298 name = "benchmark",
299 srcs = ["hwy/examples/benchmark.cc"],
300 copts = COPTS,
301 deps = [
302 ":hwy",
303 ":nanobenchmark",
304 ],
305 )
306
307 cc_library(
308 name = "skeleton",
309 srcs = ["hwy/examples/skeleton.cc"],
310 hdrs = ["hwy/examples/skeleton.h"],
311 copts = COPTS,
312 local_defines = ["hwy_EXPORTS"],
313 textual_hdrs = ["hwy/examples/skeleton-inl.h"],
314 deps = [
315 ":hwy",
316 ],
317 )
318
319 cc_binary(
320 name = "list_targets",
321 srcs = ["hwy/tests/list_targets.cc"],
322 deps = [":hwy"],
323 )
324
325 # path, name
326 HWY_TESTS = [
327 ("hwy/contrib/algo/", "copy_test"),
328 ("hwy/contrib/algo/", "find_test"),
329 ("hwy/contrib/algo/", "transform_test"),
330 ("hwy/contrib/bit_pack/", "bit_pack_test"),
331 ("hwy/contrib/dot/", "dot_test"),
332 ("hwy/contrib/image/", "image_test"),
333 ("hwy/contrib/math/", "math_test"),
334 # contrib/sort has its own BUILD, we add it to GUITAR_TESTS.
335 ("hwy/examples/", "skeleton_test"),
336 ("hwy/", "nanobenchmark_test"),
337 ("hwy/", "aligned_allocator_test"),
338 ("hwy/", "base_test"),
339 ("hwy/", "highway_test"),
340 ("hwy/", "targets_test"),
341 ("hwy/tests/", "arithmetic_test"),
342 ("hwy/tests/", "blockwise_test"),
343 ("hwy/tests/", "blockwise_shift_test"),
344 ("hwy/tests/", "combine_test"),
345 ("hwy/tests/", "compare_test"),
346 ("hwy/tests/", "compress_test"),
347 ("hwy/tests/", "convert_test"),
348 ("hwy/tests/", "crypto_test"),
349 ("hwy/tests/", "demote_test"),
350 ("hwy/tests/", "float_test"),
351 ("hwy/tests/", "if_test"),
352 ("hwy/tests/", "interleaved_test"),
353 ("hwy/tests/", "logical_test"),
354 ("hwy/tests/", "mask_test"),
355 ("hwy/tests/", "mask_mem_test"),
356 ("hwy/tests/", "memory_test"),
357 ("hwy/tests/", "mul_test"),
358 ("hwy/tests/", "reduction_test"),
359 ("hwy/tests/", "reverse_test"),
360 ("hwy/tests/", "shift_test"),
361 ("hwy/tests/", "swizzle_test"),
362 ("hwy/tests/", "test_util_test"),
363 ]
364
365 HWY_TEST_COPTS = select({
366 ":compiler_msvc": [],
367 "//conditions:default": [
368 # gTest triggers this warning (which is enabled by the
369 # extra-semi in COPTS), so we need to disable it here,
370 # but it's still enabled for :hwy.
371 "-Wno-c++98-compat-extra-semi",
372 ],
373 })
374
375 HWY_TEST_DEPS = [
376 ":algo",
377 ":bit_pack",
378 ":dot",
379 ":hwy",
380 ":hwy_test_util",
381 ":image",
382 ":math",
383 ":nanobenchmark",
384 ":skeleton",
385 "//hwy/contrib/sort:vqsort",
386 "@com_google_googletest//:gtest_main",
387 ]
388
389 [
390 [
391 cc_test(
392 name = test,
393 size = "medium",
394 timeout = "long", # default moderate is not enough for math_test
395 srcs = [
396 subdir + test + ".cc",
397 ],
398 copts = COPTS + HWY_TEST_COPTS,
399 features = select({
400 "@platforms//cpu:riscv64": ["fully_static_link"],
401 "//conditions:default": [],
402 }),
403 linkopts = select({
404 ":compiler_emscripten": [
405 "-s ASSERTIONS=2",
406 "-s ENVIRONMENT=node,shell,web",
407 "-s ERROR_ON_UNDEFINED_SYMBOLS=1",
408 "-s DEMANGLE_SUPPORT=1",
409 "-s EXIT_RUNTIME=1",
410 "-s ALLOW_MEMORY_GROWTH=1",
411 "--pre-js $(location :preamble.js.lds)",
412 ],
413 "//conditions:default": [],
414 }),
415 linkstatic = select({
416 "@platforms//cpu:riscv64": True,
417 "//conditions:default": False,
418 }),
419 local_defines = ["HWY_IS_TEST"],
420 # for test_suite.
421 tags = ["hwy_ops_test"],
422 deps = HWY_TEST_DEPS + select({
423 ":compiler_emscripten": [":preamble.js.lds"],
424 "//conditions:default": [],
425 }),
426 ),
427 ]
428 for subdir, test in HWY_TESTS
429 ]
430
431 # For manually building the tests we define here (:all does not work in --config=msvc)
432 test_suite(
433 name = "hwy_ops_tests",
434 tags = ["hwy_ops_test"],
435 )
436
437 # Placeholder for integration test, do not remove