Skip to content

Commit 9e14f89

Browse files
committed
[Runtimes] Rework and remove default runtimes build
Summary: Currently the runtimes builds works by creating separate CMake projects that build the respetive runtime. Right now we have a separate handling for the 'default' target and manually specific runtimes via the `-DLLVM_RUNTIME_TARGETS` option. This patch changes the behavior to put all runtimes through the `LLVM_RUNTIME_TARGETS` pipeline. The old `"default"` argument is now a shorthand for `LLVM_DEFAULT_TARGET_TRIPLE` and corresponds to a sane default. In practical terms, this means the old `runtimes-bins` directory will now be `runtimes-x86_64-unknown-linux-gnu-bins` for the majority of users. We will not have `check-<name>-<triple>` targets, but I have made a top-level target that invokes all of the enabled targets check lines to keep this backward compatible. There's likely some edge cases I missed here, but it seems to work in the typical case for me. We'll see what CI thinks of this.
1 parent 8e17f80 commit 9e14f89

File tree

1 file changed

+91
-182
lines changed

1 file changed

+91
-182
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 91 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endforeach()
1818

1919
function(get_compiler_rt_path path)
2020
set(all_runtimes ${runtimes})
21-
foreach(name ${LLVM_RUNTIME_TARGETS})
21+
foreach(name ${runtime_targets})
2222
foreach(proj ${RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES})
2323
set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
2424
if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
@@ -42,6 +42,20 @@ if(NOT LLVM_BUILD_RUNTIMES)
4242
set(EXTRA_ARGS EXCLUDE_FROM_ALL)
4343
endif()
4444

45+
set(runtime_targets "")
46+
if(NOT LLVM_RUNTIME_TARGETS)
47+
list(APPEND runtime_targets "${LLVM_DEFAULT_TARGET_TRIPLE}")
48+
else()
49+
foreach(target ${LLVM_RUNTIME_TARGETS})
50+
if("${target}" STREQUAL "default")
51+
list(APPEND runtime_targets "${LLVM_DEFAULT_TARGET_TRIPLE}")
52+
else()
53+
list(APPEND runtime_targets "${target}")
54+
endif()
55+
endforeach()
56+
endif()
57+
list(REMOVE_DUPLICATES runtime_targets)
58+
4559
function(check_apple_target triple builtin_or_runtime)
4660
set(error "\
4761
compiler-rt for Darwin builds for all platforms and architectures using a \
@@ -77,33 +91,6 @@ macro(set_enable_per_target_runtime_dir)
7791
endif()
7892
endmacro()
7993

80-
function(builtin_default_target compiler_rt_path)
81-
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
82-
83-
set_enable_per_target_runtime_dir()
84-
85-
llvm_ExternalProject_Add(builtins
86-
${compiler_rt_path}/lib/builtins
87-
DEPENDS ${ARG_DEPENDS}
88-
CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
89-
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
90-
-DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
91-
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
92-
-DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}
93-
-DCMAKE_C_COMPILER_WORKS=ON
94-
-DCMAKE_CXX_COMPILER_WORKS=ON
95-
-DCMAKE_ASM_COMPILER_WORKS=ON
96-
${COMMON_CMAKE_ARGS}
97-
${BUILTINS_CMAKE_ARGS}
98-
PASSTHROUGH_PREFIXES COMPILER_RT
99-
DARWIN
100-
SANITIZER
101-
USE_TOOLCHAIN
102-
TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
103-
FOLDER "Compiler-RT"
104-
${EXTRA_ARGS})
105-
endfunction()
106-
10794
function(builtin_register_target compiler_rt_path name)
10895
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
10996

@@ -147,31 +134,35 @@ endfunction()
147134
# before the just-built compiler can pass the configuration tests.
148135
get_compiler_rt_path(compiler_rt_path)
149136
if(compiler_rt_path)
150-
# If the user did not specify the targets infer them from the runtimes.
151-
set(builtin_targets ${LLVM_BUILTIN_TARGETS})
152-
if(NOT builtin_targets)
137+
# If the user did not specify the targets infer them from the runtimes.
138+
set(builtin_targets "")
139+
if(NOT LLVM_BUILTIN_TARGETS)
153140
if("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
154-
list(APPEND builtin_targets "default")
141+
list(APPEND builtin_targets "${LLVM_DEFAULT_TARGET_TRIPLE}")
155142
endif()
156-
foreach(name ${LLVM_RUNTIME_TARGETS})
143+
foreach(name ${runtime_targets})
157144
if("compiler-rt" IN_LIST RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)
158145
list(APPEND builtin_targets ${name})
159146
endif()
160147
endforeach()
161-
endif()
162-
if("default" IN_LIST builtin_targets)
163-
builtin_default_target(${compiler_rt_path}
164-
DEPENDS clang-resource-headers)
165-
list(REMOVE_ITEM builtin_targets "default")
166148
else()
167-
add_custom_target(builtins)
168-
add_custom_target(install-builtins)
169-
add_custom_target(install-builtins-stripped)
170-
set_target_properties(
171-
builtins install-builtins install-builtins-stripped
172-
PROPERTIES FOLDER "Compiler-RT"
173-
)
149+
foreach(target ${LLVM_RUNTIME_TARGETS})
150+
if("${target}" STREQUAL "default")
151+
list(APPEND builtin_targets "${LLVM_DEFAULT_TARGET_TRIPLE}")
152+
else()
153+
list(APPEND builtin_targets "${target}")
154+
endif()
155+
endforeach()
174156
endif()
157+
list(REMOVE_DUPLICATES builtin_targets)
158+
159+
add_custom_target(builtins)
160+
add_custom_target(install-builtins)
161+
add_custom_target(install-builtins-stripped)
162+
set_target_properties(
163+
builtins install-builtins install-builtins-stripped
164+
PROPERTIES FOLDER "Compiler-RT"
165+
)
175166

176167
foreach(target ${builtin_targets})
177168
check_apple_target(${target} builtin)
@@ -226,74 +217,6 @@ foreach(entry ${runtimes})
226217
list(APPEND RUNTIME_NAMES ${name})
227218
endforeach()
228219

229-
function(runtime_default_target)
230-
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES;EXTRA_ARGS" ${ARGN})
231-
232-
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
233-
set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
234-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
235-
236-
foreach(runtime_name ${RUNTIME_NAMES})
237-
list(APPEND extra_targets
238-
${runtime_name}
239-
install-${runtime_name}
240-
install-${runtime_name}-stripped)
241-
if(LLVM_INCLUDE_TESTS)
242-
list(APPEND test_targets check-${runtime_name})
243-
endif()
244-
endforeach()
245-
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
246-
if(NOT ${component} IN_LIST SUB_COMPONENTS)
247-
list(APPEND extra_targets install-${component} install-${component}-stripped)
248-
endif()
249-
endforeach()
250-
if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
251-
# The target libomp-mod is a dependee of check-flang needed to run its
252-
# OpenMP tests
253-
list(APPEND extra_targets "libomp-mod")
254-
endif ()
255-
256-
if(LLVM_INCLUDE_TESTS)
257-
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)
259-
endif()
260-
261-
set_enable_per_target_runtime_dir()
262-
263-
llvm_ExternalProject_Add(runtimes
264-
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
265-
DEPENDS ${ARG_DEPENDS}
266-
# Builtins were built separately above
267-
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
268-
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
269-
-DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
270-
-DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
271-
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
272-
-DLLVM_BUILD_TOOLS=${LLVM_BUILD_TOOLS}
273-
-DCMAKE_C_COMPILER_WORKS=ON
274-
-DCMAKE_CXX_COMPILER_WORKS=ON
275-
-DCMAKE_Fortran_COMPILER_WORKS=ON
276-
-DCMAKE_ASM_COMPILER_WORKS=ON
277-
${COMMON_CMAKE_ARGS}
278-
${RUNTIMES_CMAKE_ARGS}
279-
${ARG_CMAKE_ARGS}
280-
PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
281-
LLVM_USE_LINKER
282-
CUDA CMAKE_CUDA # For runtimes that may look for the CUDA compiler and/or SDK (libc, offload, flang-rt)
283-
FFI # offload uses libffi
284-
FLANG_RUNTIME # Shared between Flang and Flang-RT
285-
${ARG_PREFIXES}
286-
EXTRA_TARGETS ${extra_targets}
287-
${test_targets}
288-
${SUB_COMPONENTS}
289-
${SUB_CHECK_TARGETS}
290-
${SUB_INSTALL_TARGETS}
291-
USE_TOOLCHAIN
292-
TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
293-
FOLDER "Runtimes"
294-
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
295-
endfunction()
296-
297220
# runtime_register_target(name)
298221
# Utility function to register external runtime target.
299222
function(runtime_register_target name)
@@ -318,8 +241,12 @@ function(runtime_register_target name)
318241
set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
319242
list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
320243
if(LLVM_INCLUDE_TESTS)
321-
set(check-${runtime_name}-${name} check-${runtime_name} )
244+
set(check-${runtime_name}-${name} check-${runtime_name})
322245
list(APPEND ${name}_test_targets check-${runtime_name}-${name})
246+
if(NOT TARGET check-${runtime_name})
247+
add_custom_target(check-${runtime_name})
248+
endif()
249+
add_dependencies(check-${runtime_name} check-${runtime_name}-${name})
323250
endif()
324251
endforeach()
325252

@@ -456,7 +383,7 @@ endfunction()
456383
if(runtimes)
457384
set(build_runtimes TRUE)
458385
endif()
459-
foreach(name ${LLVM_RUNTIME_TARGETS})
386+
foreach(name ${runtime_targets})
460387
if(RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)
461388
set(build_runtimes TRUE)
462389
endif()
@@ -566,82 +493,64 @@ if(build_runtimes)
566493
list(APPEND extra_args ENABLE_FORTRAN)
567494
endif ()
568495

569-
if(NOT LLVM_RUNTIME_TARGETS)
570-
runtime_default_target(
571-
DEPENDS ${builtins_dep} ${extra_deps}
572-
CMAKE_ARGS ${extra_cmake_args}
573-
PREFIXES ${prefixes}
574-
EXTRA_ARGS ${extra_args})
575-
set(test_targets check-runtimes)
576-
else()
577-
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
578-
runtime_default_target(
579-
DEPENDS ${builtins_dep} ${extra_deps}
580-
CMAKE_ARGS ${extra_cmake_args}
581-
PREFIXES ${prefixes}
582-
EXTRA_ARGS ${extra_args})
583-
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
584-
else()
585-
add_custom_target(runtimes)
586-
add_custom_target(runtimes-configure)
587-
add_custom_target(install-runtimes)
588-
add_custom_target(install-runtimes-stripped)
496+
add_custom_target(runtimes)
497+
add_custom_target(runtimes-configure)
498+
add_custom_target(install-runtimes)
499+
add_custom_target(install-runtimes-stripped)
500+
set_target_properties(
501+
runtimes runtimes-configure install-runtimes install-runtimes-stripped
502+
PROPERTIES FOLDER "Runtimes"
503+
)
504+
if(LLVM_INCLUDE_TESTS)
505+
add_custom_target(check-runtimes)
506+
add_custom_target(runtimes-test-depends)
507+
set_target_properties(
508+
check-runtimes runtimes-test-depends
509+
PROPERTIES FOLDER "Runtimes"
510+
)
511+
set(test_targets "")
512+
endif()
513+
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
514+
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
515+
add_custom_target(${component})
516+
add_custom_target(install-${component})
517+
add_custom_target(install-${component}-stripped)
589518
set_target_properties(
590-
runtimes runtimes-configure install-runtimes install-runtimes-stripped
591-
PROPERTIES FOLDER "Runtimes"
519+
${component} install-${component} install-${component}-stripped
520+
PROPERTIES FOLDER "${component}"
592521
)
593-
if(LLVM_INCLUDE_TESTS)
594-
add_custom_target(check-runtimes)
595-
add_custom_target(runtimes-test-depends)
596-
set_target_properties(
597-
check-runtimes runtimes-test-depends
598-
PROPERTIES FOLDER "Runtimes"
599-
)
600-
set(test_targets "")
601-
endif()
602-
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
603-
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
604-
add_custom_target(${component})
605-
add_custom_target(install-${component})
606-
add_custom_target(install-${component}-stripped)
607-
set_target_properties(
608-
${component} install-${component} install-${component}-stripped
609-
PROPERTIES FOLDER "${component}"
610-
)
611-
endforeach()
522+
endforeach()
523+
endif()
524+
525+
foreach(name ${runtime_targets})
526+
if(builtins_dep)
527+
if (LLVM_BUILTIN_TARGETS)
528+
set(builtins_dep_name "${builtins_dep}-${name}")
529+
else()
530+
set(builtins_dep_name ${builtins_dep})
612531
endif()
613532
endif()
614533

615-
foreach(name ${LLVM_RUNTIME_TARGETS})
616-
if(builtins_dep)
617-
if (LLVM_BUILTIN_TARGETS)
618-
set(builtins_dep_name "${builtins_dep}-${name}")
619-
else()
620-
set(builtins_dep_name ${builtins_dep})
621-
endif()
622-
endif()
534+
check_apple_target(${name} runtime)
623535

624-
check_apple_target(${name} runtime)
536+
runtime_register_target(${name}
537+
DEPENDS ${builtins_dep_name} ${extra_deps}
538+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args}
539+
EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})
540+
endforeach()
625541

626-
runtime_register_target(${name}
627-
DEPENDS ${builtins_dep_name} ${extra_deps}
628-
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args}
542+
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
543+
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
544+
runtime_register_target(${name}+${multilib}
545+
DEPENDS runtimes-${name}
546+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
547+
-DLLVM_RUNTIMES_PREFIX=${name}/
548+
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
549+
${extra_cmake_args}
550+
BASE_NAME ${name}
629551
EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})
630552
endforeach()
631-
632-
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
633-
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
634-
runtime_register_target(${name}+${multilib}
635-
DEPENDS runtimes-${name}
636-
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
637-
-DLLVM_RUNTIMES_PREFIX=${name}/
638-
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
639-
${extra_cmake_args}
640-
BASE_NAME ${name}
641-
EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})
642-
endforeach()
643-
endforeach()
644-
endif()
553+
endforeach()
645554

646555
if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
647556
# TODO: This is a hack needed because the libcxx headers are copied into the

0 commit comments

Comments
 (0)