Skip to content

Conversation

@vonosmas
Copy link
Contributor

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.

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 llvm#134780.
@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Apr 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 21, 2025

@llvm/pr-subscribers-libc

Author: Alexey Samsonov (vonosmas)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/136582.diff

2 Files Affected:

  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+13-1)
  • (added) utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel (+20)
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",
+    ],
+)

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the stdbit_test currently build? If not it might be good to disable it so that local bazel testing doesn't fail.

@vonosmas
Copy link
Contributor Author

Yes, it builds and runs successfully, because this test only verifies the implementation of llvm-libc-macros/stdbit-macros.h, not the validity of a generated header.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, should be fine to land then.

@vonosmas vonosmas merged commit 863ead2 into llvm:main Apr 21, 2025
12 checks passed
@vonosmas vonosmas deleted the libc-bazel-public-headers branch April 21, 2025 20:43
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
llvm#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 llvm#134780.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel "Peripheral" support tier build system: utils/bazel libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants