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")
6 default_applicable_licenses = ["//:license"],
7 default_visibility = ["//visibility:public"],
12 package_name = "highway",
17 exports_files(["LICENSE"])
21 name = "compiler_clang",
22 flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"},
26 name = "compiler_clangcl",
27 flag_values = {"@bazel_tools//tools/cpp:compiler": "lexan"},
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.
39 name = "compiler_msvc_cpu",
45 selects.config_setting_group(
46 name = "compiler_msvc",
48 ":compiler_msvc_actual",
54 name = "compiler_emscripten",
55 values = {"cpu": "wasm32"},
58 # See https://github.com/bazelbuild/bazel/issues/12707
60 name = "compiler_gcc_bug",
62 "@bazel_tools//tools/cpp:compiler": "compiler",
67 name = "compiler_gcc_actual",
69 "@bazel_tools//tools/cpp:compiler": "gcc",
73 selects.config_setting_group(
74 name = "compiler_gcc",
77 ":compiler_gcc_actual",
81 # Additional warnings for Clang OR GCC (skip for MSVC)
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",
98 "-Wno-unused-command-line-argument",
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",
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,
122 "@platforms//cpu:riscv64": [
124 "-menable-experimental-extensions",
126 "//conditions:default": [
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.
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.
150 "hwy/aligned_allocator.cc",
155 # Normal headers with include guards
157 "hwy/aligned_allocator.h",
159 "hwy/cache_control.h",
160 "hwy/detect_compiler_arch.h", # private
163 compatible_with = [],
166 local_defines = ["hwy_EXPORTS"],
168 # These are textual because config macros influence them:
169 "hwy/detect_targets.h", # private
171 # This .cc file #includes itself through foreach_target.h
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
192 ":compiler_emscripten": [
193 "hwy/ops/wasm_128-inl.h",
194 "hwy/ops/wasm_256-inl.h",
196 "//conditions:default": [],
198 "@platforms//cpu:riscv64": ["hwy/ops/rvv-inl.h"],
199 "//conditions:default": [],
205 compatible_with = [],
208 "hwy/contrib/algo/copy-inl.h",
209 "hwy/contrib/algo/find-inl.h",
210 "hwy/contrib/algo/transform-inl.h",
219 compatible_with = [],
222 "hwy/contrib/bit_pack/bit_pack-inl.h",
231 compatible_with = [],
234 "hwy/contrib/dot/dot-inl.h",
244 "hwy/contrib/image/image.cc",
247 "hwy/contrib/image/image.h",
249 compatible_with = [],
251 local_defines = ["hwy_contrib_EXPORTS"],
259 compatible_with = [],
262 "hwy/contrib/math/math-inl.h",
269 # Everything required for tests that use Highway.
271 name = "hwy_test_util",
272 srcs = ["hwy/tests/test_util.cc"],
273 hdrs = ["hwy/tests/test_util.h"],
274 compatible_with = [],
276 local_defines = ["hwy_test_EXPORTS"],
278 "hwy/tests/test_util-inl.h",
279 "hwy/tests/hwy_gtest.h",
281 # Must not depend on a gtest variant, which can conflict with the
282 # GUNIT_INTERNAL_BUILD_MODE defined by the test.
289 name = "nanobenchmark",
290 srcs = ["hwy/nanobenchmark.cc"],
291 hdrs = ["hwy/nanobenchmark.h"],
292 compatible_with = [],
294 local_defines = ["hwy_EXPORTS"],
300 srcs = ["hwy/examples/benchmark.cc"],
310 srcs = ["hwy/examples/skeleton.cc"],
311 hdrs = ["hwy/examples/skeleton.h"],
313 local_defines = ["hwy_EXPORTS"],
314 textual_hdrs = ["hwy/examples/skeleton-inl.h"],
321 name = "list_targets",
323 srcs = ["hwy/tests/list_targets.cc"],
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",
391 "//hwy/contrib/sort:vqsort",
392 "@com_google_googletest//:gtest_main",
400 timeout = "long", # default moderate is not enough for math_test
402 subdir + test + ".cc",
404 copts = COPTS + HWY_TEST_COPTS,
406 "@platforms//cpu:riscv64": ["fully_static_link"],
407 "//conditions:default": [],
410 ":compiler_emscripten": [
412 "-s ENVIRONMENT=node,shell,web",
413 "-s ERROR_ON_UNDEFINED_SYMBOLS=1",
414 "-s DEMANGLE_SUPPORT=1",
416 "-s ALLOW_MEMORY_GROWTH=1",
417 "--pre-js $(location :preamble.js.lds)",
419 "//conditions:default": [],
421 linkstatic = select({
422 "@platforms//cpu:riscv64": True,
423 "//conditions:default": False,
425 local_defines = ["HWY_IS_TEST"],
427 tags = ["hwy_ops_test"],
428 deps = HWY_TEST_DEPS + select({
429 ":compiler_emscripten": [":preamble.js.lds"],
430 "//conditions:default": [],
434 for subdir, test in HWY_TESTS
437 # For manually building the tests we define here (:all does not work in --config=msvc)
439 name = "hwy_ops_tests",
440 tags = ["hwy_ops_test"],
443 # Placeholder for integration test, do not remove