Skip to content

Commit 5a402ac

Browse files
authored
[libc][bazel] Add Bazel rules for rand/srand functions. (#159617)
These functions are unlikely to be used in the overlay mode (since they are stateful), but it's worth verifying the correctness of underlying RNG (which may be reused in other places) in Bazel build regardless.
1 parent a666286 commit 5a402ac

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ libc_support_library(
278278
hdrs = ["hdr/stdio_overlay.h"],
279279
)
280280

281+
libc_support_library(
282+
name = "hdr_stdlib_macros",
283+
hdrs = ["hdr/stdlib_macros.h"],
284+
deps = [
285+
":hdr_stdlib_overlay",
286+
],
287+
)
288+
281289
libc_support_library(
282290
name = "hdr_stdlib_overlay",
283291
hdrs = ["hdr/stdlib_overlay.h"],
@@ -5066,6 +5074,41 @@ libc_function(
50665074
],
50675075
)
50685076

5077+
libc_support_library(
5078+
name = "rand_util",
5079+
srcs = ["src/stdlib/rand_util.cpp"],
5080+
hdrs = ["src/stdlib/rand_util.h"],
5081+
deps = [
5082+
":__support_cpp_atomic",
5083+
":__support_macros_attributes",
5084+
":__support_macros_config",
5085+
],
5086+
)
5087+
5088+
libc_function(
5089+
name = "rand",
5090+
srcs = ["src/stdlib/rand.cpp"],
5091+
hdrs = ["src/stdlib/rand.h"],
5092+
deps = [
5093+
":__support_common",
5094+
":__support_macros_config",
5095+
":__support_threads_sleep",
5096+
":hdr_stdlib_macros",
5097+
":rand_util",
5098+
],
5099+
)
5100+
5101+
libc_function(
5102+
name = "srand",
5103+
srcs = ["src/stdlib/srand.cpp"],
5104+
hdrs = ["src/stdlib/srand.h"],
5105+
deps = [
5106+
":__support_common",
5107+
":__support_macros_config",
5108+
":rand_util",
5109+
],
5110+
)
5111+
50695112
libc_support_library(
50705113
name = "str_from_util",
50715114
hdrs = ["src/stdlib/str_from_util.h"],

utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ libc_test(
159159
],
160160
)
161161

162+
libc_test(
163+
name = "rand_test",
164+
srcs = ["rand_test.cpp"],
165+
deps = [
166+
"//libc:rand",
167+
"//libc:srand",
168+
],
169+
)
170+
162171
libc_test_library(
163172
name = "strfrom_test_helper",
164173
hdrs = ["StrfromTest.h"],

0 commit comments

Comments
 (0)