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