[llvm] [libc][bazel] Add Bazel rules for rand/srand functions. (PR #159617)
Alexey Samsonov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 18 10:49:51 PDT 2025
https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/159617
These functions are unlikely to be used in the overlay mode (since they are stateful), but internal llvm-libc implementation is used in tests for FMA family of functions, so we need Bazel support for them to ensure proper test coverage.
>From 84568a45c8c757e148b45616b1bba949a623273e Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Thu, 18 Sep 2025 10:46:54 -0700
Subject: [PATCH] [libc][bazel] Add Bazel rules for rand/srand functions.
These functions are unlikely to be used in the overlay mode (since they
are stateful), but internal llvm-libc implementation is used in tests
for FMA family of functions, so we need Bazel support for them to ensure
proper test coverage.
---
.../llvm-project-overlay/libc/BUILD.bazel | 43 +++++++++++++++++++
.../libc/test/src/stdlib/BUILD.bazel | 9 ++++
2 files changed, 52 insertions(+)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index cee92f2cc56c4..67c292f08be73 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -278,6 +278,14 @@ libc_support_library(
hdrs = ["hdr/stdio_overlay.h"],
)
+libc_support_library(
+ name = "hdr_stdlib_macros",
+ hdrs = ["hdr/stdlib_macros.h"],
+ deps = [
+ ":hdr_stdlib_overlay",
+ ],
+)
+
libc_support_library(
name = "hdr_stdlib_overlay",
hdrs = ["hdr/stdlib_overlay.h"],
@@ -5066,6 +5074,41 @@ libc_function(
],
)
+libc_support_library(
+ name = "rand_util",
+ srcs = ["src/stdlib/rand_util.cpp"],
+ hdrs = ["src/stdlib/rand_util.h"],
+ deps = [
+ ":__support_cpp_atomic",
+ ":__support_macros_attributes",
+ ":__support_macros_config",
+ ],
+)
+
+libc_function(
+ name = "rand",
+ srcs = ["src/stdlib/rand.cpp"],
+ hdrs = ["src/stdlib/rand.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":__support_threads_sleep",
+ ":hdr_stdlib_macros",
+ ":rand_util",
+ ],
+)
+
+libc_function(
+ name = "srand",
+ srcs = ["src/stdlib/srand.cpp"],
+ hdrs = ["src/stdlib/srand.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":rand_util",
+ ],
+)
+
libc_support_library(
name = "str_from_util",
hdrs = ["src/stdlib/str_from_util.h"],
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel
index ce92ca8caa6f4..fd4389e8c0579 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel
@@ -159,6 +159,15 @@ libc_test(
],
)
+libc_test(
+ name = "rand_test",
+ srcs = ["rand_test.cpp"],
+ deps = [
+ "//libc:rand",
+ "//libc:srand",
+ ],
+)
+
libc_test_library(
name = "strfrom_test_helper",
hdrs = ["StrfromTest.h"],
More information about the llvm-commits
mailing list