Skip to content

Commit 31051e0

Browse files
committed
[compiler-rt] Add check-builtins target for LLVM_ENABLE_RUNTIMES-based build
1 parent 78d6491 commit 31051e0

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ macro(darwin_add_builtin_library name suffix)
284284
${ARGN})
285285
set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}")
286286
add_library(${libname} STATIC ${LIB_SOURCES})
287+
file(WRITE "${CMAKE_BINARY_DIR}/${libname}.sources.txt" "${LIB_SOURCES}")
287288
if(DARWIN_${LIB_OS}_SYSROOT)
288289
set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT})
289290
endif()

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ else ()
976976
C_STANDARD 11
977977
CXX_STANDARD 17
978978
PARENT_TARGET builtins)
979+
file(WRITE "${CMAKE_BINARY_DIR}/clang_rt.builtins-${arch}.sources.txt" "${${arch}_SOURCES}")
979980
cmake_pop_check_state()
980981
endif ()
981982
endforeach ()

compiler-rt/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ endfunction()
6666
# Run sanitizer tests only if we're sure that clang would produce
6767
# working binaries.
6868
if(COMPILER_RT_CAN_EXECUTE_TESTS)
69-
if(COMPILER_RT_BUILD_BUILTINS)
69+
if(COMPILER_RT_BUILD_BUILTINS OR COMPILER_RT_FORCE_TEST_BUILTINS_DIR)
7070
add_subdirectory(builtins)
7171
endif()
7272
if(COMPILER_RT_BUILD_SANITIZERS)

compiler-rt/test/builtins/CMakeLists.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
set(BUILTINS_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
22

3-
set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} builtins)
3+
# If COMPILER_RT_FORCE_TEST_BUILTINS_DIR is set, the builtins
4+
# were already built and we are just going to test them.
5+
# NOTE: This is currently an LLVM-internal option which should
6+
# only be used by the LLVM_ENABLE_RUNTIMES build configured
7+
# in llvm/runtimes/CMakeLists.txt
8+
if(COMPILER_RT_FORCE_TEST_BUILTINS_DIR)
9+
set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
10+
else()
11+
set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} builtins)
12+
endif()
13+
414
set(BUILTINS_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/TestCases)
515

616
# Test cases.
@@ -79,10 +89,18 @@ foreach(arch ${BUILTIN_TEST_ARCH})
7989
else()
8090
set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins-${arch}")
8191
endif()
82-
if (NOT TARGET "${BUILTIN_LIB_TARGET_NAME}")
83-
message(FATAL_ERROR "Target ${BUILTIN_LIB_TARGET_NAME} does not exist")
92+
# Normally, we can just inspect the target directly to get the sources, but if
93+
# we are testing an externally-built builtins library, we expect
94+
# COMPILER_RT_FORCE_TEST_BUILTINS_DIR to be set and contain a file named
95+
# ${BUILTIN_LIB_TARGET_NAME}.sources.txt from the builtins build
96+
if(NOT COMPILER_RT_FORCE_TEST_BUILTINS_DIR)
97+
if (NOT TARGET "${BUILTIN_LIB_TARGET_NAME}")
98+
message(FATAL_ERROR "Target ${BUILTIN_LIB_TARGET_NAME} does not exist")
99+
endif()
100+
get_target_property(BUILTIN_LIB_SOURCES "${BUILTIN_LIB_TARGET_NAME}" SOURCES)
101+
else()
102+
file(READ "${COMPILER_RT_FORCE_TEST_BUILTINS_DIR}/${BUILTIN_LIB_TARGET_NAME}.sources.txt" BUILTIN_LIB_SOURCES)
84103
endif()
85-
get_target_property(BUILTIN_LIB_SOURCES "${BUILTIN_LIB_TARGET_NAME}" SOURCES)
86104
list(LENGTH BUILTIN_LIB_SOURCES BUILTIN_LIB_SOURCES_LENGTH)
87105
if (BUILTIN_LIB_SOURCES_LENGTH EQUAL 0)
88106
message(FATAL_ERROR "Failed to find source files for ${arch} builtin library")

llvm/runtimes/CMakeLists.txt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ function(runtime_default_target)
255255

256256
if(LLVM_INCLUDE_TESTS)
257257
set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-bins/lit.tests")
258-
list(APPEND test_targets runtimes-test-depends check-runtimes)
258+
list(APPEND test_targets runtimes-test-depends check-runtimes check-builtins)
259+
260+
# The default runtimes target can run tests the default builtins target
261+
list(APPEND ARG_CMAKE_ARGS "-DCOMPILER_RT_FORCE_TEST_BUILTINS_DIR=${LLVM_BINARY_DIR}/runtimes/builtins-bins/")
259262
endif()
260263

261264
set_enable_per_target_runtime_dir()
@@ -362,6 +365,15 @@ function(runtime_register_target name)
362365
list(APPEND ${name}_test_targets ${target}-${name})
363366
list(APPEND test_targets ${target}-${name})
364367
endforeach()
368+
369+
# If a builtins-${name} target exists, we'll test those builtins
370+
# with this runtimes build
371+
if(TARGET builtins-${name})
372+
list(APPEND ARG_CMAKE_ARGS "-DCOMPILER_RT_FORCE_TEST_BUILTINS_DIR=${LLVM_BINARY_DIR}/runtimes/builtins-${name}-bins/")
373+
set(check-builtins-${name} check-builtins)
374+
list(APPEND ${name}_test_targets check-builtins-${name})
375+
list(APPEND test_targets check-builtins-${name})
376+
endif()
365377
set(test_targets "${test_targets}" PARENT_SCOPE)
366378
endif()
367379

@@ -427,6 +439,9 @@ function(runtime_register_target name)
427439
if(LLVM_INCLUDE_TESTS)
428440
add_dependencies(check-runtimes check-runtimes-${name})
429441
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
442+
if(TARGET builtins-${name})
443+
add_dependencies(check-builtins check-builtins-${name})
444+
endif()
430445
endif()
431446
foreach(runtime_name ${runtime_names})
432447
if(NOT TARGET ${runtime_name})
@@ -602,6 +617,17 @@ if(build_runtimes)
602617
PROPERTIES FOLDER "Runtimes"
603618
)
604619
set(test_targets "")
620+
621+
# NOTE: Currently, the builtins tests are run with the runtimes build,
622+
# and the default runtimes target installs a check-builtins target
623+
# which forwards to the default builtins build. If the default runtimes
624+
# target is not used, we create a custom target which will depend on
625+
# each check-builtins-${name}.
626+
add_custom_target(check-builtins)
627+
set_target_properties(
628+
check-builtins
629+
PROPERTIES FOLDER "Compiler-RT"
630+
)
605631
endif()
606632
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
607633
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})

0 commit comments

Comments
 (0)