Skip to content

[libc] Fix unit test dependency and respect LIBC_INCLUDE_BENCHMARKS#180812

Merged
jhuber6 merged 1 commit intollvm:mainfrom
jhuber6:FixBenchCmake
Feb 10, 2026
Merged

[libc] Fix unit test dependency and respect LIBC_INCLUDE_BENCHMARKS#180812
jhuber6 merged 1 commit intollvm:mainfrom
jhuber6:FixBenchCmake

Conversation

@jhuber6
Copy link
Copy Markdown
Contributor

@jhuber6 jhuber6 commented Feb 10, 2026

Summary:
The unittest framework function is defined in another CMake file which
may not be present if the uesr disabled tests, provide a smaller version
here to keep this private. Also respesct the LIBC_INCLUDE_BENCHMARKS
variable.

Summary:
The unittest framework function is defined in another CMake file which
may not be present if the uesr disabled tests, provide a smaller version
here to keep this private. Also respesct the LIBC_INCLUDE_BENCHMARKS
variable.
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 10, 2026

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
The unittest framework function is defined in another CMake file which
may not be present if the uesr disabled tests, provide a smaller version
here to keep this private. Also respesct the LIBC_INCLUDE_BENCHMARKS
variable.


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

2 Files Affected:

  • (modified) libc/benchmarks/CMakeLists.txt (+4-4)
  • (modified) libc/benchmarks/gpu/CMakeLists.txt (+43-1)
diff --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt
index c17cc106f96d7..65c7cd76fad29 100644
--- a/libc/benchmarks/CMakeLists.txt
+++ b/libc/benchmarks/CMakeLists.txt
@@ -1,10 +1,10 @@
-if(LIBC_TARGET_OS_IS_GPU)
-  add_subdirectory(gpu)
+# The CPU build depends on Google benchmark.
+if(NOT LIBC_INCLUDE_BENCHMARKS)
   return()
 endif()
 
-# The CPU build depends on Google benchmark.
-if(NOT LIBC_INCLUDE_BENCHMARKS)
+if(LIBC_TARGET_OS_IS_GPU)
+  add_subdirectory(gpu)
   return()
 endif()
 
diff --git a/libc/benchmarks/gpu/CMakeLists.txt b/libc/benchmarks/gpu/CMakeLists.txt
index cf8c9902ca7f0..629e51c39dbb3 100644
--- a/libc/benchmarks/gpu/CMakeLists.txt
+++ b/libc/benchmarks/gpu/CMakeLists.txt
@@ -33,7 +33,49 @@ function(add_benchmark benchmark_name)
   add_dependencies(gpu-benchmark ${fq_target_name})
 endfunction(add_benchmark)
 
-add_unittest_framework_library(
+function(add_benchmark_framework_library name)
+  cmake_parse_arguments(
+    "TEST_LIB"
+    "" # No optional arguments
+    "" # No single value arguments
+    "SRCS;HDRS;DEPENDS" # Multi value arguments
+    ${ARGN}
+  )
+  if(NOT TEST_LIB_SRCS)
+    message(FATAL_ERROR "'add_benchmark_framework_library' requires SRCS; for "
+                        "header only libraries, use 'add_header_library'")
+  endif()
+
+  foreach(lib IN ITEMS ${name}.hermetic)
+    add_library(
+      ${lib}
+      STATIC
+      EXCLUDE_FROM_ALL
+      ${TEST_LIB_SRCS}
+      ${TEST_LIB_HDRS}
+    )
+    target_include_directories(${lib} PRIVATE ${LIBC_SOURCE_DIR})
+    if(TARGET libc.src.time.clock)
+      target_compile_definitions(${lib} PRIVATE TARGET_SUPPORTS_CLOCK)
+    endif()
+  endforeach()
+
+  _get_hermetic_test_compile_options(compile_options "")
+  target_include_directories(${name}.hermetic PRIVATE ${LIBC_INCLUDE_DIR})
+  target_compile_options(${name}.hermetic PRIVATE ${compile_options} -nostdinc++)
+
+  if(TEST_LIB_DEPENDS)
+    foreach(dep IN ITEMS ${TEST_LIB_DEPENDS})
+      if(TARGET ${dep}.hermetic)
+        add_dependencies(${name}.hermetic ${dep}.hermetic)
+      else()
+        add_dependencies(${name}.hermetic ${dep})
+      endif()
+    endforeach()
+  endif()
+endfunction()
+
+add_benchmark_framework_library(
   LibcGpuBenchmark
   SRCS
     LibcGpuBenchmark.cpp

Copy link
Copy Markdown
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.

LGTM

@jhuber6 jhuber6 merged commit c9ee81a into llvm:main Feb 10, 2026
28 checks passed
ronlieb pushed a commit to ROCm/llvm-project that referenced this pull request Feb 11, 2026
…lvm#180812)

Summary:
The unittest framework function is defined in another CMake file which
may not be present if the uesr disabled tests, provide a smaller version
here to keep this private. Also respesct the LIBC_INCLUDE_BENCHMARKS
variable.
ronlieb added a commit to ROCm/llvm-project that referenced this pull request Feb 11, 2026
#1414)

…llvm#180812)

Summary:
The unittest framework function is defined in another CMake file which
may not be present if the uesr disabled tests, provide a smaller version
here to keep this private. Also respesct the LIBC_INCLUDE_BENCHMARKS
variable.

Co-authored-by: Joseph Huber <[email protected]>
@jhuber6 jhuber6 added this to the LLVM 22.x Release milestone Feb 11, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in LLVM Release Status Feb 11, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in LLVM Release Status Feb 11, 2026
@jhuber6
Copy link
Copy Markdown
Contributor Author

jhuber6 commented Feb 11, 2026

/cherry-pick c9ee81a

@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 11, 2026

/pull-request #181048

c-rhodes pushed a commit to llvmbot/llvm-project that referenced this pull request Feb 12, 2026
…lvm#180812)

Summary:
The unittest framework function is defined in another CMake file which
may not be present if the uesr disabled tests, provide a smaller version
here to keep this private. Also respesct the LIBC_INCLUDE_BENCHMARKS
variable.

(cherry picked from commit c9ee81a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Development

Successfully merging this pull request may close these issues.

3 participants