Skip to content

Commit 61be4d9

Browse files
committed
[CMake][NFC] Introduce component targets for proper dependency tracking
This commit introduces a CMake target for each component, adds install targets for them, and switches build-script-impl to use the target `install-components` for installation. Each of the targets for each component depends on each of the individual targets and outputs that are associated with the corresponding swift-component. This is equivalent to what already exists, because right now install rules are only generated for components that we want to install. Therefore, this commit should be an NFC. This is a resubmission (with modifications) of an earlier change. I originally committed this but there were problems with some installation rules.
1 parent daa74c6 commit 61be4d9

File tree

17 files changed

+61
-12
lines changed

17 files changed

+61
-12
lines changed

Diff for: CMakeLists.txt

+13-10
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,18 @@ include(CMakePushCheckState)
499499

500500
print_versions()
501501

502+
include(SwiftSharedCMakeConfig)
503+
504+
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
505+
# functionality.
506+
# Support building Swift as a standalone project, using LLVM as an
507+
# external library.
508+
if(SWIFT_BUILT_STANDALONE)
509+
swift_common_standalone_build_config(SWIFT)
510+
else()
511+
swift_common_unified_build_config(SWIFT)
512+
endif()
513+
502514
include(SwiftComponents)
503515
include(SwiftHandleGybSources)
504516
include(SwiftSetIfArchBitness)
@@ -527,16 +539,6 @@ if(NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
527539
OUTPUT_STRIP_TRAILING_WHITESPACE)
528540
endif()
529541

530-
include(SwiftSharedCMakeConfig)
531-
532-
# Support building Swift as a standalone project, using LLVM as an
533-
# external library.
534-
if(SWIFT_BUILT_STANDALONE)
535-
swift_common_standalone_build_config(SWIFT)
536-
else()
537-
swift_common_unified_build_config(SWIFT)
538-
endif()
539-
540542
get_filename_component(SWIFT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
541543
set(SWIFT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
542544
set(SWIFT_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@@ -1051,6 +1053,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
10511053
else()
10521054
set(SOURCEKIT_RUNTIME_DIR lib)
10531055
endif()
1056+
add_dependencies(sourcekit-inproc BlocksRuntime dispatch)
10541057
swift_install_in_component(FILES
10551058
$<TARGET_FILE:dispatch>
10561059
$<TARGET_FILE:BlocksRuntime>

Diff for: apinotes/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_custom_target("copy_apinotes" ALL
2626
COMMENT "Copying API notes to ${output_dir}"
2727
SOURCES "${sources}")
2828

29+
add_dependencies(compiler copy_apinotes)
2930
swift_install_in_component(DIRECTORY "${output_dir}"
3031
DESTINATION "lib/swift/"
3132
COMPONENT compiler)

Diff for: cmake/modules/AddSwift.cmake

+8
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@ function(add_swift_host_library name)
15061506
INSTALL_IN_COMPONENT "dev"
15071507
)
15081508

1509+
add_dependencies(dev ${name})
15091510
if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
15101511
swift_install_in_component(TARGETS ${name}
15111512
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT dev
@@ -2117,6 +2118,7 @@ function(add_swift_target_library name)
21172118
endif()
21182119

21192120
if(sdk STREQUAL WINDOWS AND CMAKE_SYSTEM_NAME STREQUAL Windows)
2121+
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH})
21202122
swift_install_in_component(TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
21212123
RUNTIME
21222124
DESTINATION "bin"
@@ -2129,6 +2131,9 @@ function(add_swift_target_library name)
21292131
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
21302132
PERMISSIONS ${file_permissions})
21312133
else()
2134+
# NOTE: ${UNIVERSAL_LIBRARY_NAME} is the output associated with the target
2135+
# ${lipo_target}
2136+
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${lipo_target})
21322137
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
21332138
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
21342139
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
@@ -2139,6 +2144,7 @@ function(add_swift_target_library name)
21392144
foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES})
21402145
if(TARGET ${name}-windows-${arch}_IMPLIB)
21412146
get_target_property(import_library ${name}-windows-${arch}_IMPLIB IMPORTED_LOCATION)
2147+
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${name}-windows-${arch}_IMPLIB)
21422148
swift_install_in_component(FILES ${import_library}
21432149
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
21442150
COMPONENT ${SWIFTLIB_INSTALL_IN_COMPONENT}
@@ -2205,6 +2211,7 @@ function(add_swift_target_library name)
22052211
OUTPUT
22062212
"${UNIVERSAL_LIBRARY_NAME}"
22072213
${THIN_INPUT_TARGETS_STATIC})
2214+
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${lipo_target_static})
22082215
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
22092216
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${install_subdir}/${resource_dir_sdk_subdir}"
22102217
PERMISSIONS
@@ -2406,6 +2413,7 @@ function(add_swift_host_tool executable)
24062413
ARCHITECTURE ${SWIFT_HOST_VARIANT_ARCH}
24072414
${ASHT_UNPARSED_ARGUMENTS})
24082415

2416+
add_dependencies(${ASHT_SWIFT_COMPONENT} ${executable})
24092417
swift_install_in_component(TARGETS ${executable}
24102418
RUNTIME
24112419
DESTINATION bin

Diff for: cmake/modules/SwiftComponents.cmake

+19-1
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,23 @@ macro(swift_configure_components)
9292
"A semicolon-separated list of components to install from the set ${_SWIFT_DEFINED_COMPONENTS}")
9393

9494
foreach(component ${_SWIFT_DEFINED_COMPONENTS})
95+
add_custom_target(${component})
96+
add_llvm_install_targets(install-${component}
97+
DEPENDS ${component}
98+
COMPONENT ${component})
99+
95100
string(TOUPPER "${component}" var_name_piece)
96101
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
97102
set(SWIFT_INSTALL_${var_name_piece} FALSE)
98103
endforeach()
99104

105+
# NOTE: never_install is a dummy component to indicate something should not
106+
# be installed. We explicitly do not add an install target for this.
107+
add_custom_target(never_install)
108+
109+
add_custom_target(swift-components)
110+
add_custom_target(install-swift-components)
111+
100112
foreach(component ${SWIFT_INSTALL_COMPONENTS})
101113
if(NOT "${component}" IN_LIST _SWIFT_DEFINED_COMPONENTS)
102114
message(FATAL_ERROR "unknown install component: ${component}")
@@ -106,6 +118,8 @@ macro(swift_configure_components)
106118
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
107119
if(NOT SWIFT_INSTALL_EXCLUDE_${var_name_piece})
108120
set(SWIFT_INSTALL_${var_name_piece} TRUE)
121+
add_dependencies(swift-components ${component})
122+
add_dependencies(install-swift-components install-${component})
109123
endif()
110124
endforeach()
111125
endmacro()
@@ -173,6 +187,10 @@ function(swift_install_symlink_component component)
173187
precondition(INSTALL_SYMLINK
174188
MESSAGE "LLVMInstallSymlink script must be available.")
175189

190+
# Create the directory if it doesn't exist. It will fail to create a symlink
191+
# otherwise.
192+
install(DIRECTORY DESTINATION "${ARG_DESTINATION}" COMPONENT ${component})
176193
install(SCRIPT ${INSTALL_SYMLINK}
177-
CODE "install_symlink(${ARG_LINK_NAME} ${ARG_TARGET} ${ARG_DESTINATION})")
194+
CODE "install_symlink(${ARG_LINK_NAME} ${ARG_TARGET} ${ARG_DESTINATION})"
195+
COMPONENT ${component})
178196
endfunction()

Diff for: cmake/modules/SwiftManpage.cmake

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function(manpage)
2727
"${CMAKE_CURRENT_BINARY_DIR}/${MP_MAN_FILE_BASENAME}.${MP_MAN_SECTION}")
2828

2929
add_custom_command_target(
30-
unused_var
30+
manpage_target
3131
COMMAND
3232
"${POD2MAN}" "--section" "${MP_MAN_SECTION}"
3333
"--center" "${MP_PAGE_HEADER}" "--release=\"swift ${SWIFT_VERSION}\""
@@ -38,6 +38,7 @@ function(manpage)
3838
DEPENDS "${MP_SOURCE}"
3939
ALL)
4040

41+
add_dependencies(${MP_INSTALL_IN_COMPONENT} ${manpage_target})
4142
swift_install_in_component(FILES "${output_file_name}"
4243
DESTINATION "share/man/man${MP_MAN_SECTION}"
4344
COMPONENT "${MP_INSTALL_IN_COMPONENT}")

Diff for: docs/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ if (DOXYGEN_FOUND)
6868
add_dependencies(doxygen doxygen-swift)
6969
endif()
7070

71+
add_dependencies(dev doxygen-swift)
7172
swift_install_in_component(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
7273
DESTINATION "docs/html"
7374
COMPONENT dev)

Diff for: lib/Driver/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ if(SWIFT_BUILD_STATIC_STDLIB)
6262
endif()
6363
endforeach()
6464
add_custom_target(swift_static_lnk_args ALL DEPENDS ${static_stdlib_lnk_file_list})
65+
add_dependencies(stdlib swift_static_lnk_args)
6566
endif()

Diff for: lib/SwiftDemangle/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ target_compile_definitions(swiftDemangle PRIVATE
66
target_link_libraries(swiftDemangle PRIVATE
77
swiftDemangling)
88

9+
add_dependencies(compiler swiftDemangle)
910
swift_install_in_component(TARGETS swiftDemangle
1011
LIBRARY
1112
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"

Diff for: stdlib/public/Platform/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,4 @@ foreach(sdk ${SWIFT_SDKS})
125125
endforeach()
126126
add_custom_target(glibc_modulemap DEPENDS ${glibc_modulemap_target_list})
127127
set_property(TARGET glibc_modulemap PROPERTY FOLDER "Miscellaneous")
128+
add_dependencies(sdk-overlay glibc_modulemap)

Diff for: stdlib/public/runtime/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
111111
"${LibraryLocation}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
112112
DEPENDS
113113
${FragileSupportLibrary})
114+
add_dependencies(stdlib ${FragileSupportLibrary})
114115
swift_install_in_component(FILES $<TARGET_FILE:${FragileSupportLibrary}>
115116
DESTINATION "lib/swift_static/${lowercase_sdk}/${arch}"
116117
COMPONENT stdlib)
@@ -125,6 +126,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
125126
"${LibraryLocationPrimary}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
126127
DEPENDS
127128
${FragileSupportLibraryPrimary})
129+
add_dependencies(stdlib ${FragileSupportLibraryPrimary})
128130
swift_install_in_component(FILES $<TARGET_FILE:${FragileSupportLibraryPrimary}>
129131
DESTINATION "lib/swift_static/${lowercase_sdk}"
130132
COMPONENT stdlib)
@@ -150,6 +152,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
150152
add_dependencies(static_binary_magic ${swift_image_inspection_${arch}_static})
151153
endforeach()
152154
add_dependencies(static_binary_magic ${swift_image_inspection_static_primary_arch})
155+
add_dependencies(stdlib static_binary_magic)
153156

154157
add_swift_target_library(swiftImageInspectionSharedObject OBJECT_LIBRARY
155158
ImageInspectionELF.cpp
@@ -250,6 +253,7 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
250253
add_custom_target(swiftImageRegistration-${arch_suffix}
251254
ALL DEPENDS
252255
${swiftImageRegistration-${arch_suffix}})
256+
add_dependencies(stdlib swift-stdlib-${arch_suffix} swiftImageRegistration-${arch_suffix})
253257
endif()
254258
endforeach()
255259
endforeach()

Diff for: tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ macro(add_sourcekit_library name)
188188
set(SOURCEKITLIB_INSTALL_IN_COMPONENT dev)
189189
endif()
190190
endif()
191+
add_dependencies(${SOURCEKITLIB_INSTALL_IN_COMPONENT} ${name})
191192
swift_install_in_component(TARGETS ${name}
192193
LIBRARY
193194
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
@@ -345,6 +346,7 @@ macro(add_sourcekit_framework name)
345346
MACOSX_FRAMEWORK_SHORT_VERSION_STRING "1.0"
346347
MACOSX_FRAMEWORK_BUNDLE_VERSION "${SOURCEKIT_VERSION_STRING}"
347348
PUBLIC_HEADER "${headers}")
349+
add_dependencies(${SOURCEKITFW_INSTALL_IN_COMPONENT} ${name})
348350
swift_install_in_component(TARGETS ${name}
349351
FRAMEWORK
350352
DESTINATION lib${LLVM_LIBDIR_SUFFIX}

Diff for: tools/SourceKit/tools/complete-test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if(SWIFT_ANALYZE_CODE_COVERAGE)
2424
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
2525
endif()
2626

27+
add_dependencies(tools complete-test)
2728
swift_install_in_component(TARGETS complete-test
2829
RUNTIME
2930
DESTINATION bin

Diff for: tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if(HAVE_UNICODE_LIBEDIT)
2727
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
2828
endif()
2929

30+
add_dependencies(tools sourcekitd-repl)
3031
swift_install_in_component(TARGETS sourcekitd-repl
3132
RUNTIME
3233
DESTINATION bin

Diff for: tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if(SWIFT_ANALYZE_CODE_COVERAGE)
3232
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
3333
endif()
3434

35+
add_dependencies(tools sourcekitd-test)
3536
swift_install_in_component(TARGETS sourcekitd-test
3637
RUNTIME
3738
DESTINATION bin

Diff for: tools/driver/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ if(NOT SWIFT_BUILT_STANDALONE)
3737
add_dependencies(swift clang-headers)
3838
endif()
3939

40+
add_dependencies(compiler swift)
4041
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc${CMAKE_EXECUTABLE_SUFFIX}"
4142
DESTINATION "bin"
4243
COMPONENT compiler)
44+
add_dependencies(autolink-driver swift)
4345
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-autolink-extract${CMAKE_EXECUTABLE_SUFFIX}"
4446
DESTINATION "bin"
4547
COMPONENT autolink-driver)
48+
add_dependencies(editor-integration swift)
4649
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-indent${CMAKE_EXECUTABLE_SUFFIX}"
4750
DESTINATION "bin"
4851
COMPONENT editor-integration)

Diff for: tools/libSwiftSyntaxParser/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
4646
target_link_libraries(libSwiftSyntaxParser PRIVATE BlocksRuntime)
4747
endif()
4848

49+
add_dependencies(parser-lib libSwiftSyntaxParser)
4950
swift_install_in_component(FILES "${SWIFT_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${SYNTAX_PARSER_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
5051
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
5152
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"

Diff for: utils/build-script-impl

+1
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,7 @@ for host in "${ALL_HOSTS[@]}"; do
35543554
if [[ -z "${INSTALL_SWIFT}" ]] ; then
35553555
continue
35563556
fi
3557+
INSTALL_TARGETS=install-swift-components
35573558
# Swift syntax parser is currently a sub-product of Swift;
35583559
# We need to specify the install target separately here.
35593560
if [ "${BUILD_LIBPARSER_ONLY}" ]; then

0 commit comments

Comments
 (0)