[libc-commits] [libc] [libc] Finetune libc.src.__support.OSUtil.osutil dependency. (PR #189501)
via libc-commits
libc-commits at lists.llvm.org
Mon Mar 30 22:05:58 PDT 2026
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/189501
>From 7b821a14e3c0a0652434bd36c395094cac6001bc Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 30 Mar 2026 22:41:36 +0000
Subject: [PATCH 1/4] [libc] Finetune libc.src.__support.OSUtil.osutil
dependency.
Targets included:
- libc.src.__support.libc_assert
- libc.src.__support.time.*
- libc.src.time.linux.*
- libc.src.unistd.*
- LibcTest
---
.../modules/LLVMLibCCompileOptionRules.cmake | 4 +++
libc/config/config.json | 6 +++++
libc/config/gpu/config.json | 5 ++++
libc/src/__support/CMakeLists.txt | 26 ++++++++++++-------
libc/src/__support/time/CMakeLists.txt | 4 ++-
libc/src/time/linux/CMakeLists.txt | 6 +++++
libc/src/unistd/CMakeLists.txt | 6 +++++
libc/test/UnitTest/CMakeLists.txt | 24 +++++++++++++----
libc/test/UnitTest/TestLogger.cpp | 19 +++++++++++++-
9 files changed, 84 insertions(+), 16 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 2e2c5e3ad7471..c034db8e6c4df 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -163,6 +163,10 @@ function(_get_compile_options_from_config output_var)
list(APPEND config_options "-DLIBC_COPT_PRINTF_DISABLE_BITINT")
endif()
+ if(LIBC_COPT_USE_C_ASSERT)
+ list(APPEND config_options "-DLIBC_COPT_USE_C_ASSERT")
+ endif()
+
set(${output_var} ${config_options} PARENT_SCOPE)
endfunction(_get_compile_options_from_config)
diff --git a/libc/config/config.json b/libc/config/config.json
index 39cb2d8cfa331..506526bbb1fc4 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -186,5 +186,11 @@
"value": false,
"doc": "Trap with SIGFPE when feraiseexcept is called with unmasked floating point exceptions, similar to glibc's behavior. This is currently working only on x86 with SSE."
}
+ },
+ "assert": {
+ "LIBC_COPT_USE_C_ASSERT": {
+ "value": false,
+ "doc": "Use the system assert macro for LIBC_ASSERT."
+ }
}
}
diff --git a/libc/config/gpu/config.json b/libc/config/gpu/config.json
index ef13f6a704635..c6318faaa3539 100644
--- a/libc/config/gpu/config.json
+++ b/libc/config/gpu/config.json
@@ -49,5 +49,10 @@
"LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR": {
"value": false
}
+ },
+ "assert": {
+ "LIBC_COPT_USE_C_ASSERT": {
+ "value": true
+ }
}
}
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 19b3a1d554f1c..7a845574eaad2 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -368,15 +368,23 @@ add_header_library(
libc.src.__support.macros.properties.types
)
-add_header_library(
- libc_assert
- HDRS
- libc_assert.h
- DEPENDS
- .integer_to_string
- libc.src.__support.OSUtil.osutil
- libc.src.__support.macros.optimization
-)
+if(LIBC_COPT_USE_C_ASSERT OR NOT LLVM_LIBC_FULL_BUILD)
+ add_header_library(
+ libc_assert
+ HDRS
+ libc_assert.h
+ )
+else()
+ add_header_library(
+ libc_assert
+ HDRS
+ libc_assert.h
+ DEPENDS
+ .integer_to_string
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.macros.optimization
+ )
+endif()
add_header_library(
hash
diff --git a/libc/src/__support/time/CMakeLists.txt b/libc/src/__support/time/CMakeLists.txt
index 3cc3fd873220a..f007f95bbee42 100644
--- a/libc/src/__support/time/CMakeLists.txt
+++ b/libc/src/__support/time/CMakeLists.txt
@@ -7,9 +7,11 @@ add_header_library(
libc.hdr.types.time_t
)
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}
+ AND TARGET libc.src.__support.OSUtil.osutil)
add_subdirectory(${LIBC_TARGET_OS})
else()
+ message(STATUS "Skip libc.src.__support.time.* targets.")
return()
endif()
diff --git a/libc/src/time/linux/CMakeLists.txt b/libc/src/time/linux/CMakeLists.txt
index 6ea04597063cb..623f01eb0d78c 100644
--- a/libc/src/time/linux/CMakeLists.txt
+++ b/libc/src/time/linux/CMakeLists.txt
@@ -1,3 +1,9 @@
+if(NOT TARGET libc.src.__support.OSUtil.osutil)
+ message(STATUS "libc.src.__support.OSUtil.osutil is not available. "
+ "Skip libc.src.time.linux.* targets.")
+ return()
+endif()
+
add_entrypoint_object(
timespec_get
SRCS
diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt
index 4d78b4a7fbc84..5e6df74ac92db 100644
--- a/libc/src/unistd/CMakeLists.txt
+++ b/libc/src/unistd/CMakeLists.txt
@@ -1,3 +1,9 @@
+if(NOT TARGET libc.src.__support.OSUtil.osutil)
+ message(STATUS "libc.src.__support.OSUtil.osutil is not avaiable. "
+ "Skip unistd targets.")
+ return()
+endif()
+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
endif()
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 54e41ece5f4d9..ba27d9e1a0ddd 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -3,7 +3,7 @@ function(add_unittest_framework_library name)
"TEST_LIB"
"" # No optional arguments
"" # No single value arguments
- "SRCS;HDRS;DEPENDS" # Multi value arguments
+ "SRCS;HDRS;DEPENDS;COMPILE_OPTIONS" # Multi value arguments
${ARGN}
)
if(NOT TEST_LIB_SRCS)
@@ -30,14 +30,17 @@ function(add_unittest_framework_library name)
# making LibcFPExceptionHelpers and LibcDeathTestExecutors hermetic.
set(LLVM_LIBC_FULL_BUILD "")
_get_common_test_compile_options(compile_options "" "")
- target_compile_options(${name}.unit PRIVATE ${compile_options})
set(LLVM_LIBC_FULL_BUILD ON)
else()
_get_common_test_compile_options(compile_options "" "")
- target_compile_options(${name}.unit PRIVATE ${compile_options})
endif()
- _get_hermetic_test_compile_options(compile_options "")
+ if (TEST_LIB_COMPILE_OPTIONS)
+ list(APPEND compile_options ${TEST_LIB_COMPILE_OPTIONS})
+ endif()
+ target_compile_options(${name}.unit PRIVATE ${compile_options})
+
+ _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++)
@@ -57,6 +60,15 @@ function(add_unittest_framework_library name)
endif()
endfunction()
+if (NOT TARGET libc.src.__support.OSUtil.osutil AND NOT LLVM_LIBC_FULL_BUILD)
+ message(STATUS "TestLogger will use system libc's stdio to print.")
+ set(test_logger_compile_options "-DLIBC_TEST_USE_SYSTEM_PRINTF")
+ set(test_logger_osutil "")
+else()
+ set(test_logger_compile_options "")
+ set(test_logger_osutil "libc.src.__support.OSUtil.osutil")
+endif()
+
add_unittest_framework_library(
LibcTest
SRCS
@@ -68,6 +80,8 @@ add_unittest_framework_library(
LibcTest.h
Test.h
TestLogger.h
+ COMPILE_OPTIONS
+ ${test_logger_compile_options}
DEPENDS
libc.hdr.stdint_proxy
libc.src.__support.big_int
@@ -78,8 +92,8 @@ add_unittest_framework_library(
libc.src.__support.fixed_point.fx_rep
libc.src.__support.macros.properties.compiler
libc.src.__support.macros.properties.types
- libc.src.__support.OSUtil.osutil
libc.src.__support.uint128
+ ${test_logger_osutil}
)
set(libc_death_test_srcs LibcDeathTestExecutors.cpp)
diff --git a/libc/test/UnitTest/TestLogger.cpp b/libc/test/UnitTest/TestLogger.cpp
index 3d95d48a5f5a2..50656e5c09513 100644
--- a/libc/test/UnitTest/TestLogger.cpp
+++ b/libc/test/UnitTest/TestLogger.cpp
@@ -2,12 +2,29 @@
#include "hdr/stdint_proxy.h"
#include "src/__support/CPP/string.h"
#include "src/__support/CPP/string_view.h"
-#include "src/__support/OSUtil/io.h" // write_to_stderr
#include "src/__support/big_int.h" // is_big_int
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
#include "src/__support/uint128.h"
+#ifdef LIBC_TEST_USE_SYSTEM_PRINTF
+
+#include <stdio.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+void write_to_stderr(cpp::string_view str) {
+ fprintf(stderr, "%.*s", static_cast<int>(str.size()), str.data());
+}
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#else // !LIBC_TEST_USE_SYSTEM_PRINTF
+
+#include "src/__support/OSUtil/io.h" // write_to_stderr
+
+#endif // LIBC_TEST_USE_SYSTEM_PRINTF
+
namespace LIBC_NAMESPACE_DECL {
namespace testing {
>From 7b37be072e2ff9e393d03baf2cc152b2db992b92 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 31 Mar 2026 04:34:58 +0000
Subject: [PATCH 2/4] Fix definition flag for MSVC.
---
.../modules/LLVMLibCCompileOptionRules.cmake | 87 +++++++++++--------
libc/src/__support/CMakeLists.txt | 3 +-
libc/src/__support/HashTable/CMakeLists.txt | 2 +-
.../__support/threads/linux/CMakeLists.txt | 11 +--
libc/src/setjmp/aarch64/CMakeLists.txt | 12 ++-
libc/test/UnitTest/CMakeLists.txt | 2 +-
6 files changed, 68 insertions(+), 49 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index c034db8e6c4df..f4f975ddc224a 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -10,6 +10,31 @@ if(NOT DEFINED LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
endif()
endif()
+function(libc_add_definition output_var def)
+ if(MSVC)
+ list(APPEND ${output_var} "/D${def}")
+ else()
+ list(APPEND ${output_var} "-D${def}")
+ endif()
+
+ set(${output_var} ${${output_var}} PARENT_SCOPE)
+endfunction()
+
+function(libc_set_definition output_var)
+ set(defs "")
+ if(MSVC)
+ foreach(def IN LISTS ARGN)
+ list(APPEND defs "/D${def}")
+ endforeach()
+ else()
+ foreach(def IN LISTS ARGN)
+ list(APPEND defs "-D${def}")
+ endforeach()
+ endif()
+
+ set(${output_var} "${defs}" PARENT_SCOPE)
+endfunction()
+
function(_get_compile_options_from_flags output_var)
set(compile_options "")
@@ -45,9 +70,6 @@ function(_get_compile_options_from_flags output_var)
list(APPEND compile_options "-D__LIBC_USE_BUILTIN_ROUNDEVEN")
endif()
endif()
- if(ADD_EXPLICIT_SIMD_OPT_FLAG)
- list(APPEND compile_options "-D__LIBC_EXPLICIT_SIMD_OPT")
- endif()
if(ADD_MISC_MATH_BASIC_OPS_OPT_FLAG)
list(APPEND compile_options "-D__LIBC_MISC_MATH_BASIC_OPS_OPT")
if(LIBC_COMPILER_HAS_BUILTIN_FMAX_FMIN)
@@ -66,9 +88,10 @@ function(_get_compile_options_from_flags output_var)
if(ADD_FMA_FLAG)
list(APPEND compile_options "/arch:AVX2")
endif()
- if(ADD_EXPLICIT_SIMD_OPT_FLAG)
- list(APPEND compile_options "/D__LIBC_EXPLICIT_SIMD_OPT")
- endif()
+ endif()
+
+ if(ADD_EXPLICIT_SIMD_OPT_FLAG)
+ libc_add_definition(compile_options "__LIBC_EXPLICIT_SIMD_OPT")
endif()
set(${output_var} ${compile_options} PARENT_SCOPE)
@@ -78,89 +101,85 @@ function(_get_compile_options_from_config output_var)
set(config_options "")
if(LIBC_CONF_STRTOFLOAT_DISABLE_EISEL_LEMIRE)
- list(APPEND config_options "-DLIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE")
+ libc_add_definition(config_options LIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE")
endif()
if(LIBC_CONF_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION)
- list(APPEND config_options "-DLIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION")
+ libc_add_definition(config_options LIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION")
endif()
if(LIBC_CONF_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH)
- list(APPEND config_options "-DLIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH")
+ libc_add_definition(config_options LIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH")
endif()
if(LIBC_CONF_QSORT_IMPL)
- list(APPEND config_options "-DLIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
+ libc_add_definition(config_options LIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
endif()
- list(APPEND config_options "-DLIBC_COPT_STRING_LENGTH_IMPL=${LIBC_CONF_STRING_LENGTH_IMPL}")
- list(APPEND config_options "-DLIBC_COPT_FIND_FIRST_CHARACTER_IMPL=${LIBC_CONF_FIND_FIRST_CHARACTER_IMPL}")
+ libc_add_definition(config_options LIBC_COPT_STRING_LENGTH_IMPL=${LIBC_CONF_STRING_LENGTH_IMPL}")
+ libc_add_definition(config_options LIBC_COPT_FIND_FIRST_CHARACTER_IMPL=${LIBC_CONF_FIND_FIRST_CHARACTER_IMPL}")
if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING)
- list(APPEND config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
+ libc_add_definition(config_options LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
endif()
if(LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES)
- list(APPEND config_options "-DLIBC_COPT_MEMCPY_X86_USE_NTA_STORES")
+ libc_add_definition(config_options LIBC_COPT_MEMCPY_X86_USE_NTA_STORES")
endif()
if(LIBC_TYPES_TIME_T_IS_32_BIT AND LLVM_LIBC_FULL_BUILD)
- list(APPEND config_options "-DLIBC_TYPES_TIME_T_IS_32_BIT")
+ libc_add_definition(config_options LIBC_TYPES_TIME_T_IS_32_BIT")
endif()
if(LIBC_ADD_NULL_CHECKS)
- list(APPEND config_options "-DLIBC_ADD_NULL_CHECKS")
+ libc_add_definition(config_options LIBC_ADD_NULL_CHECKS")
endif()
if(NOT "${LIBC_CONF_FREXP_INF_NAN_EXPONENT}" STREQUAL "")
- list(APPEND config_options "-DLIBC_FREXP_INF_NAN_EXPONENT=${LIBC_CONF_FREXP_INF_NAN_EXPONENT}")
+ libc_add_definition(config_options LIBC_FREXP_INF_NAN_EXPONENT=${LIBC_CONF_FREXP_INF_NAN_EXPONENT}")
endif()
if(LIBC_CONF_MATH_OPTIMIZATIONS)
- list(APPEND config_options "-DLIBC_MATH=${LIBC_CONF_MATH_OPTIMIZATIONS}")
+ libc_add_definition(config_options LIBC_MATH=${LIBC_CONF_MATH_OPTIMIZATIONS}")
if(LIBC_CONF_MATH_OPTIMIZATIONS MATCHES "LIBC_MATH_NO_ERRNO")
list(APPEND config_options "-fno-math-errno")
endif()
endif()
if(LIBC_CONF_ERRNO_MODE)
- list(APPEND config_options "-DLIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}")
+ libc_add_definition(config_options LIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}")
endif()
if(LIBC_CONF_THREAD_MODE)
- list(APPEND config_options "-DLIBC_THREAD_MODE=${LIBC_CONF_THREAD_MODE}")
+ libc_add_definition(config_options LIBC_THREAD_MODE=${LIBC_CONF_THREAD_MODE}")
endif()
if(LIBC_CONF_TRAP_ON_RAISE_FP_EXCEPT)
- list(APPEND config_options "-DLIBC_TRAP_ON_RAISE_FP_EXCEPT")
+ libc_add_definition(config_options LIBC_TRAP_ON_RAISE_FP_EXCEPT")
endif()
if(LIBC_CONF_WCTYPE_MODE)
- list(APPEND config_options "-DLIBC_CONF_WCTYPE_MODE=${LIBC_CONF_WCTYPE_MODE}")
+ libc_add_definition(config_options LIBC_CONF_WCTYPE_MODE=${LIBC_CONF_WCTYPE_MODE}")
endif()
if(LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT)
- list(APPEND config_options "-DLIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=${LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT}")
+ libc_add_definition(config_options LIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=${LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT}")
endif()
if(LIBC_CONF_MATH_USE_SYSTEM_FENV)
- if(MSVC)
- list(APPEND config_options "/DLIBC_MATH_USE_SYSTEM_FENV")
- else()
- list(APPEND config_options "-DLIBC_MATH_USE_SYSTEM_FENV")
- endif()
+ libc_add_definition(config_options LIBC_MATH_USE_SYSTEM_FENV")
endif()
if(LIBC_CONF_CTYPE_SMALLER_ASCII)
- list(APPEND config_options "-DLIBC_COPT_CTYPE_SMALLER_ASCII")
+ libc_add_definition(config_options LIBC_COPT_CTYPE_SMALLER_ASCII")
endif()
if(LIBC_CONF_PRINTF_DISABLE_WIDE)
- list(APPEND config_options "-DLIBC_COPT_PRINTF_DISABLE_WIDE")
+ libc_add_definition(config_options LIBC_COPT_PRINTF_DISABLE_WIDE")
endif()
if(LIBC_COPT_PRINTF_DISABLE_BITINT)
- list(APPEND config_options "-DLIBC_COPT_PRINTF_DISABLE_BITINT")
+ libc_add_definition(config_options LIBC_COPT_PRINTF_DISABLE_BITINT")
endif()
if(LIBC_COPT_USE_C_ASSERT)
@@ -177,13 +196,13 @@ function(_get_compile_options_from_arch output_var)
set(config_options "")
if (LIBC_TARGET_OS_IS_BAREMETAL)
- list(APPEND config_options "-DLIBC_TARGET_OS_IS_BAREMETAL")
+ libc_add_definition(config_options LIBC_TARGET_OS_IS_BAREMETAL")
endif()
if (LIBC_TARGET_OS_IS_GPU)
- list(APPEND config_options "-DLIBC_TARGET_OS_IS_GPU")
+ libc_add_definition(config_options LIBC_TARGET_OS_IS_GPU")
endif()
if (LIBC_TARGET_OS_IS_UEFI)
- list(APPEND config_options "-DLIBC_TARGET_OS_IS_UEFI")
+ libc_add_definition(config_options LIBC_TARGET_OS_IS_UEFI")
endif()
set(${output_var} ${config_options} PARENT_SCOPE)
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 7a845574eaad2..08a4db8e49a73 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -59,6 +59,7 @@ add_header_library(
.freetrie
)
+libc_set_definition(libc_freelist_malloc_size "LIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}")
add_object_library(
freelist_heap
SRCS
@@ -66,7 +67,7 @@ add_object_library(
HDRS
freelist_heap.h
COMPILE_OPTIONS
- -DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
+ ${libc_freelist_malloc_size}
DEPENDS
.block
.freelist
diff --git a/libc/src/__support/HashTable/CMakeLists.txt b/libc/src/__support/HashTable/CMakeLists.txt
index 82e88c02ae443..6dfe2391e7316 100644
--- a/libc/src/__support/HashTable/CMakeLists.txt
+++ b/libc/src/__support/HashTable/CMakeLists.txt
@@ -14,7 +14,7 @@ add_header_library(
list(FIND TARGET_ENTRYPOINT_NAME_LIST getrandom getrandom_index)
if (NOT ${getrandom_index} EQUAL -1)
message(STATUS "Using getrandom for hashtable randomness")
- set(randomness_compile_flags -DLIBC_HASHTABLE_USE_GETRANDOM)
+ libc_set_definition(randomness_compile_flags LIBC_HASHTABLE_USE_GETRANDOM)
set(randomness_extra_depends
libc.src.__support.OSUtil.linux.syscall_wrappers.getrandom
libc.hdr.errno_macros)
diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index 200a3b1529fec..7ae8eccebdd27 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -26,15 +26,19 @@ add_header_library(
set(monotonicity_flags)
if (LIBC_CONF_TIMEOUT_ENSURE_MONOTONICITY)
- set(monotonicity_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=1)
+ libc_set_definition(monotonicity_flags LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=1)
else()
- set(monotonicity_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=0)
+ libc_set_definition(monotonicity_flags LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=0)
endif()
+libc_set_definition(rwlock_default_spin_count LIBC_COPT_RWLOCK_DEFAULT_SPIN_COUNT=${LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT})
add_header_library(
rwlock
HDRS
rwlock.h
+ COMPILE_OPTIONS
+ ${rwlock_default_spin_count}
+ ${monotonicity_flags}
DEPENDS
.futex_utils
libc.src.__support.threads.raw_mutex
@@ -42,9 +46,6 @@ add_header_library(
libc.src.__support.OSUtil.osutil
libc.src.__support.CPP.limits
libc.src.__support.threads.identifier
- COMPILE_OPTIONS
- -DLIBC_COPT_RWLOCK_DEFAULT_SPIN_COUNT=${LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT}
- ${monotonicity_flags}
)
add_object_library(
diff --git a/libc/src/setjmp/aarch64/CMakeLists.txt b/libc/src/setjmp/aarch64/CMakeLists.txt
index 12991101b0fdd..cbb36ecddd406 100644
--- a/libc/src/setjmp/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/aarch64/CMakeLists.txt
@@ -1,9 +1,5 @@
if(LIBC_CONF_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER)
- list(APPEND setjmp_config_options "-DLIBC_COPT_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER")
-endif()
-if(setjmp_config_options)
- list(PREPEND setjmp_config_options "COMPILE_OPTIONS")
-endif()
+ libc_set_definition(setjmp_config_options LIBC_COPT_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER)
add_entrypoint_object(
setjmp
@@ -11,9 +7,10 @@ add_entrypoint_object(
setjmp.cpp
HDRS
../setjmp_impl.h
+ COMPILE_OPTIONS
+ "${setjmp_config_options}"
DEPENDS
libc.hdr.types.jmp_buf
- ${setjmp_config_options}
)
add_entrypoint_object(
@@ -22,9 +19,10 @@ add_entrypoint_object(
longjmp.cpp
HDRS
../longjmp.h
+ COMPILE_OPTIONS
+ "${setjmp_config_options}"
DEPENDS
libc.hdr.types.jmp_buf
- ${setjmp_config_options}
)
add_entrypoint_object(
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index ba27d9e1a0ddd..638c66b1aceb7 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -62,7 +62,7 @@ endfunction()
if (NOT TARGET libc.src.__support.OSUtil.osutil AND NOT LLVM_LIBC_FULL_BUILD)
message(STATUS "TestLogger will use system libc's stdio to print.")
- set(test_logger_compile_options "-DLIBC_TEST_USE_SYSTEM_PRINTF")
+ libc_set_definition(test_logger_compile_options LIBC_TEST_USE_SYSTEM_PRINTF)
set(test_logger_osutil "")
else()
set(test_logger_compile_options "")
>From dd9e6b795c0a2161a9d5c98cc0db0403b973d9c8 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 31 Mar 2026 04:42:29 +0000
Subject: [PATCH 3/4] Fix merging issues.
---
.../modules/LLVMLibCCompileOptionRules.cmake | 48 +++++++++----------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index f4f975ddc224a..426fcef7e36f4 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -101,85 +101,85 @@ function(_get_compile_options_from_config output_var)
set(config_options "")
if(LIBC_CONF_STRTOFLOAT_DISABLE_EISEL_LEMIRE)
- libc_add_definition(config_options LIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE")
+ libc_add_definition(config_options "LIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE")
endif()
if(LIBC_CONF_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION)
- libc_add_definition(config_options LIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION")
+ libc_add_definition(config_options "LIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION")
endif()
if(LIBC_CONF_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH)
- libc_add_definition(config_options LIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH")
+ libc_add_definition(config_options "LIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH")
endif()
if(LIBC_CONF_QSORT_IMPL)
- libc_add_definition(config_options LIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
+ libc_add_definition(config_options "LIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
endif()
- libc_add_definition(config_options LIBC_COPT_STRING_LENGTH_IMPL=${LIBC_CONF_STRING_LENGTH_IMPL}")
- libc_add_definition(config_options LIBC_COPT_FIND_FIRST_CHARACTER_IMPL=${LIBC_CONF_FIND_FIRST_CHARACTER_IMPL}")
+ libc_add_definition(config_options "LIBC_COPT_STRING_LENGTH_IMPL=${LIBC_CONF_STRING_LENGTH_IMPL}")
+ libc_add_definition(config_options "LIBC_COPT_FIND_FIRST_CHARACTER_IMPL=${LIBC_CONF_FIND_FIRST_CHARACTER_IMPL}")
if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING)
- libc_add_definition(config_options LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
+ libc_add_definition(config_options "LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
endif()
if(LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES)
- libc_add_definition(config_options LIBC_COPT_MEMCPY_X86_USE_NTA_STORES")
+ libc_add_definition(config_options "LIBC_COPT_MEMCPY_X86_USE_NTA_STORES")
endif()
if(LIBC_TYPES_TIME_T_IS_32_BIT AND LLVM_LIBC_FULL_BUILD)
- libc_add_definition(config_options LIBC_TYPES_TIME_T_IS_32_BIT")
+ libc_add_definition(config_options "LIBC_TYPES_TIME_T_IS_32_BIT")
endif()
if(LIBC_ADD_NULL_CHECKS)
- libc_add_definition(config_options LIBC_ADD_NULL_CHECKS")
+ libc_add_definition(config_options "LIBC_ADD_NULL_CHECKS")
endif()
if(NOT "${LIBC_CONF_FREXP_INF_NAN_EXPONENT}" STREQUAL "")
- libc_add_definition(config_options LIBC_FREXP_INF_NAN_EXPONENT=${LIBC_CONF_FREXP_INF_NAN_EXPONENT}")
+ libc_add_definition(config_options "LIBC_FREXP_INF_NAN_EXPONENT=${LIBC_CONF_FREXP_INF_NAN_EXPONENT}")
endif()
if(LIBC_CONF_MATH_OPTIMIZATIONS)
- libc_add_definition(config_options LIBC_MATH=${LIBC_CONF_MATH_OPTIMIZATIONS}")
+ libc_add_definition(config_options "LIBC_MATH=${LIBC_CONF_MATH_OPTIMIZATIONS}")
if(LIBC_CONF_MATH_OPTIMIZATIONS MATCHES "LIBC_MATH_NO_ERRNO")
list(APPEND config_options "-fno-math-errno")
endif()
endif()
if(LIBC_CONF_ERRNO_MODE)
- libc_add_definition(config_options LIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}")
+ libc_add_definition(config_options "LIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}")
endif()
if(LIBC_CONF_THREAD_MODE)
- libc_add_definition(config_options LIBC_THREAD_MODE=${LIBC_CONF_THREAD_MODE}")
+ libc_add_definition(config_options "LIBC_THREAD_MODE=${LIBC_CONF_THREAD_MODE}")
endif()
if(LIBC_CONF_TRAP_ON_RAISE_FP_EXCEPT)
- libc_add_definition(config_options LIBC_TRAP_ON_RAISE_FP_EXCEPT")
+ libc_add_definition(config_options "LIBC_TRAP_ON_RAISE_FP_EXCEPT")
endif()
if(LIBC_CONF_WCTYPE_MODE)
- libc_add_definition(config_options LIBC_CONF_WCTYPE_MODE=${LIBC_CONF_WCTYPE_MODE}")
+ libc_add_definition(config_options "LIBC_CONF_WCTYPE_MODE=${LIBC_CONF_WCTYPE_MODE}")
endif()
if(LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT)
- libc_add_definition(config_options LIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=${LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT}")
+ libc_add_definition(config_options "LIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=${LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT}")
endif()
if(LIBC_CONF_MATH_USE_SYSTEM_FENV)
- libc_add_definition(config_options LIBC_MATH_USE_SYSTEM_FENV")
+ libc_add_definition(config_options "LIBC_MATH_USE_SYSTEM_FENV")
endif()
if(LIBC_CONF_CTYPE_SMALLER_ASCII)
- libc_add_definition(config_options LIBC_COPT_CTYPE_SMALLER_ASCII")
+ libc_add_definition(config_options "LIBC_COPT_CTYPE_SMALLER_ASCII")
endif()
if(LIBC_CONF_PRINTF_DISABLE_WIDE)
- libc_add_definition(config_options LIBC_COPT_PRINTF_DISABLE_WIDE")
+ libc_add_definition(config_options "LIBC_COPT_PRINTF_DISABLE_WIDE")
endif()
if(LIBC_COPT_PRINTF_DISABLE_BITINT)
- libc_add_definition(config_options LIBC_COPT_PRINTF_DISABLE_BITINT")
+ libc_add_definition(config_options "LIBC_COPT_PRINTF_DISABLE_BITINT")
endif()
if(LIBC_COPT_USE_C_ASSERT)
@@ -196,13 +196,13 @@ function(_get_compile_options_from_arch output_var)
set(config_options "")
if (LIBC_TARGET_OS_IS_BAREMETAL)
- libc_add_definition(config_options LIBC_TARGET_OS_IS_BAREMETAL")
+ libc_add_definition(config_options "LIBC_TARGET_OS_IS_BAREMETAL")
endif()
if (LIBC_TARGET_OS_IS_GPU)
- libc_add_definition(config_options LIBC_TARGET_OS_IS_GPU")
+ libc_add_definition(config_options "LIBC_TARGET_OS_IS_GPU")
endif()
if (LIBC_TARGET_OS_IS_UEFI)
- libc_add_definition(config_options LIBC_TARGET_OS_IS_UEFI")
+ libc_add_definition(config_options "LIBC_TARGET_OS_IS_UEFI")
endif()
set(${output_var} ${config_options} PARENT_SCOPE)
>From 987425cb13647f2e4a0dff27ed9d5b11cae4841e Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 31 Mar 2026 05:05:30 +0000
Subject: [PATCH 4/4] Fix test logger cmake condition.
---
libc/test/UnitTest/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 638c66b1aceb7..d4d01c5bac96d 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -60,7 +60,7 @@ function(add_unittest_framework_library name)
endif()
endfunction()
-if (NOT TARGET libc.src.__support.OSUtil.osutil AND NOT LLVM_LIBC_FULL_BUILD)
+if (NOT TARGET libc.src.__support.OSUtil.osutil OR NOT LLVM_LIBC_FULL_BUILD)
message(STATUS "TestLogger will use system libc's stdio to print.")
libc_set_definition(test_logger_compile_options LIBC_TEST_USE_SYSTEM_PRINTF)
set(test_logger_osutil "")
More information about the libc-commits
mailing list