Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ macro(darwin_add_builtin_library name suffix)
${ARGN})
set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}")
add_library(${libname} STATIC ${LIB_SOURCES})
file(WRITE "${CMAKE_BINARY_DIR}/${libname}.sources.txt" "${LIB_SOURCES}")
if(DARWIN_${LIB_OS}_SYSROOT)
set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT})
endif()
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ else ()
check_c_source_compiles("__bf16 foo(__bf16 x) { return x; }
int main(void) { return 0; }"
COMPILER_RT_HAS_${arch}_BFLOAT16)
append_list_if(COMPILER_RT_HAS_${arch}_BFLOAT16 -DCOMPILER_RT_HAS_BFLOAT16 BUILTIN_CFLAGS_${arch})
# Build BF16 files only when "__bf16" is available.
if(COMPILER_RT_HAS_${arch}_BFLOAT16)
list(APPEND ${arch}_SOURCES ${BF16_SOURCES})
Expand Down Expand Up @@ -976,6 +977,7 @@ else ()
C_STANDARD 11
CXX_STANDARD 17
PARENT_TARGET builtins)
file(WRITE "${CMAKE_BINARY_DIR}/clang_rt.builtins-${arch}.sources.txt" "${${arch}_SOURCES}")
cmake_pop_check_state()
endif ()
endforeach ()
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ endfunction()
# Run sanitizer tests only if we're sure that clang would produce
# working binaries.
if(COMPILER_RT_CAN_EXECUTE_TESTS)
if(COMPILER_RT_BUILD_BUILTINS)
if(COMPILER_RT_BUILD_BUILTINS OR COMPILER_RT_FORCE_TEST_BUILTINS_DIR)
add_subdirectory(builtins)
endif()
if(COMPILER_RT_BUILD_SANITIZERS)
Expand Down
26 changes: 22 additions & 4 deletions compiler-rt/test/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
set(BUILTINS_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} builtins)
# If COMPILER_RT_FORCE_TEST_BUILTINS_DIR is set, the builtins
# were already built and we are just going to test them.
# NOTE: This is currently an LLVM-internal option which should
# only be used by the LLVM_ENABLE_RUNTIMES build configured
# in llvm/runtimes/CMakeLists.txt
if(COMPILER_RT_FORCE_TEST_BUILTINS_DIR)
set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
else()
set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} builtins)
endif()

set(BUILTINS_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/TestCases)

# Test cases.
Expand Down Expand Up @@ -79,10 +89,18 @@ foreach(arch ${BUILTIN_TEST_ARCH})
else()
set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins-${arch}")
endif()
if (NOT TARGET "${BUILTIN_LIB_TARGET_NAME}")
message(FATAL_ERROR "Target ${BUILTIN_LIB_TARGET_NAME} does not exist")
# Normally, we can just inspect the target directly to get the sources, but if
# we are testing an externally-built builtins library, we expect
# COMPILER_RT_FORCE_TEST_BUILTINS_DIR to be set and contain a file named
# ${BUILTIN_LIB_TARGET_NAME}.sources.txt from the builtins build
if(NOT COMPILER_RT_FORCE_TEST_BUILTINS_DIR)
if (NOT TARGET "${BUILTIN_LIB_TARGET_NAME}")
message(FATAL_ERROR "Target ${BUILTIN_LIB_TARGET_NAME} does not exist")
endif()
get_target_property(BUILTIN_LIB_SOURCES "${BUILTIN_LIB_TARGET_NAME}" SOURCES)
else()
file(READ "${COMPILER_RT_FORCE_TEST_BUILTINS_DIR}/${BUILTIN_LIB_TARGET_NAME}.sources.txt" BUILTIN_LIB_SOURCES)
endif()
get_target_property(BUILTIN_LIB_SOURCES "${BUILTIN_LIB_TARGET_NAME}" SOURCES)
list(LENGTH BUILTIN_LIB_SOURCES BUILTIN_LIB_SOURCES_LENGTH)
if (BUILTIN_LIB_SOURCES_LENGTH EQUAL 0)
message(FATAL_ERROR "Failed to find source files for ${arch} builtin library")
Expand Down
28 changes: 27 additions & 1 deletion llvm/runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ function(runtime_default_target)

if(LLVM_INCLUDE_TESTS)
set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-bins/lit.tests")
list(APPEND test_targets runtimes-test-depends check-runtimes)
list(APPEND test_targets runtimes-test-depends check-runtimes check-builtins)

# The default runtimes target can run tests the default builtins target
list(APPEND ARG_CMAKE_ARGS "-DCOMPILER_RT_FORCE_TEST_BUILTINS_DIR=${LLVM_BINARY_DIR}/runtimes/builtins-bins/")
endif()

set_enable_per_target_runtime_dir()
Expand Down Expand Up @@ -362,6 +365,15 @@ function(runtime_register_target name)
list(APPEND ${name}_test_targets ${target}-${name})
list(APPEND test_targets ${target}-${name})
endforeach()

# If a builtins-${name} target exists, we'll test those builtins
# with this runtimes build
if(TARGET builtins-${name})
list(APPEND ARG_CMAKE_ARGS "-DCOMPILER_RT_FORCE_TEST_BUILTINS_DIR=${LLVM_BINARY_DIR}/runtimes/builtins-${name}-bins/")
set(check-builtins-${name} check-builtins)
list(APPEND ${name}_test_targets check-builtins-${name})
list(APPEND test_targets check-builtins-${name})
endif()
set(test_targets "${test_targets}" PARENT_SCOPE)
endif()

Expand Down Expand Up @@ -427,6 +439,9 @@ function(runtime_register_target name)
if(LLVM_INCLUDE_TESTS)
add_dependencies(check-runtimes check-runtimes-${name})
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
if(TARGET builtins-${name})
add_dependencies(check-builtins check-builtins-${name})
endif()
endif()
foreach(runtime_name ${runtime_names})
if(NOT TARGET ${runtime_name})
Expand Down Expand Up @@ -602,6 +617,17 @@ if(build_runtimes)
PROPERTIES FOLDER "Runtimes"
)
set(test_targets "")

# NOTE: Currently, the builtins tests are run with the runtimes build,
# and the default runtimes target installs a check-builtins target
# which forwards to the default builtins build. If the default runtimes
# target is not used, we create a custom target which will depend on
# each check-builtins-${name}.
add_custom_target(check-builtins)
set_target_properties(
check-builtins
PROPERTIES FOLDER "Compiler-RT"
)
endif()
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
Expand Down
Loading