1# 2# Copyright 2019 The Abseil Authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") 18 19# Internal-only implementation classes for Abseil Random 20load( 21 "//absl:copts/configure_copts.bzl", 22 "ABSL_DEFAULT_COPTS", 23 "ABSL_DEFAULT_LINKOPTS", 24 "ABSL_RANDOM_RANDEN_COPTS", 25 "ABSL_TEST_COPTS", 26 "absl_random_randen_copts_init", 27) 28 29package(default_visibility = [ 30 "//absl/random:__pkg__", 31]) 32 33licenses(["notice"]) # Apache 2.0 34 35cc_library( 36 name = "traits", 37 hdrs = ["traits.h"], 38 copts = ABSL_DEFAULT_COPTS, 39 linkopts = ABSL_DEFAULT_LINKOPTS, 40 visibility = [ 41 "//absl/random:__pkg__", 42 ], 43 deps = ["//absl/base:config"], 44) 45 46cc_library( 47 name = "distribution_caller", 48 hdrs = ["distribution_caller.h"], 49 copts = ABSL_DEFAULT_COPTS, 50 linkopts = ABSL_DEFAULT_LINKOPTS, 51 visibility = [ 52 "//absl/random:__pkg__", 53 ], 54 deps = ["//absl/base:config"], 55) 56 57cc_library( 58 name = "distributions", 59 hdrs = ["distributions.h"], 60 copts = ABSL_DEFAULT_COPTS, 61 linkopts = ABSL_DEFAULT_LINKOPTS, 62 deps = [ 63 ":distribution_caller", 64 ":traits", 65 ":uniform_helper", 66 "//absl/base", 67 "//absl/meta:type_traits", 68 "//absl/strings", 69 ], 70) 71 72cc_library( 73 name = "fast_uniform_bits", 74 hdrs = [ 75 "fast_uniform_bits.h", 76 ], 77 copts = ABSL_DEFAULT_COPTS, 78 linkopts = ABSL_DEFAULT_LINKOPTS, 79 visibility = [ 80 "//absl/random:__pkg__", 81 ], 82 deps = ["//absl/base:config"], 83) 84 85cc_library( 86 name = "seed_material", 87 srcs = [ 88 "seed_material.cc", 89 ], 90 hdrs = [ 91 "seed_material.h", 92 ], 93 copts = ABSL_DEFAULT_COPTS, 94 linkopts = ABSL_DEFAULT_LINKOPTS + select({ 95 "//absl:windows": ["-DEFAULTLIB:bcrypt.lib"], 96 "//conditions:default": [], 97 }), 98 deps = [ 99 ":fast_uniform_bits", 100 "//absl/base:core_headers", 101 "//absl/base:raw_logging_internal", 102 "//absl/strings", 103 "//absl/types:optional", 104 "//absl/types:span", 105 ], 106) 107 108cc_library( 109 name = "pool_urbg", 110 srcs = [ 111 "pool_urbg.cc", 112 ], 113 hdrs = [ 114 "pool_urbg.h", 115 ], 116 copts = ABSL_DEFAULT_COPTS, 117 linkopts = select({ 118 "//absl:windows": [], 119 "//conditions:default": ["-pthread"], 120 }) + ABSL_DEFAULT_LINKOPTS, 121 deps = [ 122 ":randen", 123 ":seed_material", 124 ":traits", 125 "//absl/base", 126 "//absl/base:config", 127 "//absl/base:core_headers", 128 "//absl/base:endian", 129 "//absl/base:raw_logging_internal", 130 "//absl/random:seed_gen_exception", 131 "//absl/types:span", 132 ], 133) 134 135cc_library( 136 name = "explicit_seed_seq", 137 testonly = 1, 138 hdrs = [ 139 "explicit_seed_seq.h", 140 ], 141 copts = ABSL_DEFAULT_COPTS, 142 linkopts = ABSL_DEFAULT_LINKOPTS, 143 deps = ["//absl/base:config"], 144) 145 146cc_library( 147 name = "sequence_urbg", 148 testonly = 1, 149 hdrs = [ 150 "sequence_urbg.h", 151 ], 152 copts = ABSL_DEFAULT_COPTS, 153 linkopts = ABSL_DEFAULT_LINKOPTS, 154 deps = ["//absl/base:config"], 155) 156 157cc_library( 158 name = "salted_seed_seq", 159 hdrs = [ 160 "salted_seed_seq.h", 161 ], 162 copts = ABSL_DEFAULT_COPTS, 163 linkopts = ABSL_DEFAULT_LINKOPTS, 164 deps = [ 165 ":seed_material", 166 "//absl/container:inlined_vector", 167 "//absl/meta:type_traits", 168 "//absl/types:optional", 169 "//absl/types:span", 170 ], 171) 172 173cc_library( 174 name = "iostream_state_saver", 175 hdrs = ["iostream_state_saver.h"], 176 copts = ABSL_DEFAULT_COPTS, 177 linkopts = ABSL_DEFAULT_LINKOPTS, 178 deps = [ 179 "//absl/meta:type_traits", 180 "//absl/numeric:int128", 181 ], 182) 183 184cc_library( 185 name = "generate_real", 186 hdrs = [ 187 "generate_real.h", 188 ], 189 copts = ABSL_DEFAULT_COPTS, 190 linkopts = ABSL_DEFAULT_LINKOPTS, 191 deps = [ 192 ":fastmath", 193 ":traits", 194 "//absl/base:bits", 195 "//absl/meta:type_traits", 196 ], 197) 198 199cc_library( 200 name = "fastmath", 201 hdrs = [ 202 "fastmath.h", 203 ], 204 copts = ABSL_DEFAULT_COPTS, 205 linkopts = ABSL_DEFAULT_LINKOPTS, 206 deps = ["//absl/base:bits"], 207) 208 209cc_library( 210 name = "wide_multiply", 211 hdrs = ["wide_multiply.h"], 212 copts = ABSL_DEFAULT_COPTS, 213 linkopts = ABSL_DEFAULT_LINKOPTS, 214 deps = [ 215 ":traits", 216 "//absl/base:bits", 217 "//absl/base:config", 218 "//absl/numeric:int128", 219 ], 220) 221 222cc_library( 223 name = "nonsecure_base", 224 hdrs = ["nonsecure_base.h"], 225 copts = ABSL_DEFAULT_COPTS, 226 linkopts = ABSL_DEFAULT_LINKOPTS, 227 deps = [ 228 ":pool_urbg", 229 ":salted_seed_seq", 230 ":seed_material", 231 "//absl/base:core_headers", 232 "//absl/meta:type_traits", 233 "//absl/strings", 234 "//absl/types:optional", 235 "//absl/types:span", 236 ], 237) 238 239cc_library( 240 name = "pcg_engine", 241 hdrs = ["pcg_engine.h"], 242 copts = ABSL_DEFAULT_COPTS, 243 linkopts = ABSL_DEFAULT_LINKOPTS, 244 deps = [ 245 ":fastmath", 246 ":iostream_state_saver", 247 "//absl/base:config", 248 "//absl/meta:type_traits", 249 "//absl/numeric:int128", 250 ], 251) 252 253cc_library( 254 name = "randen_engine", 255 hdrs = ["randen_engine.h"], 256 copts = ABSL_DEFAULT_COPTS, 257 linkopts = ABSL_DEFAULT_LINKOPTS, 258 deps = [ 259 ":iostream_state_saver", 260 ":randen", 261 "//absl/meta:type_traits", 262 ], 263) 264 265cc_library( 266 name = "platform", 267 hdrs = [ 268 "randen_traits.h", 269 ], 270 copts = ABSL_DEFAULT_COPTS, 271 linkopts = ABSL_DEFAULT_LINKOPTS, 272 textual_hdrs = [ 273 "randen-keys.inc", 274 "platform.h", 275 ], 276 deps = ["//absl/base:config"], 277) 278 279cc_library( 280 name = "randen", 281 srcs = [ 282 "randen.cc", 283 ], 284 hdrs = [ 285 "randen.h", 286 ], 287 copts = ABSL_DEFAULT_COPTS, 288 linkopts = ABSL_DEFAULT_LINKOPTS, 289 deps = [ 290 ":platform", 291 ":randen_hwaes", 292 ":randen_slow", 293 "//absl/base:raw_logging_internal", 294 ], 295) 296 297cc_library( 298 name = "randen_slow", 299 srcs = ["randen_slow.cc"], 300 hdrs = ["randen_slow.h"], 301 copts = ABSL_DEFAULT_COPTS, 302 linkopts = ABSL_DEFAULT_LINKOPTS, 303 deps = [ 304 ":platform", 305 "//absl/base:config", 306 "//absl/base:core_headers", 307 ], 308) 309 310absl_random_randen_copts_init() 311 312cc_library( 313 name = "randen_hwaes", 314 srcs = [ 315 "randen_detect.cc", 316 ], 317 hdrs = [ 318 "randen_detect.h", 319 "randen_hwaes.h", 320 ], 321 copts = ABSL_DEFAULT_COPTS, 322 linkopts = ABSL_DEFAULT_LINKOPTS, 323 deps = [ 324 ":platform", 325 ":randen_hwaes_impl", 326 "//absl/base:config", 327 ], 328) 329 330# build with --save_temps to see assembly language output. 331cc_library( 332 name = "randen_hwaes_impl", 333 srcs = [ 334 "randen_hwaes.cc", 335 "randen_hwaes.h", 336 ], 337 copts = ABSL_DEFAULT_COPTS + ABSL_RANDOM_RANDEN_COPTS + select({ 338 "//absl:windows": [], 339 "//conditions:default": ["-Wno-pass-failed"], 340 }), 341 # copts in RANDEN_HWAES_COPTS can make this target unusable as a module 342 # leading to a Clang diagnostic. Furthermore, it only has a private header 343 # anyway and thus there wouldn't be any gain from using it as a module. 344 features = ["-header_modules"], 345 linkopts = ABSL_DEFAULT_LINKOPTS, 346 deps = [ 347 ":platform", 348 "//absl/base:config", 349 "//absl/base:core_headers", 350 ], 351) 352 353cc_binary( 354 name = "gaussian_distribution_gentables", 355 srcs = [ 356 "gaussian_distribution_gentables.cc", 357 ], 358 linkopts = ABSL_DEFAULT_LINKOPTS, 359 deps = [ 360 "//absl/base:core_headers", 361 "//absl/random:distributions", 362 ], 363) 364 365cc_library( 366 name = "distribution_test_util", 367 testonly = 1, 368 srcs = [ 369 "chi_square.cc", 370 "distribution_test_util.cc", 371 ], 372 hdrs = [ 373 "chi_square.h", 374 "distribution_test_util.h", 375 ], 376 copts = ABSL_DEFAULT_COPTS, 377 linkopts = ABSL_DEFAULT_LINKOPTS, 378 deps = [ 379 "//absl/base:config", 380 "//absl/base:core_headers", 381 "//absl/base:raw_logging_internal", 382 "//absl/strings", 383 "//absl/strings:str_format", 384 "//absl/types:span", 385 ], 386) 387 388# Common tags for tests, etc. 389ABSL_RANDOM_NONPORTABLE_TAGS = [ 390 "no_test_android_arm", 391 "no_test_android_arm64", 392 "no_test_android_x86", 393 "no_test_darwin_x86_64", 394 "no_test_ios_x86_64", 395 "no_test_loonix", 396 "no_test_msvc_x64", 397 "no_test_wasm", 398] 399 400cc_test( 401 name = "traits_test", 402 size = "small", 403 srcs = ["traits_test.cc"], 404 copts = ABSL_TEST_COPTS, 405 linkopts = ABSL_DEFAULT_LINKOPTS, 406 deps = [ 407 ":traits", 408 "@com_google_googletest//:gtest_main", 409 ], 410) 411 412cc_test( 413 name = "generate_real_test", 414 size = "small", 415 srcs = [ 416 "generate_real_test.cc", 417 ], 418 copts = ABSL_TEST_COPTS, 419 linkopts = ABSL_DEFAULT_LINKOPTS, 420 deps = [ 421 ":generate_real", 422 "//absl/base:bits", 423 "//absl/flags:flag", 424 "@com_google_googletest//:gtest_main", 425 ], 426) 427 428cc_test( 429 name = "distribution_test_util_test", 430 size = "small", 431 srcs = ["distribution_test_util_test.cc"], 432 copts = ABSL_TEST_COPTS, 433 linkopts = ABSL_DEFAULT_LINKOPTS, 434 deps = [ 435 ":distribution_test_util", 436 "@com_google_googletest//:gtest_main", 437 ], 438) 439 440cc_test( 441 name = "fastmath_test", 442 size = "small", 443 srcs = ["fastmath_test.cc"], 444 copts = ABSL_TEST_COPTS, 445 linkopts = ABSL_DEFAULT_LINKOPTS, 446 deps = [ 447 ":fastmath", 448 "@com_google_googletest//:gtest_main", 449 ], 450) 451 452cc_test( 453 name = "explicit_seed_seq_test", 454 size = "small", 455 srcs = ["explicit_seed_seq_test.cc"], 456 copts = ABSL_TEST_COPTS, 457 linkopts = ABSL_DEFAULT_LINKOPTS, 458 deps = [ 459 ":explicit_seed_seq", 460 "//absl/random:seed_sequences", 461 "@com_google_googletest//:gtest_main", 462 ], 463) 464 465cc_test( 466 name = "salted_seed_seq_test", 467 size = "small", 468 srcs = ["salted_seed_seq_test.cc"], 469 copts = ABSL_TEST_COPTS, 470 linkopts = ABSL_DEFAULT_LINKOPTS, 471 deps = [ 472 ":salted_seed_seq", 473 "@com_google_googletest//:gtest_main", 474 ], 475) 476 477cc_test( 478 name = "chi_square_test", 479 size = "small", 480 srcs = [ 481 "chi_square_test.cc", 482 ], 483 copts = ABSL_TEST_COPTS, 484 linkopts = ABSL_DEFAULT_LINKOPTS, 485 deps = [ 486 ":distribution_test_util", 487 "//absl/base:core_headers", 488 "@com_google_googletest//:gtest_main", 489 ], 490) 491 492cc_test( 493 name = "fast_uniform_bits_test", 494 size = "small", 495 srcs = [ 496 "fast_uniform_bits_test.cc", 497 ], 498 copts = ABSL_TEST_COPTS, 499 linkopts = ABSL_DEFAULT_LINKOPTS, 500 deps = [ 501 ":fast_uniform_bits", 502 "@com_google_googletest//:gtest_main", 503 ], 504) 505 506cc_library( 507 name = "mocking_bit_gen_base", 508 hdrs = ["mocking_bit_gen_base.h"], 509 linkopts = ABSL_DEFAULT_LINKOPTS, 510 deps = [ 511 "//absl/random", 512 "//absl/strings", 513 ], 514) 515 516cc_library( 517 name = "mock_overload_set", 518 testonly = 1, 519 hdrs = ["mock_overload_set.h"], 520 visibility = [ 521 "//absl/random:__pkg__", 522 ], 523 deps = [ 524 "//absl/random:mocking_bit_gen", 525 "@com_google_googletest//:gtest", 526 ], 527) 528 529cc_test( 530 name = "nonsecure_base_test", 531 size = "small", 532 srcs = [ 533 "nonsecure_base_test.cc", 534 ], 535 copts = ABSL_TEST_COPTS, 536 linkopts = ABSL_DEFAULT_LINKOPTS, 537 deps = [ 538 ":nonsecure_base", 539 "//absl/random", 540 "//absl/random:distributions", 541 "//absl/random:seed_sequences", 542 "//absl/strings", 543 "@com_google_googletest//:gtest_main", 544 ], 545) 546 547cc_test( 548 name = "seed_material_test", 549 size = "small", 550 srcs = ["seed_material_test.cc"], 551 copts = ABSL_TEST_COPTS, 552 linkopts = ABSL_DEFAULT_LINKOPTS, 553 deps = [ 554 ":seed_material", 555 "@com_google_googletest//:gtest_main", 556 ], 557) 558 559cc_test( 560 name = "pool_urbg_test", 561 size = "small", 562 srcs = [ 563 "pool_urbg_test.cc", 564 ], 565 copts = ABSL_TEST_COPTS, 566 linkopts = ABSL_DEFAULT_LINKOPTS, 567 deps = [ 568 ":pool_urbg", 569 "//absl/meta:type_traits", 570 "//absl/types:span", 571 "@com_google_googletest//:gtest_main", 572 ], 573) 574 575cc_test( 576 name = "pcg_engine_test", 577 size = "medium", # Trying to measure accuracy. 578 srcs = ["pcg_engine_test.cc"], 579 copts = ABSL_TEST_COPTS, 580 flaky = 1, 581 linkopts = ABSL_DEFAULT_LINKOPTS, 582 deps = [ 583 ":explicit_seed_seq", 584 ":pcg_engine", 585 "//absl/time", 586 "@com_google_googletest//:gtest_main", 587 ], 588) 589 590cc_test( 591 name = "randen_engine_test", 592 size = "medium", 593 srcs = [ 594 "randen_engine_test.cc", 595 ], 596 copts = ABSL_TEST_COPTS, 597 linkopts = ABSL_DEFAULT_LINKOPTS, 598 deps = [ 599 ":explicit_seed_seq", 600 ":randen_engine", 601 "//absl/base:raw_logging_internal", 602 "//absl/strings", 603 "//absl/time", 604 "@com_google_googletest//:gtest_main", 605 ], 606) 607 608cc_test( 609 name = "randen_test", 610 size = "small", 611 srcs = ["randen_test.cc"], 612 copts = ABSL_TEST_COPTS, 613 linkopts = ABSL_DEFAULT_LINKOPTS, 614 deps = [ 615 ":randen", 616 "//absl/meta:type_traits", 617 "@com_google_googletest//:gtest_main", 618 ], 619) 620 621cc_test( 622 name = "randen_slow_test", 623 size = "small", 624 srcs = ["randen_slow_test.cc"], 625 copts = ABSL_TEST_COPTS, 626 linkopts = ABSL_DEFAULT_LINKOPTS, 627 deps = [ 628 ":randen_slow", 629 "@com_google_googletest//:gtest_main", 630 ], 631) 632 633cc_test( 634 name = "randen_hwaes_test", 635 size = "small", 636 srcs = ["randen_hwaes_test.cc"], 637 copts = ABSL_TEST_COPTS, 638 linkopts = ABSL_DEFAULT_LINKOPTS, 639 tags = ABSL_RANDOM_NONPORTABLE_TAGS, 640 deps = [ 641 ":platform", 642 ":randen_hwaes", 643 ":randen_hwaes_impl", # build_cleaner: keep 644 "//absl/base:raw_logging_internal", 645 "//absl/strings:str_format", 646 "@com_google_googletest//:gtest", 647 ], 648) 649 650cc_test( 651 name = "wide_multiply_test", 652 size = "small", 653 srcs = ["wide_multiply_test.cc"], 654 copts = ABSL_TEST_COPTS, 655 linkopts = ABSL_DEFAULT_LINKOPTS, 656 deps = [ 657 ":wide_multiply", 658 "//absl/base:bits", 659 "//absl/numeric:int128", 660 "@com_google_googletest//:gtest_main", 661 ], 662) 663 664cc_library( 665 name = "nanobenchmark", 666 srcs = ["nanobenchmark.cc"], 667 linkopts = ABSL_DEFAULT_LINKOPTS, 668 textual_hdrs = ["nanobenchmark.h"], 669 deps = [ 670 ":platform", 671 ":randen_engine", 672 "//absl/base:core_headers", 673 "//absl/base:raw_logging_internal", 674 ], 675) 676 677cc_library( 678 name = "uniform_helper", 679 hdrs = ["uniform_helper.h"], 680 copts = ABSL_DEFAULT_COPTS, 681 linkopts = ABSL_DEFAULT_LINKOPTS, 682 deps = [ 683 "//absl/meta:type_traits", 684 ], 685) 686 687cc_test( 688 name = "nanobenchmark_test", 689 size = "small", 690 srcs = ["nanobenchmark_test.cc"], 691 flaky = 1, 692 linkopts = ABSL_DEFAULT_LINKOPTS, 693 tags = [ 694 "benchmark", 695 "no_test_ios_x86_64", 696 "no_test_loonix", # Crashing. 697 ], 698 deps = [ 699 ":nanobenchmark", 700 "//absl/base:raw_logging_internal", 701 "//absl/strings", 702 ], 703) 704 705cc_test( 706 name = "randen_benchmarks", 707 size = "medium", 708 srcs = ["randen_benchmarks.cc"], 709 copts = ABSL_TEST_COPTS + ABSL_RANDOM_RANDEN_COPTS, 710 flaky = 1, 711 linkopts = ABSL_DEFAULT_LINKOPTS, 712 tags = ABSL_RANDOM_NONPORTABLE_TAGS + ["benchmark"], 713 deps = [ 714 ":nanobenchmark", 715 ":platform", 716 ":randen", 717 ":randen_engine", 718 ":randen_hwaes", 719 ":randen_hwaes_impl", 720 ":randen_slow", 721 "//absl/base:raw_logging_internal", 722 "//absl/strings", 723 ], 724) 725 726cc_test( 727 name = "iostream_state_saver_test", 728 size = "small", 729 srcs = ["iostream_state_saver_test.cc"], 730 linkopts = ABSL_DEFAULT_LINKOPTS, 731 deps = [ 732 ":iostream_state_saver", 733 "@com_google_googletest//:gtest_main", 734 ], 735) 736