BUILD (13875B)
1 # Placeholder for cc_test, do not remove 2 load("@bazel_skylib//lib:selects.bzl", "selects") 3 load("//:hwy_tests.bzl", "HWY_TESTS") 4 load("@rules_license//rules:license.bzl", "license") 5 6 package( 7 default_applicable_licenses = ["//:license"], 8 default_visibility = ["//visibility:public"], 9 ) 10 11 license( 12 name = "license", 13 package_name = "highway", 14 license_kinds = ["@rules_license//licenses/generic:notice"], 15 ) 16 17 # Dual-licensed Apache 2 and 3-clause BSD. 18 licenses(["notice"]) 19 20 exports_files(["LICENSE"]) 21 22 # Detect compiler: 23 config_setting( 24 name = "compiler_clang", 25 flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"}, 26 ) 27 28 config_setting( 29 name = "compiler_clangcl", 30 flag_values = {"@bazel_tools//tools/cpp:compiler": "lexan"}, 31 ) 32 33 config_setting( 34 name = "compiler_msvc", 35 flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"}, 36 ) 37 38 config_setting( 39 name = "compiler_emscripten", 40 constraint_values = [ 41 "@platforms//cpu:wasm32", 42 ], 43 ) 44 45 # See https://github.com/bazelbuild/bazel/issues/12707 46 config_setting( 47 name = "compiler_gcc_bug", 48 flag_values = { 49 "@bazel_tools//tools/cpp:compiler": "compiler", 50 }, 51 ) 52 53 config_setting( 54 name = "compiler_gcc_actual", 55 flag_values = { 56 "@bazel_tools//tools/cpp:compiler": "gcc", 57 }, 58 ) 59 60 selects.config_setting_group( 61 name = "compiler_gcc", 62 match_any = [ 63 ":compiler_gcc_bug", 64 ":compiler_gcc_actual", 65 ], 66 ) 67 68 # Additional warnings for Clang OR GCC (skip for MSVC) 69 CLANG_GCC_COPTS = [ 70 "-Wunused", 71 "-Wextra-semi", 72 "-Wunreachable-code", 73 "-Wshadow", 74 "-Wmissing-declarations", 75 ] 76 77 # Warnings supported by Clang and Clang-cl 78 CLANG_OR_CLANGCL_OPTS = CLANG_GCC_COPTS + [ 79 "-Wfloat-overflow-conversion", 80 "-Wfloat-zero-conversion", 81 "-Wfor-loop-analysis", 82 "-Wgnu-redeclared-enum", 83 "-Winfinite-recursion", 84 "-Wliteral-conversion", 85 "-Wno-c++98-compat", 86 "-Wno-unused-command-line-argument", 87 "-Wprivate-header", 88 "-Wself-assign", 89 "-Wstring-conversion", 90 "-Wtautological-overlap-compare", 91 "-Wthread-safety-analysis", 92 "-Wundefined-func-template", 93 "-Wunreachable-code-aggressive", 94 "-Wunused-comparison", 95 ] 96 97 # Warnings only supported by Clang, but not Clang-cl 98 CLANG_ONLY_COPTS = CLANG_OR_CLANGCL_OPTS + [ 99 # Do not treat the third_party headers as system headers when building 100 # highway - the errors are pertinent. 101 "--no-system-header-prefix=third_party/highway", 102 ] 103 104 COPTS = select({ 105 ":compiler_msvc": [], 106 ":compiler_gcc": CLANG_GCC_COPTS, 107 ":compiler_clangcl": CLANG_OR_CLANGCL_OPTS, 108 # Default to clang because compiler detection only works in Bazel 109 "//conditions:default": CLANG_ONLY_COPTS, 110 }) + select({ 111 "@platforms//cpu:riscv64": [ 112 "-march=rv64gcv1p0", 113 "-menable-experimental-extensions", 114 ], 115 "//conditions:default": [ 116 ], 117 }) 118 119 DEFINES = select({ 120 ":compiler_msvc": ["HWY_SHARED_DEFINE"], 121 ":compiler_clangcl": ["HWY_SHARED_DEFINE"], 122 "//conditions:default": [], 123 }) 124 125 # Unused on Bazel builds, where this is not defined/known; Copybara replaces 126 # usages with an empty list. 127 COMPAT = [ 128 "//buildenv/target:non_prod", # includes mobile/vendor. 129 ] 130 131 # WARNING: changing flags such as HWY_DISABLED_TARGETS may break users without 132 # failing integration tests, if the machine running tests does not support the 133 # newly enabled instruction set, or the failure is only caught by sanitizers 134 # which do not run in CI. 135 136 # NOTE: when adding a new dependency on the Highway library, please add your 137 # test to the highway.users list in highway.blueprint. 138 cc_library( 139 name = "hwy", 140 srcs = [ 141 "hwy/abort.cc", 142 "hwy/aligned_allocator.cc", 143 "hwy/per_target.cc", 144 "hwy/print.cc", 145 "hwy/targets.cc", 146 ], 147 # Normal headers with include guards 148 hdrs = [ 149 "hwy/abort.h", 150 "hwy/aligned_allocator.h", 151 "hwy/base.h", 152 "hwy/cache_control.h", 153 "hwy/detect_compiler_arch.h", # private 154 "hwy/print.h", 155 "hwy/x86_cpuid.h", 156 ], 157 compatible_with = [], 158 copts = COPTS, 159 defines = DEFINES, 160 local_defines = ["hwy_EXPORTS"], 161 textual_hdrs = [ 162 # These are textual because config macros influence them: 163 "hwy/detect_targets.h", # private 164 "hwy/targets.h", 165 # This .cc file #includes itself through foreach_target.h 166 "hwy/per_target.cc", 167 # End of list 168 "hwy/highway.h", # public 169 "hwy/foreach_target.h", # public 170 "hwy/per_target.h", # public 171 "hwy/print-inl.h", # public 172 "hwy/highway_export.h", # public 173 "hwy/ops/arm_neon-inl.h", 174 "hwy/ops/arm_sve-inl.h", 175 "hwy/ops/emu128-inl.h", 176 "hwy/ops/generic_ops-inl.h", 177 "hwy/ops/inside-inl.h", 178 "hwy/ops/scalar-inl.h", 179 "hwy/ops/set_macros-inl.h", 180 "hwy/ops/shared-inl.h", 181 "hwy/ops/x86_128-inl.h", 182 "hwy/ops/x86_256-inl.h", 183 "hwy/ops/x86_512-inl.h", 184 "hwy/ops/x86_avx3-inl.h", 185 # Select avoids recompiling native arch if only non-native changed 186 ] + select({ 187 ":compiler_emscripten": [ 188 "hwy/ops/wasm_128-inl.h", 189 "hwy/ops/wasm_256-inl.h", 190 ], 191 "//conditions:default": [], 192 }) + select({ 193 "@platforms//cpu:riscv64": ["hwy/ops/rvv-inl.h"], 194 "//conditions:default": [], 195 }), 196 ) 197 198 cc_library( 199 name = "stats", 200 srcs = ["hwy/stats.cc"], 201 hdrs = ["hwy/stats.h"], 202 compatible_with = [], 203 copts = COPTS, 204 deps = [":hwy"], 205 ) 206 207 cc_library( 208 name = "robust_statistics", 209 hdrs = ["hwy/robust_statistics.h"], 210 compatible_with = [], 211 copts = COPTS, 212 deps = [":hwy"], 213 ) 214 215 cc_library( 216 name = "timer", 217 srcs = ["hwy/timer.cc"], 218 hdrs = ["hwy/timer.h"], 219 compatible_with = [], 220 copts = COPTS, 221 # Deprecated. 222 textual_hdrs = [ 223 "hwy/timer-inl.h", 224 ], 225 deps = [ 226 ":hwy", 227 ":robust_statistics", 228 ], 229 ) 230 231 # Previously provided timer.*, use :timer instead. 232 cc_library( 233 name = "nanobenchmark", 234 srcs = ["hwy/nanobenchmark.cc"], 235 hdrs = [ 236 "hwy/nanobenchmark.h", 237 # TODO(janwas): remove after users depend on :timer. 238 "hwy/timer.h", 239 ], 240 compatible_with = [], 241 copts = COPTS, 242 local_defines = ["hwy_EXPORTS"], 243 deps = [ 244 ":hwy", 245 ":robust_statistics", 246 ":timer", 247 ], 248 ) 249 250 cc_library( 251 name = "bit_set", 252 hdrs = ["hwy/bit_set.h"], 253 compatible_with = [], 254 copts = COPTS, 255 deps = [ 256 ":hwy", # HWY_DASSERT 257 ], 258 ) 259 260 cc_library( 261 name = "auto_tune", 262 hdrs = ["hwy/auto_tune.h"], 263 compatible_with = [], 264 copts = COPTS, 265 deps = [ 266 ":hwy", 267 "//hwy/contrib/sort:vqsort", 268 ], 269 ) 270 271 cc_library( 272 name = "perf_counters", 273 srcs = ["hwy/perf_counters.cc"], 274 hdrs = ["hwy/perf_counters.h"], 275 compatible_with = [], 276 copts = COPTS, 277 deps = [ 278 ":bit_set", 279 ":hwy", 280 ":timer", 281 ], 282 ) 283 284 cc_library( 285 name = "profiler", 286 srcs = ["hwy/profiler.cc"], 287 hdrs = ["hwy/profiler.h"], 288 compatible_with = [], 289 copts = COPTS, 290 deps = [ 291 ":bit_set", 292 ":hwy", 293 ":robust_statistics", 294 ":timer", 295 ], 296 ) 297 298 cc_binary( 299 name = "profiler_example", 300 srcs = ["hwy/examples/profiler_example.cc"], 301 copts = COPTS, 302 deps = [ 303 ":hwy", 304 ":profiler", 305 ":thread_pool", 306 ":timer", 307 ], 308 ) 309 310 cc_library( 311 name = "algo", 312 compatible_with = [], 313 copts = COPTS, 314 textual_hdrs = [ 315 "hwy/contrib/algo/copy-inl.h", 316 "hwy/contrib/algo/find-inl.h", 317 "hwy/contrib/algo/transform-inl.h", 318 ], 319 deps = [ 320 ":hwy", 321 ], 322 ) 323 324 cc_library( 325 name = "bit_pack", 326 compatible_with = [], 327 copts = COPTS, 328 textual_hdrs = [ 329 "hwy/contrib/bit_pack/bit_pack-inl.h", 330 ], 331 deps = [ 332 ":hwy", 333 ], 334 ) 335 336 cc_library( 337 name = "dot", 338 compatible_with = [], 339 copts = COPTS, 340 textual_hdrs = [ 341 "hwy/contrib/dot/dot-inl.h", 342 ], 343 deps = [ 344 ":hwy", 345 ], 346 ) 347 348 cc_library( 349 name = "topology", 350 srcs = ["hwy/contrib/thread_pool/topology.cc"], 351 hdrs = ["hwy/contrib/thread_pool/topology.h"], 352 compatible_with = [], 353 copts = COPTS, 354 deps = [ 355 ":bit_set", 356 ":hwy", 357 ], 358 ) 359 360 cc_library( 361 name = "thread_pool", 362 srcs = [ 363 "hwy/contrib/thread_pool/thread_pool.cc", 364 ], 365 hdrs = [ 366 "hwy/contrib/thread_pool/futex.h", 367 "hwy/contrib/thread_pool/spin.h", 368 "hwy/contrib/thread_pool/thread_pool.h", 369 ], 370 compatible_with = [], 371 copts = COPTS, 372 deps = [ 373 ":auto_tune", 374 ":bit_set", 375 ":hwy", 376 ":profiler", 377 ":stats", 378 ":timer", 379 ":topology", 380 ], 381 ) 382 383 cc_library( 384 name = "matvec", 385 compatible_with = [], 386 copts = COPTS, 387 textual_hdrs = [ 388 "hwy/contrib/matvec/matvec-inl.h", 389 ], 390 deps = [ 391 ":hwy", 392 ":thread_pool", 393 ], 394 ) 395 396 cc_library( 397 name = "image", 398 srcs = [ 399 "hwy/contrib/image/image.cc", 400 ], 401 hdrs = [ 402 "hwy/contrib/image/image.h", 403 ], 404 compatible_with = [], 405 copts = COPTS, 406 local_defines = ["hwy_contrib_EXPORTS"], 407 deps = [ 408 ":hwy", 409 ], 410 ) 411 412 cc_library( 413 name = "math", 414 compatible_with = [], 415 copts = COPTS, 416 textual_hdrs = [ 417 "hwy/contrib/math/math-inl.h", 418 ], 419 deps = [ 420 ":hwy", 421 ], 422 ) 423 424 cc_library( 425 name = "random", 426 compatible_with = [], 427 copts = COPTS, 428 textual_hdrs = [ 429 "hwy/contrib/random/random-inl.h", 430 ], 431 deps = [ 432 ":hwy", 433 ], 434 ) 435 436 cc_library( 437 name = "unroller", 438 compatible_with = [], 439 copts = COPTS, 440 textual_hdrs = [ 441 "hwy/contrib/unroller/unroller-inl.h", 442 ], 443 deps = [ 444 ":hwy", 445 ], 446 ) 447 448 # Everything required for tests that use Highway. 449 cc_library( 450 name = "hwy_test_util", 451 srcs = ["hwy/tests/test_util.cc"], 452 hdrs = ["hwy/tests/test_util.h"], 453 compatible_with = [], 454 copts = COPTS, 455 local_defines = ["hwy_test_EXPORTS"], 456 textual_hdrs = [ 457 "hwy/tests/test_util-inl.h", 458 "hwy/tests/hwy_gtest.h", 459 ], 460 # Must not depend on a gtest variant, which can conflict with the 461 # GUNIT_INTERNAL_BUILD_MODE defined by the test. 462 deps = [ 463 ":hwy", 464 ":nanobenchmark", 465 ], 466 ) 467 468 cc_binary( 469 name = "benchmark", 470 srcs = ["hwy/examples/benchmark.cc"], 471 copts = COPTS, 472 deps = [ 473 ":hwy", 474 ":nanobenchmark", 475 ], 476 ) 477 478 cc_library( 479 name = "skeleton", 480 srcs = ["hwy/examples/skeleton.cc"], 481 hdrs = ["hwy/examples/skeleton.h"], 482 copts = COPTS, 483 local_defines = ["hwy_EXPORTS"], 484 textual_hdrs = ["hwy/examples/skeleton-inl.h"], 485 deps = [ 486 ":hwy", 487 ], 488 ) 489 490 cc_library( 491 name = "abort_header_only", 492 hdrs = [ 493 "hwy/abort.h", 494 "hwy/base.h", 495 "hwy/detect_compiler_arch.h", # private 496 "hwy/highway_export.h", # public 497 ], 498 compatible_with = [], 499 copts = COPTS, 500 local_defines = ["HWY_HEADER_ONLY"], 501 ) 502 503 cc_test( 504 name = "list_targets", 505 size = "small", 506 srcs = ["hwy/tests/list_targets.cc"], 507 deps = [ 508 ":hwy", 509 ":timer", 510 ], 511 ) 512 513 cc_test( 514 name = "abort_header_only_test", 515 size = "small", 516 srcs = ["hwy/abort_header_only_test.cc"], 517 deps = [ 518 ":abort_header_only", 519 ":hwy_test_util", 520 "@com_google_googletest//:gtest_main", 521 ], 522 ) 523 524 HWY_TEST_COPTS = select({ 525 ":compiler_msvc": [], 526 "//conditions:default": [ 527 # gTest triggers this warning (which is enabled by the 528 # extra-semi in COPTS), so we need to disable it here, 529 # but it's still enabled for :hwy. 530 "-Wno-c++98-compat-extra-semi", 531 ], 532 }) 533 534 # Common to all tests. 535 HWY_TEST_DEPS = [ 536 ":hwy_test_util", 537 ":hwy", 538 ":nanobenchmark", 539 ":timer", 540 ] + select({ 541 ":compiler_msvc": [], 542 "//conditions:default": ["@com_google_googletest//:gtest_main"], 543 }) 544 545 [ 546 [ 547 cc_test( 548 name = test, 549 size = "medium", 550 timeout = "long", # default moderate is not enough for math_test 551 srcs = [ 552 subdir + test + ".cc", 553 ], 554 copts = COPTS + HWY_TEST_COPTS, 555 # Fixes OOM for matvec_test on RVV. 556 exec_properties = select({ 557 "@platforms//cpu:riscv64": {"mem": "16g"}, 558 "//conditions:default": None, 559 }), 560 features = select({ 561 "@platforms//cpu:riscv64": ["fully_static_link"], 562 "//conditions:default": [], 563 }), 564 linkopts = select({ 565 ":compiler_emscripten": [ 566 "-s ASSERTIONS=2", 567 "-s ENVIRONMENT=node,shell,web", 568 "-s ERROR_ON_UNDEFINED_SYMBOLS=1", 569 "-s EXIT_RUNTIME=1", 570 "-s ALLOW_MEMORY_GROWTH=1", 571 "--pre-js $(location :preamble.js.lds)", 572 ], 573 "//conditions:default": [], 574 }), 575 linkstatic = select({ 576 "@platforms//cpu:riscv64": True, 577 "//conditions:default": False, 578 }), 579 local_defines = ["HWY_IS_TEST"], 580 # Placeholder for malloc, do not remove 581 # for test_suite. 582 tags = ["hwy_ops_test"], 583 deps = HWY_TEST_DEPS + extra_deps + select({ 584 ":compiler_emscripten": [":preamble.js.lds"], 585 "//conditions:default": [], 586 }), 587 ), 588 ] 589 for subdir, test, extra_deps in HWY_TESTS 590 ] 591 592 # For manually building the tests we define here (:all does not work in --config=msvc) 593 test_suite( 594 name = "hwy_ops_tests", 595 tags = ["hwy_ops_test"], 596 )