[libc-commits] [libc] [libc][cmake] Disable unit tests on bare-metal (PR #187296)

Volodymyr Turanskyy via libc-commits libc-commits at lists.llvm.org
Wed Mar 18 08:12:12 PDT 2026


https://github.com/voltur01 created https://github.com/llvm/llvm-project/pull/187296

Disable unit tests on bare-metal targets where they fail to build and avoid trying to build unit tests implicitly through dependencies before lit is run.

Assisted-by: codex for initial fix and refinement, the changes were reviewed by me and tested with Arm Toolchain for Embedded.

>From aaae18fbbda886afd1a1c78b2d16c2aab89364fb Mon Sep 17 00:00:00 2001
From: Volodymyr Turanskyy <volodymyr.turanskyy at arm.com>
Date: Wed, 18 Mar 2026 14:50:30 +0000
Subject: [PATCH] Disable unit tests on bare-metal

Disable unit tests on bare-metal targets where they fail to build and avoid trying to build unit tests implicitly through dependencies before lit is run.

Assisted-by: codex for initial fix and refinement, the changes were reviewed by me and tested with Arm Toolchain for Embedded.
---
 libc/CMakeLists.txt                        | 2 ++
 libc/cmake/modules/LLVMLibCTestRules.cmake | 4 ++++
 libc/test/CMakeLists.txt                   | 8 +++++++-
 libc/test/include/CMakeLists.txt           | 1 -
 libc/test/integration/CMakeLists.txt       | 1 -
 5 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 2d474f08841ca..0f28dd4682053 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -271,6 +271,8 @@ endif()
 if(LIBC_TARGET_OS_IS_GPU)
   include(prepare_libc_gpu_build)
   set(LIBC_ENABLE_UNITTESTS OFF)
+elseif(LIBC_TARGET_OS_IS_BAREMETAL)
+  set(LIBC_ENABLE_UNITTESTS OFF)
 endif()
 
 include(LLVMLibCCheckMPFR)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 6759bb9fb833e..e392bae9941bb 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -350,6 +350,9 @@ function(create_libc_unittest fq_target_name)
 endfunction(create_libc_unittest)
 
 function(add_libc_unittest target_name)
+  if(NOT LIBC_ENABLE_UNITTESTS)
+    return()
+  endif()
   add_target_with_flags(
     ${target_name}
     CREATE_TARGET create_libc_unittest
@@ -667,6 +670,7 @@ function(add_integration_test test_name)
     COMMENT "Running integration test ${fq_target_name}"
   )
   add_dependencies(${INTEGRATION_TEST_SUITE} ${fq_target_name})
+  add_dependencies(libc-integration-tests-build ${fq_build_target_name})
 endfunction(add_integration_test)
 
 # Rule to add a hermetic program. A hermetic program is one whose executable is fully
diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index bff8e9d82e949..7855dfe8b2f84 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -13,6 +13,7 @@ add_custom_target(libc-long-running-tests)
 # Build-only targets for lit (don't run tests, just build executables)
 add_custom_target(libc-unit-tests-build)
 add_custom_target(libc-hermetic-tests-build)
+add_custom_target(libc-integration-tests-build)
 
 # Resolve the GPU loader executable path for the lit site config.
 if(TARGET libc.utils.gpu.loader)
@@ -35,10 +36,15 @@ configure_lit_site_cfg(
   "LIBC_GPU_LOADER_EXECUTABLE"
 )
 
+set(libc_lit_deps libc-hermetic-tests-build libc-integration-tests-build)
+if(LIBC_ENABLE_UNITTESTS)
+  list(APPEND libc_lit_deps libc-unit-tests-build)
+endif()
+
 add_lit_testsuite(check-libc-lit
   "Running libc tests via lit"
   ${LIBC_BUILD_DIR}/test
-  DEPENDS libc-unit-tests-build libc-hermetic-tests-build
+  DEPENDS ${libc_lit_deps}
 )
 
 add_subdirectory(UnitTest)
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index c1828f51c261e..3ac5615d7e209 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -1,6 +1,5 @@
 add_custom_target(libc_include_tests)
 add_dependencies(check-libc libc_include_tests)
-add_dependencies(check-libc-lit libc_include_tests)
 
 add_libc_test(
   assert_test
diff --git a/libc/test/integration/CMakeLists.txt b/libc/test/integration/CMakeLists.txt
index 9a7e9a57752e6..7dbcc9544a0b9 100644
--- a/libc/test/integration/CMakeLists.txt
+++ b/libc/test/integration/CMakeLists.txt
@@ -1,6 +1,5 @@
 add_custom_target(libc-integration-tests)
 add_dependencies(check-libc libc-integration-tests)
-add_dependencies(check-libc-lit libc-integration-tests)
 
 function(add_libc_integration_test_suite name)
   add_custom_target(${name})



More information about the libc-commits mailing list