Skip to content

Commit d37496e

Browse files
[libc] Fix printf config not working (#66834)
The list of printf copts available in config.json wasn't working because the printf_core subdirectory was included before the printf_copts variable was defined, making it effectively nothing for the printf internals. Additionally, the tests weren't respecting the flags so they would cause the tests to fail. This patch reorders the cmake in src and adds flag handling in test.
1 parent 6af2674 commit d37496e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

libc/src/stdio/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
2626
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
2727
endif()
2828

29-
add_subdirectory(printf_core)
30-
add_subdirectory(scanf_core)
31-
3229
add_entrypoint_object(
3330
fflush
3431
SRCS
@@ -286,6 +283,9 @@ add_entrypoint_object(
286283
${printf_copts}
287284
)
288285

286+
add_subdirectory(printf_core)
287+
add_subdirectory(scanf_core)
288+
289289
add_entrypoint_object(
290290
ftell
291291
SRCS

libc/test/src/stdio/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ add_libc_unittest(
112112
LibcMemoryHelpers
113113
)
114114

115+
if(LIBC_CONF_PRINTF_DISABLE_FLOAT)
116+
list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")
117+
endif()
118+
if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)
119+
list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")
120+
endif()
121+
if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)
122+
list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")
123+
endif()
124+
115125
add_fp_unittest(
116126
sprintf_test
117127
UNIT_TEST_ONLY
@@ -123,6 +133,8 @@ add_fp_unittest(
123133
libc.src.stdio.sprintf
124134
libc.src.__support.FPUtil.fp_bits
125135
libc.src.__support.FPUtil.platform_defs
136+
COMPILE_OPTIONS
137+
${sprintf_test_copts}
126138
)
127139

128140
add_libc_unittest(

0 commit comments

Comments
 (0)