[llvm] [libc][bazel] Add a helper library with all deps of generated headers. (PR #136582)

Alexey Samsonov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 21 10:23:22 PDT 2025


https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/136582

Create "public_header_deps" that is a convenient way to express dependencies of a generated headers as a single (and same) target. It's also convenient to use it in unit tests - which is also demonstrated in this PR by adding the BUILD.bazel placeholder for test/include unit tests, and creating a libc_test target for one of these tests.

See issue #134780.

>From 3303741a3eec71bdc23e602d4d6c43241f80640c Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Mon, 21 Apr 2025 10:18:50 -0700
Subject: [PATCH] [libc][bazel] Add a helper library with all deps of generated
 headers.

Create "public_header_deps" that is a convenient way to express
dependencies of a generated headers as a single (and same) target. It's
also convenient to use it in unit tests - which is also demonstrated in
this PR by adding the BUILD.bazel placeholder for test/include unit
tests, and creating a libc_test target for one of these tests.

See issue #134780.
---
 .../llvm-project-overlay/libc/BUILD.bazel     | 14 ++++++++++++-
 .../libc/test/include/BUILD.bazel             | 20 +++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel

diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 4412f2beaffcd..fea2cf54ab1ed 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -90,6 +90,18 @@ py_binary(
     main = "utils/hdrgen/hdrgen/main.py",
 )
 
+# Library containing all headers that can be transitively included by generated llvm-libc
+# public headers (or by the unit tests).
+libc_support_library(
+    name = "public_headers_deps",
+    textual_hdrs = [
+        "include/__llvm-libc-common.h",
+    ] + glob([
+        "include/llvm-libc-types/**/*.h",
+        "include/llvm-libc-macros/**/*.h",
+    ]),
+)
+
 ################################## Base Config #################################
 
 libc_support_library(
@@ -1898,11 +1910,11 @@ libc_support_library(
     name = "atan_utils",
     hdrs = ["src/math/generic/atan_utils.h"],
     deps = [
-        ":__support_integer_literals",
         ":__support_fputil_double_double",
         ":__support_fputil_dyadic_float",
         ":__support_fputil_multiply_add",
         ":__support_fputil_polyeval",
+        ":__support_integer_literals",
         ":__support_macros_optimization",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
new file mode 100644
index 0000000000000..361c7c8db6542
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
@@ -0,0 +1,20 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# Tests for LLVM libc public headers.
+
+load("//libc/test:libc_test_rules.bzl", "libc_test")
+
+licenses(["notice"])
+
+libc_test(
+    name = "stdbit_test",
+    srcs = [
+        "stdbit_stub.h",
+        "stdbit_test.cpp",
+    ],
+    deps = [
+        "//libc:public_headers_deps",
+    ],
+)



More information about the llvm-commits mailing list