@@ -8,3 +8,91 @@ add_subdirectory(string)
88add_subdirectory (sys)
99add_subdirectory (threads)
1010add_subdirectory (unistd)
11+
12+ include ("${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_MACHINE} /entrypoints.txt" )
13+ include ("${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /${LIBC_TARGET_MACHINE} /headers.txt" )
14+
15+ set (public_test ${CMAKE_CURRENT_BINARY_DIR} /public_integration_test.cpp)
16+
17+ set (entrypoints_name_list "" )
18+ foreach (entry IN LISTS LIBC_ENTRYPOINTS LIBM_ENTRYPOINTS)
19+ get_target_property (entry_name ${entry} "ENTRYPOINT_NAME" )
20+ list (APPEND entrypoints_name_list ${entry_name} )
21+ endforeach ()
22+
23+ # TODO: Remove these when they are added to the TableGen.
24+ list (REMOVE_ITEM entrypoints_name_list "__assert_fail" "__errno_location" )
25+ list (TRANSFORM entrypoints_name_list PREPEND "-e=" )
26+
27+ # Generate integration test souce code.
28+ add_custom_command (
29+ OUTPUT ${public_test}
30+ COMMAND $<TARGET_FILE:libc-prototype-testgen> -o ${public_test}
31+ ${entrypoints_name_list}
32+ -I ${LIBC_SOURCE_DIR}
33+ ${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /api.td
34+
35+ DEPENDS ${LIBC_SOURCE_DIR} /config/${LIBC_TARGET_OS} /api.td
36+ libc-prototype-testgen ${PUBLIC_HEADERS}
37+ llvmlibc llvmlibm
38+ )
39+
40+ add_executable (
41+ public_integration_test
42+ EXCLUDE_FROM_ALL
43+ ${public_test}
44+ )
45+ # Blank out default include directories to prevent accidentally including
46+ # system headers or our own internal headers.
47+ set_target_properties (
48+ public_integration_test
49+ PROPERTIES
50+ INCLUDE_DIRECTORIES ""
51+ )
52+ # Only include we need is the include for cpp::IsSame and our generated
53+ # public headers.
54+ target_include_directories (
55+ public_integration_test BEFORE
56+ PRIVATE
57+ "${LIBC_SOURCE_DIR} /utils/CPP"
58+ "${LIBC_BUILD_DIR} /include"
59+ )
60+ target_compile_options (
61+ public_integration_test
62+ PRIVATE
63+ -ffreestanding
64+ )
65+ target_link_options (
66+ public_integration_test
67+ PRIVATE "-nostdlib"
68+ )
69+ set (library_files)
70+ foreach (library_name IN LISTS "llvmlibc;llvmlibm" )
71+ get_target_property (library_file ${library_name} "LIBRARY_FILE" )
72+ list (APPEND library_files ${library_file} )
73+ endforeach ()
74+
75+ if (COMPILER_RESOURCE_DIR AND LLVM_LIBC_ENABLE_LINTING)
76+ add_custom_target (
77+ public_integration_test-tidy
78+ VERBATIM
79+ COMMAND $<TARGET_FILE:clang-tidy> --system -headers
80+ --checks=-*,llvmlibc-restrict-system -libc-headers
81+ "--extra-arg=-resource-dir=${COMPILER_RESOURCE_DIR} "
82+ --header-filter =.*
83+ --warnings-as-errors=llvmlibc-*
84+ "-config={CheckOptions: [{key: llvmlibc-restrict-system-libc-headers.Includes, value: '-*, linux/*, asm/*.h, asm-generic/*.h'}]}"
85+ --quiet
86+ -p ${PROJECT_BINARY_DIR}
87+ ${public_test}
88+ DEPENDS
89+ clang-tidy ${public_test}
90+ )
91+ add_dependencies (check-libc public_integration_test-tidy)
92+ endif ()
93+
94+ target_link_libraries (public_integration_test
95+ PRIVATE
96+ ${library_files}
97+ )
98+ add_dependencies (check-libc public_integration_test)
0 commit comments