Skip to content

Commit

Permalink
[libc] Fix printf config not working (#66834)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelrj-google committed Sep 19, 2023
1 parent 6af2674 commit d37496e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libc/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
endif()

add_subdirectory(printf_core)
add_subdirectory(scanf_core)

add_entrypoint_object(
fflush
SRCS
Expand Down Expand Up @@ -286,6 +283,9 @@ add_entrypoint_object(
${printf_copts}
)

add_subdirectory(printf_core)
add_subdirectory(scanf_core)

add_entrypoint_object(
ftell
SRCS
Expand Down
12 changes: 12 additions & 0 deletions libc/test/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ add_libc_unittest(
LibcMemoryHelpers
)

if(LIBC_CONF_PRINTF_DISABLE_FLOAT)
list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")
endif()
if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)
list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")
endif()
if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)
list(APPEND sprintf_test_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")
endif()

add_fp_unittest(
sprintf_test
UNIT_TEST_ONLY
Expand All @@ -123,6 +133,8 @@ add_fp_unittest(
libc.src.stdio.sprintf
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.platform_defs
COMPILE_OPTIONS
${sprintf_test_copts}
)

add_libc_unittest(
Expand Down

0 comments on commit d37496e

Please sign in to comment.