Skip to content

Commit

Permalink
[CMake][NFC] Introduce component targets for proper dependency tracking
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bulbazord committed Aug 8, 2019
1 parent 9bd97ea commit 50a0e87
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 12 deletions.
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,18 @@ include(CMakePushCheckState)

print_versions()

include(SwiftSharedCMakeConfig)

# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
# functionality.
# Support building Swift as a standalone project, using LLVM as an
# external library.
if(SWIFT_BUILT_STANDALONE)
swift_common_standalone_build_config(SWIFT)
else()
swift_common_unified_build_config(SWIFT)
endif()

include(SwiftComponents)
include(SwiftHandleGybSources)
include(SwiftSetIfArchBitness)
Expand Down Expand Up @@ -527,16 +539,6 @@ if(NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

include(SwiftSharedCMakeConfig)

# Support building Swift as a standalone project, using LLVM as an
# external library.
if(SWIFT_BUILT_STANDALONE)
swift_common_standalone_build_config(SWIFT)
else()
swift_common_unified_build_config(SWIFT)
endif()

get_filename_component(SWIFT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
set(SWIFT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(SWIFT_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
Expand Down Expand Up @@ -1051,6 +1053,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
else()
set(SOURCEKIT_RUNTIME_DIR lib)
endif()
add_dependencies(sourcekit-inproc BlocksRuntime dispatch)
swift_install_in_component(FILES
$<TARGET_FILE:dispatch>
$<TARGET_FILE:BlocksRuntime>
Expand Down
1 change: 1 addition & 0 deletions apinotes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_custom_target("copy_apinotes" ALL
COMMENT "Copying API notes to ${output_dir}"
SOURCES "${sources}")

add_dependencies(compiler copy_apinotes)
swift_install_in_component(DIRECTORY "${output_dir}"
DESTINATION "lib/swift/"
COMPONENT compiler)
8 changes: 8 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,7 @@ function(add_swift_host_library name)
INSTALL_IN_COMPONENT "dev"
)

add_dependencies(dev ${name})
if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
swift_install_in_component(TARGETS ${name}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT dev
Expand Down Expand Up @@ -2117,6 +2118,7 @@ function(add_swift_target_library name)
endif()

if(sdk STREQUAL WINDOWS AND CMAKE_SYSTEM_NAME STREQUAL Windows)
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH})
swift_install_in_component(TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
RUNTIME
DESTINATION "bin"
Expand All @@ -2129,6 +2131,9 @@ function(add_swift_target_library name)
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
PERMISSIONS ${file_permissions})
else()
# NOTE: ${UNIVERSAL_LIBRARY_NAME} is the output associated with the target
# ${lipo_target}
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${lipo_target})
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
Expand All @@ -2139,6 +2144,7 @@ function(add_swift_target_library name)
foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES})
if(TARGET ${name}-windows-${arch}_IMPLIB)
get_target_property(import_library ${name}-windows-${arch}_IMPLIB IMPORTED_LOCATION)
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${name}-windows-${arch}_IMPLIB)
swift_install_in_component(FILES ${import_library}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
COMPONENT ${SWIFTLIB_INSTALL_IN_COMPONENT}
Expand Down Expand Up @@ -2205,6 +2211,7 @@ function(add_swift_target_library name)
OUTPUT
"${UNIVERSAL_LIBRARY_NAME}"
${THIN_INPUT_TARGETS_STATIC})
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${lipo_target_static})
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${install_subdir}/${resource_dir_sdk_subdir}"
PERMISSIONS
Expand Down Expand Up @@ -2406,6 +2413,7 @@ function(add_swift_host_tool executable)
ARCHITECTURE ${SWIFT_HOST_VARIANT_ARCH}
${ASHT_UNPARSED_ARGUMENTS})

add_dependencies(${ASHT_SWIFT_COMPONENT} ${executable})
swift_install_in_component(TARGETS ${executable}
RUNTIME
DESTINATION bin
Expand Down
17 changes: 16 additions & 1 deletion cmake/modules/SwiftComponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,23 @@ macro(swift_configure_components)
"A semicolon-separated list of components to install from the set ${_SWIFT_DEFINED_COMPONENTS}")

foreach(component ${_SWIFT_DEFINED_COMPONENTS})
add_custom_target(${component})
add_llvm_install_targets(install-${component}
DEPENDS ${component}
COMPONENT ${component})

string(TOUPPER "${component}" var_name_piece)
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
set(SWIFT_INSTALL_${var_name_piece} FALSE)
endforeach()

# NOTE: never_install is a dummy component to indicate something should not
# be installed. We explicitly do not add an install target for this.
add_custom_target(never_install)

add_custom_target(swift-components)
add_custom_target(install-swift-components)

foreach(component ${SWIFT_INSTALL_COMPONENTS})
if(NOT "${component}" IN_LIST _SWIFT_DEFINED_COMPONENTS)
message(FATAL_ERROR "unknown install component: ${component}")
Expand All @@ -106,6 +118,8 @@ macro(swift_configure_components)
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
if(NOT SWIFT_INSTALL_EXCLUDE_${var_name_piece})
set(SWIFT_INSTALL_${var_name_piece} TRUE)
add_dependencies(swift-components ${component})
add_dependencies(install-swift-components install-${component})
endif()
endforeach()
endmacro()
Expand Down Expand Up @@ -174,5 +188,6 @@ function(swift_install_symlink_component component)
MESSAGE "LLVMInstallSymlink script must be available.")

install(SCRIPT ${INSTALL_SYMLINK}
CODE "install_symlink(${ARG_LINK_NAME} ${ARG_TARGET} ${ARG_DESTINATION})")
CODE "install_symlink(${ARG_LINK_NAME} ${ARG_TARGET} ${ARG_DESTINATION})"
COMPONENT ${component})
endfunction()
3 changes: 2 additions & 1 deletion cmake/modules/SwiftManpage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function(manpage)
"${CMAKE_CURRENT_BINARY_DIR}/${MP_MAN_FILE_BASENAME}.${MP_MAN_SECTION}")

add_custom_command_target(
unused_var
manpage_target
COMMAND
"${POD2MAN}" "--section" "${MP_MAN_SECTION}"
"--center" "${MP_PAGE_HEADER}" "--release=\"swift ${SWIFT_VERSION}\""
Expand All @@ -38,6 +38,7 @@ function(manpage)
DEPENDS "${MP_SOURCE}"
ALL)

add_dependencies(${MP_INSTALL_IN_COMPONENT} ${manpage_target})
swift_install_in_component(FILES "${output_file_name}"
DESTINATION "share/man/man${MP_MAN_SECTION}"
COMPONENT "${MP_INSTALL_IN_COMPONENT}")
Expand Down
1 change: 1 addition & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if (DOXYGEN_FOUND)
add_dependencies(doxygen doxygen-swift)
endif()

add_dependencies(dev doxygen-swift)
swift_install_in_component(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
DESTINATION "docs/html"
COMPONENT dev)
Expand Down
1 change: 1 addition & 0 deletions lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ if(SWIFT_BUILD_STATIC_STDLIB)
endif()
endforeach()
add_custom_target(swift_static_lnk_args ALL DEPENDS ${static_stdlib_lnk_file_list})
add_dependencies(stdlib swift_static_lnk_args)
endif()
1 change: 1 addition & 0 deletions lib/SwiftDemangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target_compile_definitions(swiftDemangle PRIVATE
target_link_libraries(swiftDemangle PRIVATE
swiftDemangling)

add_dependencies(compiler swiftDemangle)
swift_install_in_component(TARGETS swiftDemangle
LIBRARY
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ foreach(sdk ${SWIFT_SDKS})
endforeach()
add_custom_target(glibc_modulemap DEPENDS ${glibc_modulemap_target_list})
set_property(TARGET glibc_modulemap PROPERTY FOLDER "Miscellaneous")
add_dependencies(sdk-overlay glibc_modulemap)
4 changes: 4 additions & 0 deletions stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
"${LibraryLocation}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
DEPENDS
${FragileSupportLibrary})
add_dependencies(stdlib ${FragileSupportLibrary})
swift_install_in_component(FILES $<TARGET_FILE:${FragileSupportLibrary}>
DESTINATION "lib/swift_static/${lowercase_sdk}/${arch}"
COMPONENT stdlib)
Expand All @@ -125,6 +126,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
"${LibraryLocationPrimary}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
DEPENDS
${FragileSupportLibraryPrimary})
add_dependencies(stdlib ${FragileSupportLibraryPrimary})
swift_install_in_component(FILES $<TARGET_FILE:${FragileSupportLibraryPrimary}>
DESTINATION "lib/swift_static/${lowercase_sdk}"
COMPONENT stdlib)
Expand All @@ -150,6 +152,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
add_dependencies(static_binary_magic ${swift_image_inspection_${arch}_static})
endforeach()
add_dependencies(static_binary_magic ${swift_image_inspection_static_primary_arch})
add_dependencies(stdlib static_binary_magic)

add_swift_target_library(swiftImageInspectionSharedObject OBJECT_LIBRARY
ImageInspectionELF.cpp
Expand Down Expand Up @@ -250,6 +253,7 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
add_custom_target(swiftImageRegistration-${arch_suffix}
ALL DEPENDS
${swiftImageRegistration-${arch_suffix}})
add_dependencies(stdlib swift-stdlib-${arch_suffix} swiftImageRegistration-${arch_suffix})
endif()
endforeach()
endforeach()
Expand Down
2 changes: 2 additions & 0 deletions tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ macro(add_sourcekit_library name)
set(SOURCEKITLIB_INSTALL_IN_COMPONENT dev)
endif()
endif()
add_dependencies(${SOURCEKITLIB_INSTALL_IN_COMPONENT} ${name})
swift_install_in_component(TARGETS ${name}
LIBRARY
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
Expand Down Expand Up @@ -345,6 +346,7 @@ macro(add_sourcekit_framework name)
MACOSX_FRAMEWORK_SHORT_VERSION_STRING "1.0"
MACOSX_FRAMEWORK_BUNDLE_VERSION "${SOURCEKIT_VERSION_STRING}"
PUBLIC_HEADER "${headers}")
add_dependencies(${SOURCEKITFW_INSTALL_IN_COMPONENT} ${name})
swift_install_in_component(TARGETS ${name}
FRAMEWORK
DESTINATION lib${LLVM_LIBDIR_SUFFIX}
Expand Down
1 change: 1 addition & 0 deletions tools/SourceKit/tools/complete-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if(SWIFT_ANALYZE_CODE_COVERAGE)
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
endif()

add_dependencies(tools complete-test)
swift_install_in_component(TARGETS complete-test
RUNTIME
DESTINATION bin
Expand Down
1 change: 1 addition & 0 deletions tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if(HAVE_UNICODE_LIBEDIT)
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
endif()

add_dependencies(tools sourcekitd-repl)
swift_install_in_component(TARGETS sourcekitd-repl
RUNTIME
DESTINATION bin
Expand Down
1 change: 1 addition & 0 deletions tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if(SWIFT_ANALYZE_CODE_COVERAGE)
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
endif()

add_dependencies(tools sourcekitd-test)
swift_install_in_component(TARGETS sourcekitd-test
RUNTIME
DESTINATION bin
Expand Down
3 changes: 3 additions & 0 deletions tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ if(NOT SWIFT_BUILT_STANDALONE)
add_dependencies(swift clang-headers)
endif()

add_dependencies(compiler swift)
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc${CMAKE_EXECUTABLE_SUFFIX}"
DESTINATION "bin"
COMPONENT compiler)
add_dependencies(autolink-driver swift)
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-autolink-extract${CMAKE_EXECUTABLE_SUFFIX}"
DESTINATION "bin"
COMPONENT autolink-driver)
add_dependencies(editor-integration swift)
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-indent${CMAKE_EXECUTABLE_SUFFIX}"
DESTINATION "bin"
COMPONENT editor-integration)
1 change: 1 addition & 0 deletions tools/libSwiftSyntaxParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
target_link_libraries(libSwiftSyntaxParser PRIVATE BlocksRuntime)
endif()

add_dependencies(parser-lib libSwiftSyntaxParser)
swift_install_in_component(FILES "${SWIFT_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${SYNTAX_PARSER_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
Expand Down
1 change: 1 addition & 0 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -3552,6 +3552,7 @@ for host in "${ALL_HOSTS[@]}"; do
if [[ -z "${INSTALL_SWIFT}" ]] ; then
continue
fi
INSTALL_TARGETS=install-swift-components
# Swift syntax parser is currently a sub-product of Swift;
# We need to specify the install target separately here.
if [ "${BUILD_LIBPARSER_ONLY}" ]; then
Expand Down

0 comments on commit 50a0e87

Please sign in to comment.