Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / third_party / highway / BUILD
blob92ca4721fc89ddcab6350b5bf45db83a71b1c20c
1 load("@rules_license//rules:license.bzl", "license")
2 load("@bazel_skylib//lib:selects.bzl", "selects")
4 load("@rules_cc//cc:defs.bzl", "cc_test")
5 package(
6     default_applicable_licenses = ["//:license"],
7     default_visibility = ["//visibility:public"],
10 license(
11     name = "license",
12     package_name = "highway",
15 licenses(["notice"])
17 exports_files(["LICENSE"])
19 # Detect compiler:
20 config_setting(
21     name = "compiler_clang",
22     flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"},
25 config_setting(
26     name = "compiler_clangcl",
27     flag_values = {"@bazel_tools//tools/cpp:compiler": "lexan"},
30 config_setting(
31     name = "compiler_msvc_actual",
32     flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc"},
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     },
45 selects.config_setting_group(
46     name = "compiler_msvc",
47     match_any = [
48         ":compiler_msvc_actual",
49         ":compiler_msvc_cpu",
50     ],
53 config_setting(
54     name = "compiler_emscripten",
55     values = {"cpu": "wasm32"},
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     },
66 config_setting(
67     name = "compiler_gcc_actual",
68     flag_values = {
69         "@bazel_tools//tools/cpp:compiler": "gcc",
70     },
73 selects.config_setting_group(
74     name = "compiler_gcc",
75     match_any = [
76         ":compiler_gcc_bug",
77         ":compiler_gcc_actual",
78     ],
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",
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",
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",
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     ],
130 DEFINES = select({
131     ":compiler_msvc": ["HWY_SHARED_DEFINE"],
132     ":compiler_clangcl": ["HWY_SHARED_DEFINE"],
133     "//conditions:default": [],
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.
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.
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/tuple-inl.h",
187         "hwy/ops/x86_128-inl.h",
188         "hwy/ops/x86_256-inl.h",
189         "hwy/ops/x86_512-inl.h",
190         # Select avoids recompiling native arch if only non-native changed
191     ] + select({
192         ":compiler_emscripten": [
193             "hwy/ops/wasm_128-inl.h",
194             "hwy/ops/wasm_256-inl.h",
195         ],
196         "//conditions:default": [],
197     }) + select({
198         "@platforms//cpu:riscv64": ["hwy/ops/rvv-inl.h"],
199         "//conditions:default": [],
200     }),
203 cc_library(
204     name = "algo",
205     compatible_with = [],
206     copts = COPTS,
207     textual_hdrs = [
208         "hwy/contrib/algo/copy-inl.h",
209         "hwy/contrib/algo/find-inl.h",
210         "hwy/contrib/algo/transform-inl.h",
211     ],
212     deps = [
213         ":hwy",
214     ],
217 cc_library(
218     name = "bit_pack",
219     compatible_with = [],
220     copts = COPTS,
221     textual_hdrs = [
222         "hwy/contrib/bit_pack/bit_pack-inl.h",
223     ],
224     deps = [
225         ":hwy",
226     ],
229 cc_library(
230     name = "dot",
231     compatible_with = [],
232     copts = COPTS,
233     textual_hdrs = [
234         "hwy/contrib/dot/dot-inl.h",
235     ],
236     deps = [
237         ":hwy",
238     ],
241 cc_library(
242     name = "image",
243     srcs = [
244         "hwy/contrib/image/image.cc",
245     ],
246     hdrs = [
247         "hwy/contrib/image/image.h",
248     ],
249     compatible_with = [],
250     copts = COPTS,
251     local_defines = ["hwy_contrib_EXPORTS"],
252     deps = [
253         ":hwy",
254     ],
257 cc_library(
258     name = "math",
259     compatible_with = [],
260     copts = COPTS,
261     textual_hdrs = [
262         "hwy/contrib/math/math-inl.h",
263     ],
264     deps = [
265         ":hwy",
266     ],
269 # Everything required for tests that use Highway.
270 cc_library(
271     name = "hwy_test_util",
272     srcs = ["hwy/tests/test_util.cc"],
273     hdrs = ["hwy/tests/test_util.h"],
274     compatible_with = [],
275     copts = COPTS,
276     local_defines = ["hwy_test_EXPORTS"],
277     textual_hdrs = [
278         "hwy/tests/test_util-inl.h",
279         "hwy/tests/hwy_gtest.h",
280     ],
281     # Must not depend on a gtest variant, which can conflict with the
282     # GUNIT_INTERNAL_BUILD_MODE defined by the test.
283     deps = [
284         ":hwy",
285     ],
288 cc_library(
289     name = "nanobenchmark",
290     srcs = ["hwy/nanobenchmark.cc"],
291     hdrs = ["hwy/nanobenchmark.h"],
292     compatible_with = [],
293     copts = COPTS,
294     local_defines = ["hwy_EXPORTS"],
295     deps = [":hwy"],
298 cc_binary(
299     name = "benchmark",
300     srcs = ["hwy/examples/benchmark.cc"],
301     copts = COPTS,
302     deps = [
303         ":hwy",
304         ":nanobenchmark",
305     ],
308 cc_library(
309     name = "skeleton",
310     srcs = ["hwy/examples/skeleton.cc"],
311     hdrs = ["hwy/examples/skeleton.h"],
312     copts = COPTS,
313     local_defines = ["hwy_EXPORTS"],
314     textual_hdrs = ["hwy/examples/skeleton-inl.h"],
315     deps = [
316         ":hwy",
317     ],
320 cc_test(
321     name = "list_targets",
322     size = "small",
323     srcs = ["hwy/tests/list_targets.cc"],
324     deps = [":hwy"],
327 # path, name
328 HWY_TESTS = [
329     ("hwy/contrib/algo/", "copy_test"),
330     ("hwy/contrib/algo/", "find_test"),
331     ("hwy/contrib/algo/", "transform_test"),
332     ("hwy/contrib/bit_pack/", "bit_pack_test"),
333     ("hwy/contrib/dot/", "dot_test"),
334     ("hwy/contrib/image/", "image_test"),
335     ("hwy/contrib/math/", "math_test"),
336     # contrib/sort has its own BUILD, we also add sort_test to GUITAR_TESTS.
337     # To run bench_sort, specify --test=hwy/contrib/sort:bench_sort.
338     ("hwy/examples/", "skeleton_test"),
339     ("hwy/", "nanobenchmark_test"),
340     ("hwy/", "aligned_allocator_test"),
341     ("hwy/", "base_test"),
342     ("hwy/", "highway_test"),
343     ("hwy/", "targets_test"),
344     ("hwy/tests/", "arithmetic_test"),
345     ("hwy/tests/", "blockwise_shift_test"),
346     ("hwy/tests/", "blockwise_test"),
347     ("hwy/tests/", "combine_test"),
348     ("hwy/tests/", "compare_test"),
349     ("hwy/tests/", "compress_test"),
350     ("hwy/tests/", "convert_test"),
351     ("hwy/tests/", "count_test"),
352     ("hwy/tests/", "crypto_test"),
353     ("hwy/tests/", "demote_test"),
354     ("hwy/tests/", "expand_test"),
355     ("hwy/tests/", "float_test"),
356     ("hwy/tests/", "if_test"),
357     ("hwy/tests/", "interleaved_test"),
358     ("hwy/tests/", "logical_test"),
359     ("hwy/tests/", "mask_mem_test"),
360     ("hwy/tests/", "mask_test"),
361     ("hwy/tests/", "memory_test"),
362     ("hwy/tests/", "mul_test"),
363     ("hwy/tests/", "reduction_test"),
364     ("hwy/tests/", "reverse_test"),
365     ("hwy/tests/", "shift_test"),
366     ("hwy/tests/", "swizzle_test"),
367     ("hwy/tests/", "test_util_test"),
368     ("hwy/tests/", "tuple_test"),
371 HWY_TEST_COPTS = select({
372     ":compiler_msvc": [],
373     "//conditions:default": [
374         # gTest triggers this warning (which is enabled by the
375         # extra-semi in COPTS), so we need to disable it here,
376         # but it's still enabled for :hwy.
377         "-Wno-c++98-compat-extra-semi",
378     ],
381 HWY_TEST_DEPS = [
382     ":algo",
383     ":bit_pack",
384     ":dot",
385     ":hwy",
386     ":hwy_test_util",
387     ":image",
388     ":math",
389     ":nanobenchmark",
390     ":skeleton",
391     "//hwy/contrib/sort:vqsort",
392     "@com_google_googletest//:gtest_main",
396     [
397         cc_test(
398             name = test,
399             size = "medium",
400             timeout = "long",  # default moderate is not enough for math_test
401             srcs = [
402                 subdir + test + ".cc",
403             ],
404             copts = COPTS + HWY_TEST_COPTS,
405             features = select({
406                 "@platforms//cpu:riscv64": ["fully_static_link"],
407                 "//conditions:default": [],
408             }),
409             linkopts = select({
410                 ":compiler_emscripten": [
411                     "-s ASSERTIONS=2",
412                     "-s ENVIRONMENT=node,shell,web",
413                     "-s ERROR_ON_UNDEFINED_SYMBOLS=1",
414                     "-s DEMANGLE_SUPPORT=1",
415                     "-s EXIT_RUNTIME=1",
416                     "-s ALLOW_MEMORY_GROWTH=1",
417                     "--pre-js $(location :preamble.js.lds)",
418                 ],
419                 "//conditions:default": [],
420             }),
421             linkstatic = select({
422                 "@platforms//cpu:riscv64": True,
423                 "//conditions:default": False,
424             }),
425             local_defines = ["HWY_IS_TEST"],
426             # for test_suite.
427             tags = ["hwy_ops_test"],
428             deps = HWY_TEST_DEPS + select({
429                 ":compiler_emscripten": [":preamble.js.lds"],
430                 "//conditions:default": [],
431             }),
432         ),
433     ]
434     for subdir, test in HWY_TESTS
437 # For manually building the tests we define here (:all does not work in --config=msvc)
438 test_suite(
439     name = "hwy_ops_tests",
440     tags = ["hwy_ops_test"],
443 # Placeholder for integration test, do not remove