[libc-commits] [libc] [llvm] [ci][libc] Enable libc-lint in Linux premerge bootstrap CI (PR #240822)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Tue Nov 10 04:47:02 PST 2026


https://github.com/kaladron created https://github.com/llvm/llvm-project/pull/240822

Wire clang-tools-extra and libc-lint into the Linux premerge bootstrapping build so every libc change is linted with a clang-tidy built from the exact same trunk revision as clang and the libc sources.

Update PROJECT_DEPENDENCIES in .ci/compute_projects.py so libc pulls in clang-tools-extra alongside clang and lld, and update the matching assertions in .ci/compute_projects_test.py.  In
llvm/runtimes/CMakeLists.txt, expose libc-lint from top-level runtime builds, forward global libc linting options to registered libc targets while honouring per-target overrides, and depend on clang-tidy for runtimes-configure when linting uses the in-tree binary.  In .ci/monolithic-linux.sh, pass LLVM_LIBC_ENABLE_LINTING=ON and append libc-lint to runtime_targets when check-libc runs, leaving Stage 1 compiler flags untouched to preserve sccache hits.

Update libc/docs/dev/code_style.md to document premerge bootstrapping lint behaviour, and refresh item 4 in libc/docs/contributing.md to reflect remaining expansion work now that libc/src lint runs in CI.

Assisted-by: Automated tooling, human reviewed.

>From af58327c127190899ca46cd1023cd603e0de19f7 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Mon, 9 Nov 2026 22:50:02 +0000
Subject: [PATCH] [ci][libc] Enable libc-lint in Linux premerge bootstrap CI

Wire clang-tools-extra and libc-lint into the Linux premerge
bootstrapping build so every libc change is linted with a clang-tidy
built from the exact same trunk revision as clang and the libc
sources.

Update PROJECT_DEPENDENCIES in .ci/compute_projects.py so libc pulls in
clang-tools-extra alongside clang and lld, and update the matching
assertions in .ci/compute_projects_test.py.  In
llvm/runtimes/CMakeLists.txt, expose libc-lint from top-level runtime
builds, forward global libc linting options to registered libc
targets while honouring per-target overrides, and depend on clang-tidy
for runtimes-configure when linting uses the in-tree binary.  In
.ci/monolithic-linux.sh, pass LLVM_LIBC_ENABLE_LINTING=ON and append
libc-lint to runtime_targets when check-libc runs, leaving Stage 1
compiler flags untouched to preserve sccache hits.

Update libc/docs/dev/code_style.md to document premerge bootstrapping
lint behaviour, and refresh item 4 in libc/docs/contributing.md to
reflect remaining expansion work now that libc/src lint runs in CI.

Assisted-by: Automated tooling, human reviewed.
---
 .ci/compute_projects.py      |  2 +-
 .ci/compute_projects_test.py |  9 +++-
 .ci/monolithic-linux.sh      |  2 +
 libc/docs/contributing.md    | 12 +++--
 libc/docs/dev/code_style.md  |  8 +++-
 llvm/runtimes/CMakeLists.txt | 88 ++++++++++++++++++++++++++++++++++++
 6 files changed, 111 insertions(+), 10 deletions(-)

diff --git a/.ci/compute_projects.py b/.ci/compute_projects.py
index 431929e2213c0c..eaac8f2e7dec8a 100644
--- a/.ci/compute_projects.py
+++ b/.ci/compute_projects.py
@@ -24,7 +24,7 @@
     "clang-tools-extra": {"clang", "llvm"},
     "compiler-rt": {"clang", "lld"},
     "cross-project-tests": {"clang", "lldb", "lld"},
-    "libc": {"clang", "lld"},
+    "libc": {"clang", "clang-tools-extra", "lld"},
     "openmp": {"clang", "lld"},
     "orc-rt": {"llvm"},
     "flang": {"llvm", "clang"},
diff --git a/.ci/compute_projects_test.py b/.ci/compute_projects_test.py
index 84233d13713c24..77663f22d953e9 100644
--- a/.ci/compute_projects_test.py
+++ b/.ci/compute_projects_test.py
@@ -307,7 +307,9 @@ def test_include_libc_in_runtimes(self):
         env_variables = compute_projects.get_env_variables(
             ["libc/CMakeLists.txt"], "Linux"
         )
-        self.assertEqual(env_variables["projects_to_build"], "clang;lld")
+        self.assertEqual(
+            env_variables["projects_to_build"], "clang;clang-tools-extra;lld"
+        )
         self.assertEqual(env_variables["project_check_targets"], "")
         self.assertEqual(env_variables["runtimes_to_build"], "libc")
         self.assertEqual(env_variables["runtimes_check_targets"], "check-libc")
@@ -532,7 +534,10 @@ def test_libc_shared(self):
         env_variables = compute_projects.get_env_variables(
             ["libc/shared/math/acos.h"], "Linux"
         )
-        self.assertEqual(env_variables["projects_to_build"], "clang;lld;llvm")
+        self.assertEqual(
+            env_variables["projects_to_build"],
+            "clang;clang-tools-extra;lld;llvm",
+        )
         self.assertEqual(
             env_variables["project_check_targets"],
             "check-clang check-clang-python check-llvm",
diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index ba91a0b79e6741..a011c7f3171e88 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -44,10 +44,12 @@ if [[ " ${runtime_targets} " == *" check-libc "* ]]; then
   fi
   runtime_cmake_args+=(
     -D LLVM_LIBC_FULL_BUILD=ON
+    -D LLVM_LIBC_ENABLE_LINTING=ON
     -D LIBC_TEST_SKIP_DEATH_TESTS=ON
     -D LIBC_TEST_SKIP_SHARED_TESTS=ON
     -D LIBC_KERNEL_HEADERS="${libc_kernel_headers}"
   )
+  runtime_targets="${runtime_targets} libc-lint"
 fi
 
 start-group "CMake"
diff --git a/libc/docs/contributing.md b/libc/docs/contributing.md
index 8e53f8f5501b94..01fa533fea6204 100644
--- a/libc/docs/contributing.md
+++ b/libc/docs/contributing.md
@@ -26,13 +26,15 @@ a list of open projects that one can start with:
    implemented but many more are yet to be implemented. So, a project of medium
    complexity would be to implement syscall wrappers which have not yet been
    implemented.
-4. **Update the clang-tidy lint rules and use them in the build and/or CI** -
+4. **Expand the clang-tidy lint rules and coverage** -
    The libc project has a set of clang-tidy checks (see
    {ref}`clang-tidy checks <clang_tidy_checks>`)
-   but they are not enabled by default. They can be enabled by configuring with
-   `-DLLVM_LIBC_ENABLE_LINTING=ON` (or by setting `LLVM_LIBC_CLANG_TIDY`) and
-   running the `libc-lint` build target. This project is about keeping the
-   checks up to date and reintegrating them into the build and CI.
+   that run in Linux premerge CI on `libc/src` via the `libc-lint` target,
+   and can be enabled locally by configuring with
+   `-DLLVM_LIBC_ENABLE_LINTING=ON` (or by setting `LLVM_LIBC_CLANG_TIDY`).
+   This project is about resolving remaining diagnostics so more checks can be
+   enabled and extending lint coverage to additional targets and
+   configurations.
 5. **double and higher precision math functions** - These are under active
    development but you can take a shot at those not yet implemented. See
    {ref}`math` for more information.
diff --git a/libc/docs/dev/code_style.md b/libc/docs/dev/code_style.md
index f831c16bad617c..bd56422cfbf7bf 100644
--- a/libc/docs/dev/code_style.md
+++ b/libc/docs/dev/code_style.md
@@ -375,8 +375,12 @@ configuration: it ignores checks and check options it does not know, and
 releases up to at least 21 react to an unknown top-level key by discarding
 the file and running their default checks, exiting 0 either way. Results
 from an older `clang-tidy` are therefore not comparable with a build at the
-same revision. To match, add `clang-tools-extra` to a bootstrapping build
-and point `LLVM_LIBC_CLANG_TIDY` at the `clang-tidy` it produces;
+same revision. Premerge lints with a `clang-tidy` built in the same
+bootstrapping build as the compiler, so `clang`, `clang-tidy`, and libc are all
+at the revision under test. To match premerge locally, add `clang-tools-extra`
+to a bootstrapping build with `-DLLVM_LIBC_ENABLE_LINTING=ON`; the build
+produces `clang-tidy` before configuring `libc`, picks it up automatically from
+the build tree, and exposes `libc-lint` at the top level.
 `clang-tidy --verify-config --config-file=libc/src/.clang-tidy` reports
 anything your `clang-tidy` would silently skip.
 
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index fcb85ec96e265c..870ba42888f89f 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -331,6 +331,11 @@ function(runtime_default_target)
     list(APPEND extra_targets "install-flang-rt-mod")
     list(APPEND extra_targets "install-flang-rt-mod-stripped")
   endif ()
+  if ("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND
+      (LLVM_LIBC_ENABLE_LINTING OR LLVM_LIBC_CLANG_TIDY))
+    # Expose libc-lint on top-level bootstrapping builds.
+    list(APPEND extra_targets "libc-lint")
+  endif ()
 
   if(LLVM_INCLUDE_TESTS)
     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-bins/lit.tests")
@@ -407,6 +412,22 @@ function(runtime_register_target name)
     endif()
   endforeach()
 
+  set(_target_libc_linting "${LLVM_LIBC_ENABLE_LINTING}")
+  set(_target_libc_clang_tidy "${LLVM_LIBC_CLANG_TIDY}")
+  foreach(_scope IN ITEMS ${ARG_BASE_NAME} ${name})
+    if(DEFINED RUNTIMES_${_scope}_LLVM_LIBC_ENABLE_LINTING)
+      set(_target_libc_linting "${RUNTIMES_${_scope}_LLVM_LIBC_ENABLE_LINTING}")
+    endif()
+    if(DEFINED RUNTIMES_${_scope}_LLVM_LIBC_CLANG_TIDY)
+      set(_target_libc_clang_tidy "${RUNTIMES_${_scope}_LLVM_LIBC_CLANG_TIDY}")
+    endif()
+  endforeach()
+  if("libc" IN_LIST runtime_names AND
+     (_target_libc_linting OR _target_libc_clang_tidy))
+    set(libc-lint-${name} libc-lint)
+    list(APPEND ${name}_extra_targets libc-lint-${name})
+  endif()
+
   foreach(component IN LISTS SUB_COMPONENTS)
     set(${component}-${name} ${component})
     list(APPEND ${name}_extra_targets ${component}-${name})
@@ -462,6 +483,14 @@ function(runtime_register_target name)
   string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
   list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
   list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
+  if("libc" IN_LIST runtime_names)
+    if(LLVM_LIBC_ENABLE_LINTING)
+      list(APPEND ${name}_extra_args -DLLVM_LIBC_ENABLE_LINTING=ON)
+    endif()
+    if(LLVM_LIBC_CLANG_TIDY)
+      list(APPEND ${name}_extra_args -DLLVM_LIBC_CLANG_TIDY=${LLVM_LIBC_CLANG_TIDY})
+    endif()
+  endif()
   append_passthrough_options(${name}_extra_args RUNTIMES "${ARG_BASE_NAME};${name}")
 
   set_enable_per_target_runtime_dir()
@@ -525,6 +554,13 @@ function(runtime_register_target name)
     endif()
     add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
   endforeach()
+  if(TARGET libc-lint-${name})
+    if(NOT TARGET libc-lint)
+      add_custom_target(libc-lint)
+      set_target_properties(libc-lint PROPERTIES FOLDER "libc")
+    endif()
+    add_dependencies(libc-lint libc-lint-${name})
+  endif()
   foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
     add_dependencies(${component} ${component}-${name})
     add_dependencies(install-${component} install-${component}-${name})
@@ -681,6 +717,58 @@ if(build_runtimes)
   if(LLVM_LIBC_FULL_BUILD)
     list(APPEND extra_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")
   endif()
+  set(_libc_needs_in_tree_clang_tidy FALSE)
+  if(TARGET clang-tidy)
+    get_filename_component(_libc_in_tree_clang_tidy_real
+      "${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-tidy${CMAKE_EXECUTABLE_SUFFIX}"
+      REALPATH)
+    if(NOT LLVM_RUNTIME_TARGETS OR "default" IN_LIST LLVM_RUNTIME_TARGETS)
+      if("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
+        if(LLVM_LIBC_ENABLE_LINTING AND NOT LLVM_LIBC_CLANG_TIDY)
+          set(_libc_needs_in_tree_clang_tidy TRUE)
+        elseif(LLVM_LIBC_CLANG_TIDY AND IS_ABSOLUTE "${LLVM_LIBC_CLANG_TIDY}")
+          get_filename_component(_libc_clang_tidy_real
+            "${LLVM_LIBC_CLANG_TIDY}" REALPATH)
+          if(_libc_clang_tidy_real STREQUAL _libc_in_tree_clang_tidy_real)
+            set(_libc_needs_in_tree_clang_tidy TRUE)
+          endif()
+        endif()
+      endif()
+    endif()
+    foreach(target ${LLVM_RUNTIME_TARGETS})
+      if(target STREQUAL "default")
+        continue()
+      endif()
+      set(_target_runtimes "${LLVM_ENABLE_RUNTIMES}")
+      if(DEFINED RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES)
+        set(_target_runtimes "${RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES}")
+      endif()
+      if("libc" IN_LIST _target_runtimes)
+        set(_target_libc_linting "${LLVM_LIBC_ENABLE_LINTING}")
+        set(_target_libc_clang_tidy "${LLVM_LIBC_CLANG_TIDY}")
+        if(DEFINED RUNTIMES_${target}_LLVM_LIBC_ENABLE_LINTING)
+          set(_target_libc_linting "${RUNTIMES_${target}_LLVM_LIBC_ENABLE_LINTING}")
+        endif()
+        if(DEFINED RUNTIMES_${target}_LLVM_LIBC_CLANG_TIDY)
+          set(_target_libc_clang_tidy "${RUNTIMES_${target}_LLVM_LIBC_CLANG_TIDY}")
+        endif()
+        if(_target_libc_clang_tidy)
+          if(IS_ABSOLUTE "${_target_libc_clang_tidy}")
+            get_filename_component(_libc_clang_tidy_real
+              "${_target_libc_clang_tidy}" REALPATH)
+            if(_libc_clang_tidy_real STREQUAL _libc_in_tree_clang_tidy_real)
+              set(_libc_needs_in_tree_clang_tidy TRUE)
+            endif()
+          endif()
+        elseif(_target_libc_linting)
+          set(_libc_needs_in_tree_clang_tidy TRUE)
+        endif()
+      endif()
+    endforeach()
+  endif()
+  if(_libc_needs_in_tree_clang_tidy)
+    list(APPEND extra_deps clang-tidy)
+  endif()
   if("flang" IN_LIST LLVM_ENABLE_PROJECTS)
     # Allow runtimes that can use it to access the Flang compiler
     if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES OR "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)



More information about the libc-commits mailing list