[llvm] [Github] Add LLVM-libc's full-build to Bazel Checks workflow (PR #224749)

Jackson Stogel via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 14:52:29 PDT 2026


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

>From 01e4813cb2d45a28d895c2a49b2bc458cf46938f Mon Sep 17 00:00:00 2001
From: jtstogel <jtstogel at gmail.com>
Date: Thu, 16 Jul 2026 13:19:07 -0700
Subject: [PATCH 1/3] [libc][bazel] Pull UAPI headers from debain repository
 when unset

---
 utils/bazel/MODULE.bazel.lock |  2 +-
 utils/bazel/linux_uapi.bzl    | 98 ++++++++++++++++++++---------------
 2 files changed, 56 insertions(+), 44 deletions(-)

diff --git a/utils/bazel/MODULE.bazel.lock b/utils/bazel/MODULE.bazel.lock
index ccb91f8b3db14..d3ebc94f90d22 100644
--- a/utils/bazel/MODULE.bazel.lock
+++ b/utils/bazel/MODULE.bazel.lock
@@ -331,7 +331,7 @@
   "moduleExtensions": {
     "//:extensions.bzl%llvm_repos_extension": {
       "general": {
-        "bzlTransitiveDigest": "nmqMTTDURvBeR6PLzbfX1EEbe79FTb8wSzrT13UXlFk=",
+        "bzlTransitiveDigest": "Ae2Y9H+Op6X/5+fbpaSNwEEvI9+sGfQTN3GOkDQsHJ0=",
         "usagesDigest": "X0yUkkWyxQ2Y5oZVDkRSE/K4YkDWo1IjhHsL+1weKyU=",
         "recordedFileInputs": {},
         "recordedDirentsInputs": {},
diff --git a/utils/bazel/linux_uapi.bzl b/utils/bazel/linux_uapi.bzl
index aa0a764d2e1e4..80e1973b0f756 100644
--- a/utils/bazel/linux_uapi.bzl
+++ b/utils/bazel/linux_uapi.bzl
@@ -6,28 +6,6 @@
 
 _SYSTEM_HEADERS_PATH_ENV_VAR = "LINUX_UAPI_INCLUDE_DIR"
 
-_ERROR_MESSAGE_BZL = """\
-def _error_message_impl(ctx):
-    fail(ctx.attr.message)
-
-error_message = rule(
-    implementation = _error_message_impl,
-    attrs = {"message": attr.string()},
-)
-"""
-
-_ERROR_BUILD = """\
-load(":error_message.bzl", "error_message")
-
-error_message(
-    name = "linux_uapi_headers",
-    message = \"""System linux UAPI headers not found.
-
-Pass --repo_env={var_name}=/path/to/your/linux/include to bazel build.
-\"""
-)
-""".format(var_name = _SYSTEM_HEADERS_PATH_ENV_VAR)
-
 _SYSTEM_BUILD = """\
 load("@rules_cc//cc:defs.bzl", "cc_library")
 
@@ -41,34 +19,68 @@ cc_library(
 )
 """
 
-def _default_include_dir(repository_ctx):
-    """Returns a default include dir if it looks to have Linux UAPI headers."""
-    include_dir = "/usr/include"
-    if not repository_ctx.path(include_dir + "/linux").exists:
-        return None
-    return include_dir
-
-def _linux_uapi_setup_impl(repository_ctx):
-    """Sets up a repository of UAPI headers from a system directory."""
-    include_dir = repository_ctx.getenv(_SYSTEM_HEADERS_PATH_ENV_VAR, "")
-    if not include_dir:
-        include_dir = _default_include_dir(repository_ctx)
-
-    # If the directory doesn't exist, then set up a dummy rule that just errors.
-    # This defers the error message until an actual build,
-    # rather than failing during repository setup.
-    if not include_dir:
-        repository_ctx.file("error_message.bzl", _ERROR_MESSAGE_BZL)
-        repository_ctx.file("BUILD.bazel", _ERROR_BUILD)
-        return
-
+def _setup_from_system(repository_ctx, include_dir):
+    """Sets up the repository from a user-provided include directory."""
     if not include_dir.startswith("/"):
         fail("{} must be absolute, was {}".format(
             _SYSTEM_HEADERS_PATH_ENV_VAR,
             include_dir,
         ))
 
+    if not repository_ctx.path(include_dir + "/linux").exists:
+        fail("{}={} does not contain Linux UAPI headers (no linux/ subdirectory)".format(
+            _SYSTEM_HEADERS_PATH_ENV_VAR,
+            include_dir,
+        ))
+
     repository_ctx.symlink(include_dir, "include")
     repository_ctx.file("BUILD.bazel", _SYSTEM_BUILD)
 
+_LIBC_DEV_PACKAGE_BUILD = """\
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+cc_library(
+    name = "linux_uapi_headers",
+    # The linux-libc-dev package has headers for many platforms.
+    # These may not compile, so use `textual_hdrs` instead of `hdrs`.
+    textual_hdrs = glob(["usr/include/**/*.h"]),
+    includes = [
+        "usr/include",
+    ] + select(
+        {{
+            # LLVM-libc requires the `asm` directory to exist,
+            # so include an arch-specific dir.
+            "@platforms//cpu:x86_64": ["usr/include/x86_64-linux-gnu"],
+            "@platforms//cpu:arm64": ["usr/include/aarch64-linux-gnu"],
+            "@platforms//cpu:riscv64": ["usr/include/riscv64-linux-gnu"],
+        }},
+        no_match_error = \"""Unsupported CPU for the Linux UAPI headers.
+
+Use --repo_env={var_name}=/path/to/uapi/include to load from system headers,
+or add support for your architecture.
+\""",
+    ),
+    visibility = ["//visibility:public"],
+)
+""".format(var_name = _SYSTEM_HEADERS_PATH_ENV_VAR)
+
+def _setup_from_libc_dev_package(repository_ctx):
+    """Sets up linux UAPI headers from Debian's linux-libc-dev package."""
+    repository_ctx.download_and_extract(
+        url = "https://snapshot.debian.org/archive/debian-security/20260806T175946Z/pool/updates/main/l/linux/linux-libc-dev_6.12.101-1_all.deb",
+        sha256 = "e776ef48b89af0409c6bcd2e8a7e14a3d75d0842b9fd3dc767b7822a0b0950e2",
+    )
+    repository_ctx.extract(archive = "data.tar.xz")
+    repository_ctx.delete("data.tar.xz")
+    repository_ctx.file("BUILD.bazel", _LIBC_DEV_PACKAGE_BUILD)
+
+def _linux_uapi_setup_impl(repository_ctx):
+    """Sets up a repository of Linux UAPI headers."""
+
+    include_dir = repository_ctx.getenv(_SYSTEM_HEADERS_PATH_ENV_VAR, "")
+    if include_dir:
+        _setup_from_system(repository_ctx, include_dir)
+    else:
+        _setup_from_libc_dev_package(repository_ctx)
+
 linux_uapi_setup = repository_rule(implementation = _linux_uapi_setup_impl)

>From d4674811620bc9a90d0f2a04f1804c68ab6046ff Mon Sep 17 00:00:00 2001
From: jtstogel <jtstogel at gmail.com>
Date: Tue, 22 Sep 2026 08:51:54 -0700
Subject: [PATCH 2/3] [bazel] Port 15cff90, 4faf0ae, 9028ff14 2dea05, 4057f8e4

---
 .../llvm-project-overlay/libc/BUILD.bazel     | 75 ++++++++++++++++++-
 .../libc/libc_build_rules.bzl                 | 40 +++++-----
 .../libc/startup/linux/BUILD.bazel            |  9 ++-
 .../libc/startup/linux/x86_64/BUILD.bazel     | 27 +++----
 4 files changed, 111 insertions(+), 40 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 43f712d695956..531eb948c8a31 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3686,6 +3686,29 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_osutil_linux_syscall_wrappers_clone",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/clone.h"],
+    target_compatible_with = select({
+        "@platforms//os:linux": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    textual_hdrs = [
+        "src/__support/OSUtil/linux/syscall_wrappers/aarch64/clone.h",
+        "src/__support/OSUtil/linux/syscall_wrappers/riscv/clone.h",
+        "src/__support/OSUtil/linux/syscall_wrappers/x86_64/clone.h",
+    ],
+    deps = [
+        ":__support_common",
+        ":__support_error_or",
+        ":__support_libc_assert",
+        ":__support_macros_config",
+        ":__support_macros_properties_architectures",
+        ":hdr_stdint_proxy",
+        ":types_pid_t",
+    ],
+)
+
 libc_support_library(
     name = "__support_osutil_linux_syscall_wrappers_close",
     hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/close.h"],
@@ -4243,6 +4266,20 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_threads_cleanup_stack",
+    hdrs = ["src/__support/threads/cleanup_stack.h"],
+    target_compatible_with = select({
+        ":full_build_linux": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        ":__support_macros_attributes",
+        ":__support_macros_config",
+        ":types_struct___pthread_cleanup_frame",
+    ],
+)
+
 libc_support_library(
     name = "__support_threads_thread_attributes",
     hdrs = ["src/__support/threads/thread_attributes.h"],
@@ -4256,6 +4293,7 @@ libc_support_library(
         ":__support_macros_attributes",
         ":__support_macros_config",
         ":__support_macros_properties_architectures",
+        ":__support_threads_cleanup_stack",
         ":hdr_stdint_proxy",
         ":types_size_t",
         ":types_struct___pthread_cleanup_frame",
@@ -4463,18 +4501,51 @@ libc_support_library(
         ":__support_fixedvector",
         ":__support_macros_attributes",
         ":__support_macros_config",
+        ":__support_threads_cleanup_stack",
         ":__support_threads_mutex",
         ":__support_threads_thread_headers",
+        ":types_struct___pthread_cleanup_frame",
     ] + select({
         "@platforms//os:linux": [":__support_threads_linux_thread"],
         "//conditions:default": [],
     }),
 )
 
+libc_support_library(
+    name = "__support_threads_linux_tls",
+    srcs = select({
+        PLATFORM_CPU_X86_64: ["src/__support/threads/linux/x86_64/tls.cpp"],
+        PLATFORM_CPU_ARM64: ["src/__support/threads/linux/aarch64/tls.cpp"],
+        PLATFORM_CPU_RISCV64: ["src/__support/threads/linux/riscv/tls.cpp"],
+    }),
+    copts = [
+        "-O3",
+        "-fno-stack-protector",
+        "-fno-omit-frame-pointer",
+        "-ffreestanding",
+        "-fno-builtin",
+    ],
+    target_compatible_with = select({
+        ":full_build_linux": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        ":__support_macros_config",
+        ":__support_osutil_linux_syscall_wrappers_getrandom",
+        ":__support_osutil_linux_syscall_wrappers_mmap",
+        ":__support_osutil_linux_syscall_wrappers_munmap",
+        ":__support_osutil_syscall",
+        ":__support_threads_tcb",
+        ":config_app_h",
+        ":hdr_sys_mman_macros",
+        ":string_memory_utils",
+    ],
+)
+
 libc_support_library(
     name = "__support_threads_linux_thread",
     srcs = ["src/__support/threads/linux/thread.cpp"],
-    copt_sets = ["threading"],
+    copts = ["-O3"],
     target_compatible_with = select({
         ":full_build_linux": [],
         "//conditions:default": ["@platforms//:incompatible"],
@@ -4492,6 +4563,7 @@ libc_support_library(
         ":__support_libc_errno",
         ":__support_macros_attributes",
         ":__support_macros_config",
+        ":__support_osutil_linux_syscall_wrappers_clone",
         ":__support_osutil_linux_syscall_wrappers_close",
         ":__support_osutil_linux_syscall_wrappers_getpid",
         ":__support_osutil_linux_syscall_wrappers_mmap",
@@ -4508,6 +4580,7 @@ libc_support_library(
         ":__support_threads_futex_utils",
         ":__support_threads_linux_futex_utils",
         ":__support_threads_linux_futex_word_type",
+        ":__support_threads_linux_tls",
         ":__support_threads_mutex",
         ":__support_threads_thread_attributes",
         ":__support_threads_thread_headers",
diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
index 4412ccc81dfed..7ef59c3f05baa 100644
--- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
@@ -75,42 +75,39 @@ def libc_release_copts():
     })
     return copts + platform_copts
 
-# Allowlisted sets of copts that may be used for a single libc library target.
+# Allowlisted copts that may be used for a single libc library target. These
+# mirror per-target COMPILE_OPTIONS in the CMake build; targets should list
+# exactly the options their CMake counterpart uses.
 # Adding copts here is discouraged, as it complicates the build.
-_LIBC_LIBRARY_COPT_SETS = {
-    "startup_object": [
-        "-ffreestanding",
-        "-fno-builtin",
-        "-fno-omit-frame-pointer",
-        "-fno-stack-protector",
-    ],
-    "threading": [
-        "-fno-omit-frame-pointer",
-        "-Wno-frame-address",
-    ],
-}
+_LIBC_LIBRARY_ALLOWED_COPTS = [
+    # CMake's ${libc_opt_high_flag}.
+    "-O3",
+    "-ffreestanding",
+    "-fno-builtin",
+    "-fno-omit-frame-pointer",
+    "-fno-stack-protector",
+]
 
 def _libc_library(
         name,
         deps = [],
-        copt_sets = [],
+        copts = [],
         **kwargs):
     """Internal macro to serve as a base for all other libc library rules.
 
     Args:
       name: Target name.
       deps: cc_library deps.
-      copt_sets: Which sets of allow-listed copts to include.
+      copts: Additional copts. Each must be in _LIBC_LIBRARY_ALLOWED_COPTS.
       **kwargs: All other attributes relevant for the cc_library rule.
     """
 
-    for attr in ["copts", "local_defines"]:
-        if attr in kwargs:
-            fail("disallowed attribute: '{}' in rule: '{}'".format(attr, name))
+    if "local_defines" in kwargs:
+        fail("disallowed attribute: 'local_defines' in rule: '{}'".format(name))
 
-    copts = []
-    for feature in copt_sets:
-        copts.extend(_LIBC_LIBRARY_COPT_SETS[feature])
+    for copt in copts:
+        if copt not in _LIBC_LIBRARY_ALLOWED_COPTS:
+            fail("disallowed copt: '{}' in rule: '{}'".format(copt, name))
 
     cc_library(
         name = name,
@@ -137,7 +134,6 @@ def libc_startup_library(name, **kwargs):
 
     _libc_library(
         name = name,
-        copt_sets = ["startup_object"],
         target_compatible_with = select({
             Label("//libc:full_build_linux"): [],
             "//conditions:default": ["@platforms//:incompatible"],
diff --git a/utils/bazel/llvm-project-overlay/libc/startup/linux/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/startup/linux/BUILD.bazel
index e8f76f330f49b..ab7ab2578ee72 100644
--- a/utils/bazel/llvm-project-overlay/libc/startup/linux/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/startup/linux/BUILD.bazel
@@ -48,12 +48,19 @@ libc_startup_library(
     hdrs = [
         "do_start.h",
     ],
+    copts = [
+        "-ffreestanding",
+        "-fno-builtin",
+        "-fno-stack-protector",
+    ],
     deps = [
         ":gnu_property_section",
         ":irelative_hdr",
         "//libc:__support_macros_config",
         "//libc:__support_osutil_linux_auxv",
         "//libc:__support_osutil_syscall",
+        "//libc:__support_threads_linux_futex_utils",
+        "//libc:__support_threads_linux_tls",
         "//libc:__support_threads_tcb",
         "//libc:__support_threads_thread",
         "//libc:__support_threads_thread_headers",
@@ -76,7 +83,6 @@ libc_startup_library(
     ] + selects.with_or({
         PLATFORM_CPU_X86_64: [
             "//libc/startup/linux/x86_64:irelative",
-            "//libc/startup/linux/x86_64:tls",
         ],
         "//conditions:default": [],
     }),
@@ -91,7 +97,6 @@ merge_relocatable_object(
         PLATFORM_CPU_X86_64: [
             "//libc/startup/linux/x86_64:irelative",
             "//libc/startup/linux/x86_64:start",
-            "//libc/startup/linux/x86_64:tls",
         ],
         "//conditions:default": [],
     }),
diff --git a/utils/bazel/llvm-project-overlay/libc/startup/linux/x86_64/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/startup/linux/x86_64/BUILD.bazel
index db07f7b62a2e7..3cfe98734851b 100644
--- a/utils/bazel/llvm-project-overlay/libc/startup/linux/x86_64/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/startup/linux/x86_64/BUILD.bazel
@@ -13,24 +13,15 @@ package(
     ],
 )
 
-libc_startup_library(
-    name = "tls",
-    srcs = ["tls.cpp"],
-    deps = [
-        "//libc:__support_macros_config",
-        "//libc:__support_osutil_linux_syscall_wrappers_getrandom",
-        "//libc:__support_osutil_linux_syscall_wrappers_mmap",
-        "//libc:__support_osutil_linux_syscall_wrappers_munmap",
-        "//libc:__support_threads_tcb",
-        "//libc:config_app_h",
-        "//libc:hdr_sys_mman_macros",
-        "//libc:string_memory_utils",
-    ],
-)
-
 libc_startup_library(
     name = "start",
     srcs = ["start.cpp"],
+    copts = [
+        "-fno-stack-protector",
+        "-fno-omit-frame-pointer",
+        "-ffreestanding",
+        "-fno-builtin",
+    ],
     deps = [
         "//libc:__support_macros_attributes",
         "//libc:config_app_h",
@@ -41,6 +32,12 @@ libc_startup_library(
 libc_startup_library(
     name = "irelative",
     srcs = ["irelative.cpp"],
+    copts = [
+        "-fno-stack-protector",
+        "-fno-omit-frame-pointer",
+        "-ffreestanding",
+        "-fno-builtin",
+    ],
     deps = [
         "//libc:__support_macros_config",
         "//libc:hdr_elf_macros",

>From 33df04c0112402e68be58cd0a1824203a80fd776 Mon Sep 17 00:00:00 2001
From: jtstogel <jtstogel at gmail.com>
Date: Fri, 18 Sep 2026 13:10:58 -0700
Subject: [PATCH 3/3] [Github] Add LLVM-libc's full-build to Bazel Checks
 workflow

This PR adds a job to run `bazelisk test -- at llvm-project//libc:build_mode=full @llvm-project//libc/...`. It is part of an effort to support LLVM-libc's full build functionality in Bazel.
---
 .github/workflows/bazel-checks.yml | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/bazel-checks.yml b/.github/workflows/bazel-checks.yml
index f2dd3ab35da9d..91bbfbbac5952 100644
--- a/.github/workflows/bazel-checks.yml
+++ b/.github/workflows/bazel-checks.yml
@@ -44,13 +44,23 @@ jobs:
           fi
 
   bazel-build:
-    name: "Bazel Build/Test"
+    name: "Bazel ${{ matrix.name }}"
     # Only run on US Central workers so we only have to keep one cache warm as
     # the cache buckets are per cluster.
     runs-on:
       group: llvm-premerge-cluster-us-central
       labels: llvm-premerge-linux-runners
     if: github.repository == 'llvm/llvm-project'
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          - name: "Build/Test"
+            flags: ""
+            targets: "@llvm-project//... //..."
+          - name: "LLVM-libc Fullbuild Tests"
+            flags: "-- at llvm-project//libc:build_mode=full"
+            targets: "@llvm-project//libc/..."
     steps:
       - name: Fetch LLVM sources
         uses: actions/checkout at df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
@@ -74,4 +84,5 @@ jobs:
             --remote_cache=https://storage.googleapis.com/$CACHE_GCS_BUCKET-bazel \
             --google_default_credentials \
             --remote_download_outputs=minimal \
-            @llvm-project//... //...
+            ${{ matrix.flags }} \
+            ${{ matrix.targets }}



More information about the llvm-commits mailing list