[libc-commits] [libc] [llvm] [libc][bazel] Use LLVM-libc startup objects in full-build tests (PR #219262)

Jackson Stogel via libc-commits libc-commits at lists.llvm.org
Fri Sep 11 16:47:46 PDT 2026


https://github.com/jtstogel updated https://github.com/llvm/llvm-project/pull/219262

>From 23cd975172cf10d82c0725a58a8330af715be679 Mon Sep 17 00:00:00 2001
From: jtstogel <jtstogel at gmail.com>
Date: Tue, 18 Aug 2026 10:27:40 -0700
Subject: [PATCH] [libc][bazel] Use LLVM-libc startup objects in full-build
 tests

---
 libc/test/UnitTest/BazelFilePath.cpp          |  16 +-
 .../llvm-project-overlay/libc/BUILD.bazel     |   8 +-
 .../libc/test/BUILD.bazel                     |   1 +
 .../libc/test/IntegrationTest/BUILD.bazel     |  25 +++
 .../libc/test/UnitTest/BUILD.bazel            |  51 +++++-
 .../libc/test/include/BUILD.bazel             | 150 +++++++++++-------
 .../libc/test/libc_test_rules.bzl             |  78 ++++++---
 .../libc/test/src/stdio/BUILD.bazel           |  41 ++++-
 .../libc/test/src/string/BUILD.bazel          |   4 +
 .../libc/utils/MPCWrapper/BUILD.bazel         |   8 +-
 .../libc/utils/MPFRWrapper/BUILD.bazel        |   5 +-
 11 files changed, 291 insertions(+), 96 deletions(-)
 create mode 100644 utils/bazel/llvm-project-overlay/libc/test/IntegrationTest/BUILD.bazel

diff --git a/libc/test/UnitTest/BazelFilePath.cpp b/libc/test/UnitTest/BazelFilePath.cpp
index 03ac56f083b9c..a2ae6b4f91557 100644
--- a/libc/test/UnitTest/BazelFilePath.cpp
+++ b/libc/test/UnitTest/BazelFilePath.cpp
@@ -8,18 +8,28 @@
 
 #include "LibcTest.h"
 
-#include <stdlib.h>
-
 #include "src/__support/CPP/string.h"
 #include "src/__support/c_string.h"
 #include "src/__support/macros/config.h"
 
+#ifdef LIBC_FULL_BUILD
+#include "src/stdlib/getenv.h"
+
+#define LIBC_IMPL LIBC_NAMESPACE
+
+#else // Overlay mode
+#include <stdlib.h>
+
+#define LIBC_IMPL
+#endif
+
 namespace LIBC_NAMESPACE_DECL {
 namespace testing {
 
 CString libc_make_test_file_path_func(const char *file_name) {
   // This is the path to the folder bazel wants the test outputs written to.
-  const char *UNDECLARED_OUTPUTS_PATH = getenv("TEST_UNDECLARED_OUTPUTS_DIR");
+  const char *UNDECLARED_OUTPUTS_PATH =
+      LIBC_IMPL::getenv("TEST_UNDECLARED_OUTPUTS_DIR");
   // Do something sensible if not run under bazel, otherwise this may segfault
   // when constructing the string.
   if (UNDECLARED_OUTPUTS_PATH == nullptr)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c6f6ed40c8cb4..d6da3177f9ee3 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1480,10 +1480,10 @@ libc_support_library(
 libc_support_library(
     name = "types_char8_t",
     hdrs = ["hdr/types/char8_t.h"],
-    deps = [
-        ":hdr_uchar_overlay",
-        ":llvm_libc_types_char8_t",
-    ],
+    deps = select({
+        ":full_build": [":llvm_libc_types_char8_t"],
+        "//conditions:default": [":hdr_uchar_overlay"],
+    }),
 )
 
 ############################### Support libraries ##############################
diff --git a/utils/bazel/llvm-project-overlay/libc/test/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/BUILD.bazel
index 0a2c3a2ad3dee..9b50cc18f3341 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/BUILD.bazel
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("@bazel_skylib//rules:build_test.bzl", "build_test")
+load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//libc:libc_build_rules.bzl", "libc_release_library")
 
 package(
diff --git a/utils/bazel/llvm-project-overlay/libc/test/IntegrationTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/IntegrationTest/BUILD.bazel
new file mode 100644
index 0000000000000..48238f9c0be24
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/libc/test/IntegrationTest/BUILD.bazel
@@ -0,0 +1,25 @@
+# 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
+
+# LLVM libc integration test library.
+
+load("//libc/test:libc_test_rules.bzl", "libc_test_library")
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+libc_test_library(
+    name = "IntegrationTest",
+    srcs = ["test.cpp"],
+    hdrs = ["test.h"],
+    deps = [
+        "//libc:__support_common",
+        "//libc:__support_cpp_atomic",
+        "//libc:__support_macros_config",
+        "//libc:__support_macros_properties_architectures",
+        "//libc:__support_macros_properties_types",
+        "//libc:hdr_stdint_proxy",
+    ],
+)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
index 35704e71d1306..afc165786cada 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
@@ -78,20 +78,65 @@ libc_test_library(
         "//libc:func_realloc",
         "//libc:hdr_stdint_proxy",
         "//libc:llvm_libc_macros_stdfix_macros",
-        "//llvm:Support",
-    ],
+    ] + select({
+        "//libc:full_build": [
+            "//libc:clock",
+            "//libc:close",
+            "//libc:exit",
+            "//libc:fflush",
+            "//libc:fork",
+            "//libc:getenv",
+            "//libc:kill",
+            "//libc:llvm_libc_macros_poll_macros",
+            "//libc:llvm_libc_macros_signal_macros",
+            "//libc:llvm_libc_macros_sys_wait_macros",
+            "//libc:llvm_libc_types_pid_t",
+            "//libc:llvm_libc_types_struct_pollfd",
+            "//libc:pipe",
+            "//libc:poll",
+            "//libc:stderr",
+            "//libc:stdout",
+            "//libc:strsignal",
+            "//libc:waitpid",
+        ],
+        "//conditions:default": [],
+    }),
     # Force linking in this library's `main()` to surface
     # a duplicate symbol error if a test defines its own main.
     alwayslink = True,
 )
 
+libc_test_library(
+    name = "HermeticTestUtils",
+    srcs = ["HermeticTestUtils.cpp"],
+    # Only intended to be used with full-build tests.
+    target_compatible_with = select({
+        "//libc:full_build": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        "//libc:__support_common",
+        "//libc:__support_libc_errno",
+        "//libc:__support_macros_config",
+        "//libc:atexit",
+        "//libc:bcmp",
+        "//libc:bzero",
+        "//libc:hdr_errno_macros",
+        "//libc:hdr_stdint_proxy",
+        "//libc:memcmp",
+        "//libc:memcpy",
+        "//libc:memmove",
+        "//libc:memset",
+    ],
+)
+
 libc_test_library(
     name = "LibcCTest",
     srcs = ["LibcCTest.cpp"],
     hdrs = ["LibcCTest.h"],
     deps = [
         ":LibcUnitTest",
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_common_h",
     ],
 )
 
diff --git a/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
index dcaf655c5b5c9..2236e85ede5eb 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/include/BUILD.bazel
@@ -13,15 +13,18 @@ licenses(["notice"])
 libc_test(
     name = "assert_test",
     srcs = ["assert_test.cpp"],
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_assert_macros",
+    ],
 )
 
 libc_test(
     name = "complex_test",
     srcs = ["complex_test.cpp"],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_complex_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -32,9 +35,9 @@ libc_test(
         "FpClassifyTest.h",
         "fpclassify_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -45,9 +48,9 @@ libc_test(
         "FpClassifyTest.h",
         "fpclassifyf_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -58,9 +61,9 @@ libc_test(
         "FpClassifyTest.h",
         "fpclassifyl_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -69,7 +72,10 @@ libc_test(
     name = "fpclassify_c_test",
     srcs = ["fpclassify_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
@@ -78,9 +84,9 @@ libc_test(
         "IsFiniteTest.h",
         "isfinite_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -91,9 +97,9 @@ libc_test(
         "IsFiniteTest.h",
         "isfinitef_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -104,9 +110,9 @@ libc_test(
         "IsFiniteTest.h",
         "isfinitel_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -115,7 +121,10 @@ libc_test(
     name = "isfinite_c_test",
     srcs = ["isfinite_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
@@ -124,9 +133,9 @@ libc_test(
         "IsInfTest.h",
         "isinf_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -137,9 +146,9 @@ libc_test(
         "IsInfTest.h",
         "isinff_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -150,9 +159,9 @@ libc_test(
         "IsInfTest.h",
         "isinfl_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -161,7 +170,10 @@ libc_test(
     name = "isinf_c_test",
     srcs = ["isinf_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
@@ -170,9 +182,9 @@ libc_test(
         "IsNanTest.h",
         "isnan_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -183,9 +195,9 @@ libc_test(
         "IsNanTest.h",
         "isnanf_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -196,9 +208,9 @@ libc_test(
         "IsNanTest.h",
         "isnanl_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -207,7 +219,10 @@ libc_test(
     name = "isnan_c_test",
     srcs = ["isnan_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
@@ -216,9 +231,9 @@ libc_test(
         "IsNormalTest.h",
         "isnormal_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -229,9 +244,9 @@ libc_test(
         "IsNormalTest.h",
         "isnormalf_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -242,9 +257,9 @@ libc_test(
         "IsNormalTest.h",
         "isnormall_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -253,14 +268,20 @@ libc_test(
     name = "isnormal_c_test",
     srcs = ["isnormal_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
     name = "issubnormal_c_test",
     srcs = ["issubnormal_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
@@ -269,9 +290,9 @@ libc_test(
         "IsZeroTest.h",
         "iszero_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -282,9 +303,9 @@ libc_test(
         "IsZeroTest.h",
         "iszerof_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -295,9 +316,9 @@ libc_test(
         "IsZeroTest.h",
         "iszerol_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -306,7 +327,10 @@ libc_test(
     name = "iszero_c_test",
     srcs = ["iszero_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
@@ -315,9 +339,9 @@ libc_test(
         "SignbitTest.h",
         "signbit_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -328,9 +352,9 @@ libc_test(
         "SignbitTest.h",
         "signbitf_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -341,9 +365,9 @@ libc_test(
         "SignbitTest.h",
         "signbitl_test.cpp",
     ],
-    full_build = True,
+    full_build_only = True,
     deps = [
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_math_function_macros",
         "//libc/test/UnitTest:fp_test_helpers",
     ],
 )
@@ -354,31 +378,39 @@ libc_test(
         "stdbit_stub.h",
         "stdbit_test.cpp",
     ],
-    full_build = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_common_h",
+        "//libc:llvm_libc_macros_stdbit_macros",
+    ],
 )
 
 libc_test(
     name = "signbit_c_test",
     srcs = ["signbit_test.c"],
     c_test = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_math_function_macros",
+    ],
 )
 
 libc_test(
     name = "stdckdint_test",
     srcs = ["stdckdint_test.cpp"],
-    full_build = True,
-    deps = ["//libc:public_headers_deps"],
+    full_build_only = True,
+    deps = [
+        "//libc:llvm_libc_macros_stdckdint_macros",
+    ],
 )
 
 libc_test(
     name = "sys_queue_test",
     srcs = ["sys/queue_test.cpp"],
-    full_build = True,
+    full_build_only = True,
     deps = [
         "//libc:__support_char_vector",
         "//libc:__support_cpp_string",
-        "//libc:public_headers_deps",
+        "//libc:llvm_libc_macros_sys_queue_macros",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
index ab2f98d7c4e07..2e007d14e1f07 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
@@ -13,37 +13,39 @@ When performing tests we make sure to always use the internal version.
 """
 
 load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
-load("//libc:libc_build_rules.bzl", "libc_common_copts")
+load("//libc:libc_build_rules.bzl", "libc_common_copts", "libc_common_deps")
 load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
 
-_FULL_BUILD_COPTS = [
-    "-nostdlib++",
-    "-nostdlib",
-    "-DLIBC_FULL_BUILD",
-    "-DLIBC_COPT_USE_C_ASSERT",
-]
-
-_TEST_DEFINES = ["LIBC_TEST_SUBPROCESS_TESTS=1"]
+_TEST_DEFINES = ["LIBC_TEST_SUBPROCESS_TESTS=1"] + select({
+    "//libc:full_build": ["TARGET_SUPPORTS_CLOCK"],
+    "//conditions:default": [],
+})
 
 def libc_test(
         name,
+        srcs = [],
         copts = [],
         deps = [],
         local_defines = [],
+        linkopts = [],
         c_test = False,
-        full_build = False,
+        full_build_only = False,
+        target_compatible_with = [],
+        tags = [],
         **kwargs):
     """Add target for a libc test.
 
     Args:
       name: Test target name
+      srcs: The list of sources for this test.
       copts: The list of options to add to the C++ compilation command.
       deps: The list of libc functions and libraries to be linked in.
       local_defines: The list of target local_defines if any.
+      linkopts: Link options for the cc_test.
       c_test: Whether this test is a C unit test (uses LibcCTest).
-      full_build: Whether to compile with LIBC_FULL_BUILD and disallow
-          use of system headers. This is useful for tests that include both
-          LLVM libc headers and proxy headers to avoid conflicting definitions.
+      full_build_only: Whether the test should only be run in full-build mode.
+      target_compatible_with: Constraints the target is compatible with.
+      tags: Tags for the cc_test.
       **kwargs: Attributes relevant for a cc_test.
     """
     deps = deps + [
@@ -55,34 +57,69 @@ def libc_test(
         "//libc:func_free",
         "//libc:func_malloc",
         "//libc:func_realloc",
-    ]
+    ] + select({
+        "//libc:full_build": [
+            # Required by crt1.o. These would usually be provided by libc.a.
+            "//libc:__stack_chk_fail",
+            "//libc:_r_debug",
+            "//libc:environ",
+            "//libc:program_invocation_name",
+            "//libc:program_invocation_short_name",
+
+            # Hermetic providers of common libc dependencies.
+            "//libc/test/UnitTest:HermeticTestUtils",
+        ],
+        "//conditions:default": [],
+    })
+
     if c_test:
         deps = deps + ["//libc/test/UnitTest:LibcCTest"]
     else:
         deps = deps + ["//libc/test/UnitTest:LibcUnitTest"]
 
-    tags = kwargs.pop("tags", [])
-    if full_build:
-        copts = copts + _FULL_BUILD_COPTS
+    linkopts = linkopts + select({
+        "//libc:full_build": [
+            "-nolibc",
+            "-nostartfiles",
+            "-nostdlib++",
+            "-static",
+            "-Wl,-z,muldefs",
+        ],
+        "//conditions:default": [],
+    })
 
-        # Temporarily disable full_build tests (currently broken) to unblock CI.
+    if full_build_only:
+        target_compatible_with = target_compatible_with + select({
+            "//libc:full_build": [],
+            "//conditions:default": ["@platforms//:incompatible"],
+        })
         tags = tags + ["manual", "nobuildkite", "notap"]
+
     cc_test(
         name = name,
+        srcs = srcs + select({
+            "//libc:full_build": [
+                "//libc/startup/linux:crt1",
+            ],
+            "//conditions:default": [],
+        }),
         local_defines = local_defines + _TEST_DEFINES + LIBC_CONFIGURE_OPTIONS,
-        deps = deps,
+        deps = deps + libc_common_deps(),
         copts = copts + libc_common_copts(),
+        target_compatible_with = target_compatible_with,
+        linkopts = linkopts,
         linkstatic = 1,
         tags = tags,
         **kwargs
     )
 
-def libc_test_library(name, copts = [], local_defines = [], **kwargs):
+def libc_test_library(name, copts = [], deps = [], local_defines = [], **kwargs):
     """Add target for library used in libc tests.
 
     Args:
       name: Library target name.
       copts: See cc_library.copts.
+      deps: See cc_library.deps.
       local_defines: See cc_library.local_defines.
       **kwargs: Other attributes relevant to cc_library (e.g. "deps").
     """
@@ -90,6 +127,7 @@ def libc_test_library(name, copts = [], local_defines = [], **kwargs):
         name = name,
         testonly = True,
         copts = copts + libc_common_copts(),
+        deps = deps + libc_common_deps(),
         local_defines = local_defines + _TEST_DEFINES + LIBC_CONFIGURE_OPTIONS,
         linkstatic = 1,
         **kwargs
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
index 2c54fc3726591..fa58ac8da2ac4 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
@@ -56,7 +56,15 @@ libc_test(
         "//libc:__support_cpp_limits",
         "//libc:__support_macros_properties_architectures",
         "//libc:fprintf",
-    ],
+    ] + select({
+        "//libc:full_build": [
+            "//libc:fclose",
+            "//libc:ferror",
+            "//libc:fopen",
+            "//libc:fread",
+        ],
+        "//conditions:default": [],
+    }),
 )
 
 libc_test(
@@ -97,7 +105,15 @@ libc_test(
     srcs = ["vfprintf_test.cpp"],
     deps = [
         "//libc:vfprintf",
-    ],
+    ] + select({
+        "//libc:full_build": [
+            "//libc:fclose",
+            "//libc:ferror",
+            "//libc:fopen",
+            "//libc:fread",
+        ],
+        "//conditions:default": [],
+    }),
 )
 
 libc_test(
@@ -132,7 +148,16 @@ libc_test(
         "//libc:__support_cpp_string_view",
         "//libc:fscanf",
         "//libc:hdr_stdio_macros",
-    ],
+    ] + select({
+        "//libc:full_build": [
+            "//libc:fclose",
+            "//libc:feof",
+            "//libc:ferror",
+            "//libc:fopen",
+            "//libc:fwrite",
+        ],
+        "//conditions:default": [],
+    }),
 )
 
 libc_test(
@@ -149,5 +174,13 @@ libc_test(
     deps = [
         "//libc:__support_cpp_string_view",
         "//libc:vfscanf",
-    ],
+    ] + select({
+        "//libc:full_build": [
+            "//libc:fclose",
+            "//libc:ferror",
+            "//libc:fopen",
+            "//libc:fwrite",
+        ],
+        "//conditions:default": [],
+    }),
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel
index 8b9161b537e4c..2d8cd367f424c 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel
@@ -235,6 +235,10 @@ libc_test_library(
 libc_test_library(
     name = "protected_pages",
     hdrs = ["memory_utils/protected_pages.h"],
+    target_compatible_with = select({
+        "//libc:full_build": ["@platforms//:incompatible"],
+        "//conditions:default": [],
+    }),
     deps = [
         "//libc:__support_macros_attributes",
         "//libc:__support_macros_properties_os",
diff --git a/utils/bazel/llvm-project-overlay/libc/utils/MPCWrapper/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/utils/MPCWrapper/BUILD.bazel
index 8ec7f1df874de..bcdc3481e7e2e 100644
--- a/utils/bazel/llvm-project-overlay/libc/utils/MPCWrapper/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/utils/MPCWrapper/BUILD.bazel
@@ -22,8 +22,11 @@ cc_library(
     name = "mpc_impl",
     hdrs = ["mpc_inc.h"],
     target_compatible_with = select({
-        "//conditions:default": [],
         "//libc:mpc_disable": ["@platforms//:incompatible"],
+        # In full build mode, the MPFR library should be built
+        # using our own facilities, which is currently not possible.
+        "//libc:full_build": ["@platforms//:incompatible"],
+        "//conditions:default": [],
     }),
     deps = select(
         {
@@ -46,8 +49,9 @@ libc_test_library(
         },
     ),
     target_compatible_with = select({
-        "//conditions:default": [],
         "//libc:mpc_disable": ["@platforms//:incompatible"],
+        "//libc:full_build": ["@platforms//:incompatible"],
+        "//conditions:default": [],
     }),
     deps = [
         ":mpc_impl",
diff --git a/utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel
index fc905ce22ad95..beffebe5e32ac 100644
--- a/utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel
@@ -22,8 +22,11 @@ cc_library(
     name = "mpfr_impl",
     hdrs = ["mpfr_inc.h"],
     target_compatible_with = select({
-        "//conditions:default": [],
         "//libc:mpfr_disable": ["@platforms//:incompatible"],
+        # In full build mode, the MPFR library should be built
+        # using our own facilities, which is currently not possible.
+        "//libc:full_build": ["@platforms//:incompatible"],
+        "//conditions:default": [],
     }),
     deps = select(
         {



More information about the libc-commits mailing list