Skip to content

Commit

Permalink
[libc][NFC] split standalone_cpp into single headers
Browse files Browse the repository at this point in the history
Previously, the entire support/CPP folder was in one header library,
which meant that a lot of headers were included where they shouldn't be.
This patch splits each header into its own target, as well as adjusting
each place they were included to only include what is used.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D121237
  • Loading branch information
michaelrj-google committed Mar 8, 2022
1 parent 3f66882 commit bf0ded8
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 27 deletions.
2 changes: 1 addition & 1 deletion libc/fuzzing/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ add_libc_fuzzer(
libc.src.math.truncf
libc.src.math.truncl
libc.src.__support.FPUtil.fputil
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.type_traits
)

add_libc_fuzzer(
Expand Down
4 changes: 2 additions & 2 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_header_library(
.ctype_utils
libc.include.errno
libc.src.errno.errno
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.limits
)

add_header_library(
Expand All @@ -44,7 +44,7 @@ add_header_library(
.high_precision_decimal
libc.include.errno
libc.src.errno.errno
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.limits
libc.src.__support.FPUtil.fputil
)

Expand Down
45 changes: 43 additions & 2 deletions libc/src/__support/CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
# TODO(michaelrj): separate the standalone_cpp library into individual targets.
add_header_library(
standalone_cpp
array
HDRS
Array.h
)

add_header_library(
array_ref
HDRS
ArrayRef.h
)


add_header_library(
bit
HDRS
Bit.h
)


add_header_library(
bitset
HDRS
Bitset.h
)

add_header_library(
functional
HDRS
Functional.h
)

add_header_library(
limits
HDRS
Limits.h
)

add_header_library(
string_view
HDRS
StringView.h
)

add_header_library(
type_traits
HDRS
TypeTraits.h
)

add_header_library(
utility
HDRS
Utility.h
)

Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/FPUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#TODO(michaelrj): separate the fputil library into individual targets.
add_header_library(
fputil
HDRS
Expand All @@ -19,7 +20,8 @@ add_header_library(
libc.include.errno
libc.include.fenv
libc.src.__support.common
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.type_traits
libc.src.__support.CPP.bit
libc.src.errno.errno
)

Expand Down
4 changes: 2 additions & 2 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_header_library(
HDRS
string_utils.h
DEPENDS
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.bitset
)

add_entrypoint_object(
Expand Down Expand Up @@ -210,7 +210,7 @@ add_entrypoint_object(
HDRS
strspn.h
DEPENDS
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.bitset
)

add_entrypoint_object(
Expand Down
3 changes: 2 additions & 1 deletion libc/src/string/memory_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#TODO(michaelrj): split out the implementations from memory_utils
add_header_library(
memory_utils
HDRS
Expand All @@ -8,7 +9,7 @@ add_header_library(
memcpy_implementations.h
memset_implementations.h
DEPS
standalone_cpp
libc.src.__support.CPP.bit
)

add_header_library(
Expand Down
10 changes: 5 additions & 5 deletions libc/test/src/__support/CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_libc_unittest(
SRCS
bitset_test.cpp
DEPENDS
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.bitset
)

add_libc_unittest(
Expand All @@ -17,7 +17,7 @@ add_libc_unittest(
SRCS
stringview_test.cpp
DEPENDS
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.string_view
)

add_libc_unittest(
Expand All @@ -27,7 +27,7 @@ add_libc_unittest(
SRCS
limits_test.cpp
DEPENDS
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.limits
)

add_libc_unittest(
Expand All @@ -37,7 +37,7 @@ add_libc_unittest(
SRCS
arrayref_test.cpp
DEPENDS
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.array_ref
)

add_libc_unittest(
Expand All @@ -57,7 +57,7 @@ add_libc_unittest(
SRCS
integer_sequence_test.cpp
DEPENDS
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.utility
)

add_libc_unittest(
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ add_fp_unittest(
DEPENDS
libc.include.errno
libc.src.math.cosf
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.array
libc.src.__support.FPUtil.fputil
)

Expand Down Expand Up @@ -40,7 +40,7 @@ add_fp_unittest(
DEPENDS
libc.include.errno
libc.src.math.sinf
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.array
libc.src.__support.FPUtil.fputil
)

Expand Down Expand Up @@ -68,7 +68,7 @@ add_fp_unittest(
DEPENDS
libc.include.errno
libc.src.math.sincosf
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.array
libc.src.__support.FPUtil.fputil
)

Expand Down
2 changes: 0 additions & 2 deletions libc/test/src/math/exhaustive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ add_object_library(
exhaustive_test.h
SRCS
exhaustive_test.cpp
DEPENDS
libc.src.__support.CPP.standalone_cpp
)

add_fp_unittest(
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdlib._Exit
libc.src.stdlib.exit
libc.src.stdlib.atexit
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.array
libc.src.__support.CPP.utility
)

# add_libc_unittest(
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/string/memory_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ add_libc_unittest(
utils_test.cpp
DEPENDS
libc.src.string.memory_utils.memory_utils
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.array
libc.src.__support.CPP.array_ref
COMPILE_OPTIONS
${LIBC_COMPILE_OPTIONS_NATIVE}
-ffreestanding
Expand Down
4 changes: 3 additions & 1 deletion libc/test/utils/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ add_libc_unittest(
SRCS
testfilter_test.cpp
DEPENDS
libc.src.__support.CPP.standalone_cpp
# TODO(michaelrj): Remove this dependancy. It's only here because all unit
# tests must have at least one dependancy.
libc.src.__support.CPP.bit
)
8 changes: 7 additions & 1 deletion libc/utils/MPFRWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ if(LIBC_TESTS_CAN_USE_MPFR)
add_compile_options(
-O3
)
add_dependencies(libcMPFRWrapper libc.src.__support.CPP.standalone_cpp libc.src.__support.FPUtil.fputil LibcUnitTest)
add_dependencies(
libcMPFRWrapper
libc.src.__support.CPP.string_view
libc.src.__support.CPP.type_traits
libc.src.__support.FPUtil.fputil
LibcUnitTest
)
if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
Expand Down
7 changes: 3 additions & 4 deletions libc/utils/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_library(
LibcTest.h
)
target_include_directories(LibcUnitTest PUBLIC ${LIBC_SOURCE_DIR})
add_dependencies(LibcUnitTest libc.src.__support.CPP.standalone_cpp)
add_dependencies(LibcUnitTest libc.src.__support.CPP.type_traits)
target_link_libraries(LibcUnitTest PUBLIC libc_test_utils)

add_library(
Expand All @@ -14,7 +14,7 @@ add_library(
)

target_include_directories(LibcUnitTestMain PUBLIC ${LIBC_SOURCE_DIR})
add_dependencies(LibcUnitTestMain LibcUnitTest libc.src.__support.CPP.standalone_cpp)
add_dependencies(LibcUnitTestMain LibcUnitTest)
target_link_libraries(LibcUnitTestMain PUBLIC LibcUnitTest libc_test_utils)

add_library(
Expand All @@ -29,7 +29,6 @@ target_link_libraries(LibcFPTestHelpers LibcUnitTest)
add_dependencies(
LibcFPTestHelpers
LibcUnitTest
libc.src.__support.CPP.standalone_cpp
libc.src.__support.FPUtil.fputil
)

Expand All @@ -43,5 +42,5 @@ target_link_libraries(LibcMemoryHelpers LibcUnitTest)
add_dependencies(
LibcMemoryHelpers
LibcUnitTest
libc.src.__support.CPP.standalone_cpp
libc.src.__support.CPP.array_ref
)

0 comments on commit bf0ded8

Please sign in to comment.