diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -102,6 +102,18 @@ set(BUILTINS_${target}_CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") set(BUILTINS_${target}_CMAKE_EXE_LINKER_FLAG "-fuse-ld=lld" CACHE STRING "") + list(APPEND CRT_TARGETS "${target}") + set(CRT_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "") + set(CRT_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") + set(CRT_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "") + set(CRT_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "") + set(CRT_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING "") + set(CRT_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING "") + set(CRT_${target}_CMAKE_SYSROOT ${LINUX_${target}_SYSROOT} CACHE STRING "") + set(CRT_${target}_CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") + set(CRT_${target}_CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") + set(CRT_${target}_CMAKE_EXE_LINKER_FLAG "-fuse-ld=lld" CACHE STRING "") + # Set the per-target runtimes options. list(APPEND RUNTIME_TARGETS "${target}") set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "") @@ -251,6 +263,7 @@ endif() set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "") +set(LLVM_CRT_TARGETS "${CRT_TARGETS}" CACHE STRING "") set(LLVM_RUNTIME_TARGETS "${RUNTIME_TARGETS}" CACHE STRING "") # Setup toolchain. @@ -303,6 +316,7 @@ clang-tidy clangd find-all-symbols + crt builtins runtimes ${LLVM_TOOLCHAIN_TOOLS} diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -120,6 +120,62 @@ ${EXTRA_ARGS}) endfunction() +function(crt_default_target compiler_rt_path) + cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) + + set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON) + # AIX should fold 32-bit & 64-bit arch libraries into a single archive. + if (LLVM_TARGET_TRIPLE MATCHES "aix") + set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF) + endif() + + llvm_ExternalProject_Add(crt + ${compiler_rt_path}/lib/crt + DEPENDS ${ARG_DEPENDS} + CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} + -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} + -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE} + -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default} + -DCMAKE_C_COMPILER_WORKS=ON + ${COMMON_CMAKE_ARGS} + ${CRT_CMAKE_ARGS} + PASSTHROUGH_PREFIXES COMPILER_RT + USE_TOOLCHAIN + TARGET_TRIPLE ${LLVM_TARGET_TRIPLE} + ${EXTRA_ARGS}) +endfunction() + +function(crt_register_target compiler_rt_path target) + cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) + + check_apple_target(${target} crt) + + get_cmake_property(variableNames VARIABLES) + foreach(variableName ${variableNames}) + string(FIND "${variableName}" "CRT_${target}" out) + if("${out}" EQUAL 0) + string(REPLACE "CRT_${target}_" "" new_name ${variableName}) + string(REPLACE ";" "|" new_value "${${variableName}}") + list(APPEND ${target}_extra_args "-D${new_name}=${new_value}") + endif() + endforeach() + + llvm_ExternalProject_Add(crt-${target} + ${compiler_rt_path}/lib/crt + DEPENDS ${ARG_DEPENDS} + CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} + -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} + -DLLVM_DEFAULT_TARGET_TRIPLE=${target} + -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON + -DCMAKE_C_COMPILER_WORKS=ON + -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON + ${COMMON_CMAKE_ARGS} + ${${target}_extra_args} + USE_TOOLCHAIN + TARGET_TRIPLE ${target} + ${EXTRA_ARGS}) +endfunction() + # If compiler-rt is present we need to build the builtin libraries first. This # is required because the other runtimes need the builtin libraries present # before the just-built compiler can pass the configuration tests. @@ -148,12 +204,42 @@ add_dependencies(install-builtins-stripped install-builtins-${target}-stripped) endforeach() endif() - set(deps builtins) + list(APPEND deps builtins) # We don't need to depend on the builtins if we're building instrumented # because the next stage will use the same compiler used to build this stage. if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP) add_dependencies(clang-bootstrap-deps builtins) endif() + + if(NOT LLVM_CRT_TARGETS) + crt_default_target(${compiler_rt_path} + DEPENDS clang-resource-headers) + else() + if("default" IN_LIST LLVM_CRT_TARGETS) + crt_default_target(${compiler_rt_path} + DEPENDS clang-resource-headers) + list(REMOVE_ITEM LLVM_CRT_TARGETS "default") + else() + add_custom_target(crt) + add_custom_target(install-crt) + add_custom_target(install-crt-stripped) + endif() + + foreach(target ${LLVM_CRT_TARGETS}) + crt_register_target(${compiler_rt_path} ${target} + DEPENDS clang-resource-headers) + + add_dependencies(crt crt-${target}) + add_dependencies(install-crt install-crt-${target}) + add_dependencies(install-crt-stripped install-crt-${target}-stripped) + endforeach() + endif() + list(APPEND deps crt) + # We don't need to depend on the crt if we're building instrumented + # because the next stage will use the same compiler used to build this stage. + if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP) + add_dependencies(clang-bootstrap-deps crt) + endif() endif() # Create a list with the names of all the runtime projects in all uppercase and @@ -223,7 +309,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes DEPENDS ${ARG_DEPENDS} # Builtins were built separately above - CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off + CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF + -DCOMPILER_RT_BUILD_CRT=OFF -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE} -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED} @@ -332,7 +419,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes DEPENDS ${${name}_deps} # Builtins were built separately above - CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off + CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF + -DCOMPILER_RT_BUILD_CRT=OFF -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} -DLLVM_DEFAULT_TARGET_TRIPLE=${target} -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}