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