Skip to content

Commit 17df134

Browse files
committed
[LLVM] Update handling of default runtime targets
Summary: This patch changes the handling for `default` in the LLVM runtimes list. Currently it's some different path, but I think it's more straightforward if we have everything go through the same handling and just semantically replace `default` with the target LLVM is building for (current behavior). The one thing that this changes I'm aware of is that instead of something like `ninja check-libc` we now have `ninja check-libc-x86_64-unknown-linux-gnu`. This will almost surely break some bots with hard-coded check projects, so I'm thinking the easiest solution is to *always* define the `check-<runtime>` and every time we add a specific target, it adds itself as a dependency to the global `check-<runtime>`.
1 parent f12078e commit 17df134

File tree

1 file changed

+71
-137
lines changed

1 file changed

+71
-137
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 71 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function(get_compiler_rt_path path)
3636
endforeach()
3737
endfunction()
3838

39+
function(get_canonical_runtime_name name out)
40+
if("${name}" STREQUAL "default")
41+
set(${out} "${LLVM_TARGET_TRIPLE}" PARENT_SCOPE)
42+
else()
43+
set(${out} "${name}" PARENT_SCOPE)
44+
endif()
45+
endfunction()
46+
3947
include(LLVMExternalProjectUtils)
4048

4149
if(NOT LLVM_BUILD_RUNTIMES)
@@ -229,77 +237,9 @@ foreach(entry ${runtimes})
229237
list(APPEND RUNTIME_NAMES ${name})
230238
endforeach()
231239

232-
function(runtime_default_target)
233-
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES;EXTRA_ARGS" ${ARGN})
234-
235-
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
236-
set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
237-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
238-
239-
foreach(runtime_name ${RUNTIME_NAMES})
240-
list(APPEND extra_targets
241-
${runtime_name}
242-
install-${runtime_name}
243-
install-${runtime_name}-stripped)
244-
if(LLVM_INCLUDE_TESTS)
245-
list(APPEND test_targets check-${runtime_name})
246-
endif()
247-
endforeach()
248-
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
249-
if(NOT ${component} IN_LIST SUB_COMPONENTS)
250-
list(APPEND extra_targets install-${component} install-${component}-stripped)
251-
endif()
252-
endforeach()
253-
if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
254-
# The target libomp-mod is a dependee of check-flang needed to run its
255-
# OpenMP tests
256-
list(APPEND extra_targets "libomp-mod")
257-
endif ()
258-
259-
if(LLVM_INCLUDE_TESTS)
260-
set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-bins/lit.tests")
261-
list(APPEND test_targets runtimes-test-depends check-runtimes)
262-
endif()
263-
264-
set_enable_per_target_runtime_dir()
265-
266-
llvm_ExternalProject_Add(runtimes
267-
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
268-
DEPENDS ${ARG_DEPENDS}
269-
# Builtins were built separately above
270-
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
271-
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
272-
-DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
273-
-DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
274-
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
275-
-DLLVM_BUILD_TOOLS=${LLVM_BUILD_TOOLS}
276-
-DCMAKE_C_COMPILER_WORKS=ON
277-
-DCMAKE_CXX_COMPILER_WORKS=ON
278-
-DCMAKE_Fortran_COMPILER_WORKS=ON
279-
-DCMAKE_ASM_COMPILER_WORKS=ON
280-
${COMMON_CMAKE_ARGS}
281-
${RUNTIMES_CMAKE_ARGS}
282-
${ARG_CMAKE_ARGS}
283-
PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
284-
LLVM_USE_LINKER
285-
CUDA CMAKE_CUDA # For runtimes that may look for the CUDA compiler and/or SDK (libc, offload, flang-rt)
286-
FFI # offload uses libffi
287-
FLANG_RUNTIME # Shared between Flang and Flang-RT
288-
${ARG_PREFIXES}
289-
EXTRA_TARGETS ${extra_targets}
290-
${test_targets}
291-
${SUB_COMPONENTS}
292-
${SUB_CHECK_TARGETS}
293-
${SUB_INSTALL_TARGETS}
294-
USE_TOOLCHAIN
295-
TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
296-
FOLDER "Runtimes"
297-
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
298-
endfunction()
299-
300-
# runtime_register_target(name)
240+
# runtime_register_target(name target)
301241
# Utility function to register external runtime target.
302-
function(runtime_register_target name)
242+
function(runtime_register_target name target)
303243
cmake_parse_arguments(ARG "" "BASE_NAME" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
304244
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
305245
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
@@ -320,6 +260,12 @@ function(runtime_register_target name)
320260
set(install-${runtime_name}-${name} install-${runtime_name})
321261
set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
322262
list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
263+
if(${runtime_name} STREQUAL "openmp")
264+
# The target libomp-mod is a dependee of check-flang needed to run it
265+
# OpenMP tests
266+
list(APPEND ${name}_extra_targets "libomp-mod")
267+
endif()
268+
323269
if(LLVM_INCLUDE_TESTS)
324270
set(check-${runtime_name}-${name} check-${runtime_name} )
325271
list(APPEND ${name}_test_targets check-${runtime_name}-${name})
@@ -414,7 +360,7 @@ function(runtime_register_target name)
414360
-DCMAKE_Fortran_COMPILER_WORKS=ON
415361
-DCMAKE_ASM_COMPILER_WORKS=ON
416362
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
417-
-DLLVM_RUNTIMES_TARGET=${name}
363+
-DLLVM_RUNTIMES_TARGET=${target}
418364
${COMMON_CMAKE_ARGS}
419365
${${name}_extra_args}
420366
EXTRA_TARGETS ${${name}_extra_targets}
@@ -549,81 +495,69 @@ if(build_runtimes)
549495
endif ()
550496

551497
if(NOT LLVM_RUNTIME_TARGETS)
552-
runtime_default_target(
553-
DEPENDS ${builtins_dep} ${extra_deps}
554-
CMAKE_ARGS ${extra_cmake_args}
555-
PREFIXES ${prefixes}
556-
EXTRA_ARGS ${extra_args})
557-
set(test_targets check-runtimes)
558-
else()
559-
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
560-
runtime_default_target(
561-
DEPENDS ${builtins_dep} ${extra_deps}
562-
CMAKE_ARGS ${extra_cmake_args}
563-
PREFIXES ${prefixes}
564-
EXTRA_ARGS ${extra_args})
565-
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
566-
else()
567-
add_custom_target(runtimes)
568-
add_custom_target(runtimes-configure)
569-
add_custom_target(install-runtimes)
570-
add_custom_target(install-runtimes-stripped)
498+
set(LLVM_RUNTIME_TARGETS "default")
499+
endif()
500+
501+
add_custom_target(runtimes)
502+
add_custom_target(runtimes-configure)
503+
add_custom_target(install-runtimes)
504+
add_custom_target(install-runtimes-stripped)
505+
set_target_properties(
506+
runtimes runtimes-configure install-runtimes install-runtimes-stripped
507+
PROPERTIES FOLDER "Runtimes"
508+
)
509+
if(LLVM_INCLUDE_TESTS)
510+
add_custom_target(check-runtimes)
511+
add_custom_target(runtimes-test-depends)
512+
set_target_properties(
513+
check-runtimes runtimes-test-depends
514+
PROPERTIES FOLDER "Runtimes"
515+
)
516+
set(test_targets "")
517+
endif()
518+
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
519+
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
520+
add_custom_target(${component})
521+
add_custom_target(install-${component})
522+
add_custom_target(install-${component}-stripped)
571523
set_target_properties(
572-
runtimes runtimes-configure install-runtimes install-runtimes-stripped
573-
PROPERTIES FOLDER "Runtimes"
524+
${component} install-${component} install-${component}-stripped
525+
PROPERTIES FOLDER "${component}"
574526
)
575-
if(LLVM_INCLUDE_TESTS)
576-
add_custom_target(check-runtimes)
577-
add_custom_target(runtimes-test-depends)
578-
set_target_properties(
579-
check-runtimes runtimes-test-depends
580-
PROPERTIES FOLDER "Runtimes"
581-
)
582-
set(test_targets "")
583-
endif()
584-
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
585-
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
586-
add_custom_target(${component})
587-
add_custom_target(install-${component})
588-
add_custom_target(install-${component}-stripped)
589-
set_target_properties(
590-
${component} install-${component} install-${component}-stripped
591-
PROPERTIES FOLDER "${component}"
592-
)
593-
endforeach()
527+
endforeach()
528+
endif()
529+
530+
foreach(name ${LLVM_RUNTIME_TARGETS})
531+
get_canonical_runtime_name("${name}" name)
532+
if(builtins_dep)
533+
if (LLVM_BUILTIN_TARGETS)
534+
set(builtins_dep_name "${builtins_dep}-${name}")
535+
else()
536+
set(builtins_dep_name ${builtins_dep})
594537
endif()
595538
endif()
596539

597-
foreach(name ${LLVM_RUNTIME_TARGETS})
598-
if(builtins_dep)
599-
if (LLVM_BUILTIN_TARGETS)
600-
set(builtins_dep_name "${builtins_dep}-${name}")
601-
else()
602-
set(builtins_dep_name ${builtins_dep})
603-
endif()
604-
endif()
540+
check_apple_target(${name} runtime)
605541

606-
check_apple_target(${name} runtime)
542+
runtime_register_target(${name} ${name}
543+
DEPENDS ${builtins_dep_name} ${extra_deps}
544+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args}
545+
EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})
546+
endforeach()
607547

608-
runtime_register_target(${name}
609-
DEPENDS ${builtins_dep_name} ${extra_deps}
610-
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args}
548+
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
549+
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
550+
get_canonical_runtime_name("${name}" name)
551+
runtime_register_target(${name}+${multilib} ${name}
552+
DEPENDS runtimes-${name}
553+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
554+
-DLLVM_RUNTIMES_PREFIX=${name}/
555+
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
556+
${extra_cmake_args}
557+
BASE_NAME ${name}
611558
EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})
612559
endforeach()
613-
614-
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
615-
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
616-
runtime_register_target(${name}+${multilib}
617-
DEPENDS runtimes-${name}
618-
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
619-
-DLLVM_RUNTIMES_PREFIX=${name}/
620-
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
621-
${extra_cmake_args}
622-
BASE_NAME ${name}
623-
EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})
624-
endforeach()
625-
endforeach()
626-
endif()
560+
endforeach()
627561

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

0 commit comments

Comments
 (0)