Skip to content

Rebase swift's component system ontop of LLVM's component system. #20910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ endif()

add_subdirectory(cmake/modules)

swift_install_in_component(license
swift_install_in_component(license swift-license
FILES "LICENSE.txt"
DESTINATION "share/swift")

Expand Down
10 changes: 5 additions & 5 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ function(add_swift_host_library name)
INSTALL_IN_COMPONENT "dev"
)

swift_install_in_component(dev
swift_install_in_component(dev ${name}
TARGETS ${name}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
Expand Down Expand Up @@ -2000,15 +2000,15 @@ function(add_swift_target_library name)
WORLD_READ)
endif()

swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" ${name}
FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
PERMISSIONS ${file_permissions})
if(sdk STREQUAL WINDOWS)
foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES})
if(TARGET ${name}-windows-${arch}_IMPLIB)
get_target_property(import_library ${name}-windows-${arch}_IMPLIB IMPORTED_LOCATION)
swift_install_in_component(${SWIFTLIB_INSTALL_IN_COMPONENT}
swift_install_in_component(${SWIFTLIB_INSTALL_IN_COMPONENT} ${import_library}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really should be part of the component itself. The import library is needed to be built against, and normally install(TARGET) will do the work for you.

FILES ${import_library}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
Expand Down Expand Up @@ -2043,7 +2043,7 @@ function(add_swift_target_library name)
OUTPUT
"${UNIVERSAL_LIBRARY_NAME}"
${THIN_INPUT_TARGETS_STATIC})
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" ${name}
FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}"
PERMISSIONS
Expand Down Expand Up @@ -2403,7 +2403,7 @@ function(add_swift_host_tool executable)

# And then create the install rule if we are asked to.
if (ADDSWIFTHOSTTOOL_SWIFT_COMPONENT)
swift_install_in_component(${ADDSWIFTHOSTTOOL_SWIFT_COMPONENT}
swift_install_in_component(${ADDSWIFTHOSTTOOL_SWIFT_COMPONENT} ${executable}
TARGETS ${executable}
RUNTIME DESTINATION bin)

Expand Down
58 changes: 52 additions & 6 deletions cmake/modules/SwiftComponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ 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)

# This is the high level install target that we use to create dependencies
# upon our llvm based install components.
add_custom_target(install-${component})
endif()
endforeach()
endmacro()
Expand All @@ -108,22 +112,64 @@ function(swift_is_installing_component component result_var_name)
endif()
endfunction()

# swift_install_in_component(<COMPONENT NAME>
# swift_install_in_component(<COMPONENT NAME> <TARGET NAME>
# <same parameters as install()>)
#
# Executes the specified installation actions if the named component is
# requested to be installed.
#
# This function accepts the same parameters as install().
function(swift_install_in_component component)
precondition(component MESSAGE "Component name is required")
# This function accepts the same parameters as install() except for TARGETS and
# COMPONENT since we need to control these two parameters to install so we can
# use LLVM's underlying install primitives.
function(swift_install_in_component swift_component install_target_name)
precondition(swift_component MESSAGE "Component name is required")
precondition(install_target_name MESSAGE "Install target name is required")

swift_is_installing_component("${component}" is_installing)
# Make sure that we were not passed TARGETS
cmake_parse_arguments(
SIIC # prefix
"" # options
"" # single-value args
"COMPONENT;TARGETS" # multi-value args
${ARGN})
precondition(SIIC_COMPONENT NEGATE MESSAGE "Must not specify COMPONENT as an arg")

# We do not support installing using the xcode generator.
if (NOT CMAKE_CONFIGURATION_TYPES)
return()
endif()

# First specify our install line swapping our install_target_name as our
# component.
install(COMPONENT ${install_target_name}-component ${SIIC_UNPARSED_ARGS})

# Then create the install-${install_target_name} target that invokes the given
# cmake component. If we intercepted a TARGETS argument, add those targets as
# our dependencies. Otherwise, this expands to the empty string.
set(targets_to_depend_on)
if (SIIC_TARGETS)
set(targets_to_depend_on DEPENDS ${SICC_TARGETS})
endif()
add_llvm_install_targets(install-${install_target_name}
${targets_to_depend_on}
COMPONENT ${install_target_name}-component)

# Ok, we now have setup a CMAKE component with the target
# install-${install_target_name} to trigger it. Now see if we were asked to
# install the specified ${swift_component}. If so, the variable
# install-${swift_component} will be defined and is expected to trigger the
# given CMAKE component. So in such a case make install-${swift_component}
# depend upon install-${install_target_name}.
swift_is_installing_component("${swift_component}" is_installing)
if(NOT is_installing)
return()
endif()

install(${ARGN})
if (NOT TARGET install-${swift_component})
message(FATAL "The target install-${swift_component} does not exist for component: ${swift_component}?!")
endif()

add_dependency(install-${swift_component} install-${install_target_name})
endfunction()

function(swift_install_symlink_component component)
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/SwiftManpage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ find_program(POD2MAN pod2man)
# MAN_SECTION N
# INSTALL_IN_COMPONENT comp
# )
function(manpage)
function(manpage name)
cmake_parse_arguments(
MP # prefix
"" # options
Expand All @@ -38,7 +38,7 @@ function(manpage)
DEPENDS "${MP_SOURCE}"
ALL)

swift_install_in_component("${MP_INSTALL_IN_COMPONENT}"
swift_install_in_component("${MP_INSTALL_IN_COMPONENT}" ${name}
FILES "${output_file_name}"
DESTINATION "share/man/man${MP_MAN_SECTION}")
endfunction()
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ function(_compile_swift_files
list(APPEND module_outputs "${interface_file}")
endif()

swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}" ${module_base}-module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it would be better to install the module with the module itself. You cannot use the module for development otherwise.

FILES ${module_outputs}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")

Expand Down Expand Up @@ -377,7 +377,7 @@ function(_compile_swift_files
list(APPEND depends_create_apinotes "${apinote_input_file}")

list(APPEND apinote_files "${apinote_file}")
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}" ${apinote_module}-apinotes
FILES ${apinote_file}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ if (DOXYGEN_FOUND)
add_dependencies(doxygen doxygen-swift)
endif()

swift_install_in_component(dev
swift_install_in_component(dev swift-doxygen-html
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
DESTINATION "docs/html")
endif()
Expand Down
1 change: 1 addition & 0 deletions docs/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(SwiftManpage)

manpage(
swift-pod
SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/swift.pod"
PAGE_HEADER "Swift Documentation"
MAN_FILE_BASENAME swift
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SwiftRemoteMirror/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ list(APPEND swift_remote_mirror_headers
Platform.h
SwiftRemoteMirror.h
SwiftRemoteMirrorTypes.h)
swift_install_in_component("swift-remote-mirror-headers"
swift_install_in_component("swift-remote-mirror-headers" swift-remote-mirror-headers
FILES
${swift_remote_mirror_headers}
DESTINATION
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if(SWIFT_BUILD_STATIC_STDLIB)
"${SWIFT_SOURCE_DIR}/utils/gen-static-stdlib-link-args")

list(APPEND static_stdlib_lnk_file_list ${swift_static_stdlib_${sdk}_args})
swift_install_in_component(stdlib
swift_install_in_component(stdlib ${lowercase_sdk}-linkfile
FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
DESTINATION "lib/swift_static/${lowercase_sdk}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion lib/Migrator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ add_custom_target("symlink_migrator_data"
DEPENDS "${output_dir}" "${outputs}"
COMMENT "Symlinking migrator data to ${output_dir}")

swift_install_in_component(compiler
swift_install_in_component(compiler symlink-migrator-data
FILES ${datafiles}
DESTINATION "lib/swift/migrator")

Expand Down
2 changes: 1 addition & 1 deletion lib/SwiftDemangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_swift_host_library(swiftDemangle
C_COMPILE_FLAGS
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1)

swift_install_in_component(compiler
swift_install_in_component(compiler swift-demangle-host
TARGETS swiftDemangle
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
2 changes: 1 addition & 1 deletion stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ foreach(sdk ${SWIFT_SDKS})
# It is not relocatable to the target platform itself.
# This affects any cross-comipled targets that use glibc.modulemap.

swift_install_in_component(sdk-overlay
swift_install_in_component(sdk-overlay glibc
FILES "${glibc_modulemap_out}"
DESTINATION "lib/swift/${arch_subdir}")

Expand Down
5 changes: 3 additions & 2 deletions stdlib/public/SwiftShims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ add_custom_command_target(unused_var
COMMENT "Symlinking Clang resource headers into ${SWIFTLIB_DIR}/clang")
add_dependencies(copy_shim_headers symlink_clang_headers)

swift_install_in_component(compiler
swift_install_in_component(compiler symlink-clang-headers-helper
FILES ${sources}
DESTINATION "lib/swift/shims")

# Install Clang headers under the Swift library so that an installed Swift's
# module importer can find the compiler headers corresponding to its Clang.
swift_install_in_component(clang-builtin-headers
swift_install_in_component(clang-builtin-headers clang-builtin-headers-helper
DIRECTORY "${clang_headers_location}/"
DESTINATION "lib/swift/clang"
PATTERN "*.h")
Expand All @@ -151,6 +151,7 @@ swift_install_symlink_component(clang-resource-dir-symlink
# need to use a different version of the headers than the installed Clang. This
# should be used in conjunction with clang-resource-dir-symlink.
swift_install_in_component(clang-builtin-headers-in-clang-resource-dir
clang-builtin-headers-in-clang-resource-dir-helper
DIRECTORY "${SWIFT_PATH_TO_CLANG_BUILD}/lib/clang"
DESTINATION "lib"
PATTERN "*.h")
10 changes: 5 additions & 5 deletions stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
"${LibraryLocation}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
DEPENDS
${FragileSupportLibrary})
swift_install_in_component(stdlib
swift_install_in_component(stdlib ${FragileSupportLibrary}
FILES $<TARGET_FILE:${FragileSupportLibrary}>
DESTINATION "lib/swift_static/${lowercase_sdk}/${arch}")
endforeach()
Expand All @@ -137,7 +137,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
"${LibraryLocationPrimary}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
DEPENDS
${FragileSupportLibraryPrimary})
swift_install_in_component(stdlib
swift_install_in_component(stdlib $<TARGET_FILE:${FragileSupportLibraryPrimary}>
FILES $<TARGET_FILE:${FragileSupportLibraryPrimary}>
DESTINATION "lib/swift_static/${lowercase_sdk}")

Expand All @@ -154,7 +154,7 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
"${SWIFT_SOURCE_DIR}/utils/static-executable-args.lnk")

list(APPEND static_binary_lnk_file_list ${swift_static_binary_${sdk}_args})
swift_install_in_component(stdlib
swift_install_in_component(stdlib ${lowercase_sdk}-linkfile
FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
DESTINATION "lib/swift_static/${lowercase_sdk}")
add_custom_target(static_binary_magic ALL DEPENDS ${static_binary_lnk_file_list})
Expand Down Expand Up @@ -230,14 +230,14 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
DEPENDS
"${swiftrtObject}")
if(SWIFT_BUILD_DYNAMIC_STDLIB)
swift_install_in_component(stdlib
swift_install_in_component(stdlib swiftImageRegistration-${arch_suffix}-dynamic
FILES
"${shared_runtime_registrar}"
DESTINATION
"lib/swift/${arch_subdir}")
endif()
if(SWIFT_BUILD_STATIC_STDLIB)
swift_install_in_component(stdlib
swift_install_in_component(stdlib swiftImageRegistration-${arch_suffix}-static
FILES
"${static_runtime_registrar}"
DESTINATION
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function(swift_configure_lit_site_cfg source_path destination_path installed_nam
configure_file("${source_path}" "${destination_path}" @ONLY)

if(NOT "${installed_name}" STREQUAL "")
swift_install_in_component(testsuite-tools
swift_install_in_component(testsuite-tools testsuite-tools
FILES "${destination_path}"
RENAME "${installed_name}"
DESTINATION "share/swift/testsuite")
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
add_dependencies(dispatch libdispatch-install)
add_dependencies(BlocksRuntime libdispatch-install)

swift_install_in_component(sourcekit-inproc
swift_install_in_component(sourcekit-inproc sourcekit-inproc-dispatch-blocksruntime
FILES
$<TARGET_FILE:dispatch>
$<TARGET_FILE:BlocksRuntime>
Expand Down
8 changes: 4 additions & 4 deletions tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ macro(add_sourcekit_library name)
set(SOURCEKITLIB_INSTALL_IN_COMPONENT dev)
endif()
endif()
swift_install_in_component("${SOURCEKITLIB_INSTALL_IN_COMPONENT}"
swift_install_in_component("${SOURCEKITLIB_INSTALL_IN_COMPONENT}" ${name}
TARGETS ${name}
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
RUNTIME DESTINATION "bin")
swift_install_in_component("${SOURCEKITLIB_INSTALL_IN_COMPONENT}"
swift_install_in_component("${SOURCEKITLIB_INSTALL_IN_COMPONENT}" ${name}-headers
FILES ${SOURCEKITLIB_HEADERS}
DESTINATION "include/SourceKit")
set_target_properties(${name} PROPERTIES FOLDER "SourceKit libraries")
Expand Down Expand Up @@ -335,7 +335,7 @@ macro(add_sourcekit_framework name)


if (SOURCEKIT_DEPLOYMENT_OS MATCHES "^macosx")
swift_install_in_component(${SOURCEKITFW_INSTALL_IN_COMPONENT}
swift_install_in_component(${SOURCEKITFW_INSTALL_IN_COMPONENT} ${name}
TARGETS ${name}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
Expand All @@ -354,7 +354,7 @@ macro(add_sourcekit_framework name)
MACOSX_FRAMEWORK_BUNDLE_VERSION "${SOURCEKIT_VERSION_STRING}"
PUBLIC_HEADER "${headers}")
else()
swift_install_in_component(${SOURCEKITFW_INSTALL_IN_COMPONENT}
swift_install_in_component(${SOURCEKITFW_INSTALL_IN_COMPONENT} ${name}
DIRECTORY ${framework_location}
DESTINATION lib${LLVM_LIBDIR_SUFFIX}
USE_SOURCE_PERMISSIONS)
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/tools/complete-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ if(SWIFT_ANALYZE_CODE_COVERAGE)
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
endif()

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

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

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

swift_install_in_component(compiler
swift_install_in_component(compiler swiftc
FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc${CMAKE_EXECUTABLE_SUFFIX}"
DESTINATION "bin")
swift_install_in_component(autolink-driver
swift_install_in_component(autolink-driver swift-autolink-extract
FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-autolink-extract${CMAKE_EXECUTABLE_SUFFIX}"
DESTINATION "bin")
swift_install_in_component(editor-integration
swift_install_in_component(editor-integration swift-format
FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-format${CMAKE_EXECUTABLE_SUFFIX}"
DESTINATION "bin")
Loading