Skip to content

WIP/install: build a SDK image for installation #26409

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
wants to merge 1 commit into from
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
60 changes: 60 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ set(SWIFTLIB_DIR
set(SWIFTSTATICLIB_DIR
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift_static")

set(SWIFT_PLATFORMS_DIR
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Developer/Platforms)
foreach(sdk ${SWIFT_SDKS})
set(SWIFT_${sdk}_SDK_DIR
${SWIFT_PLATFORMS_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}.platform/Developer/SDKs/${SWIFT_SDK_${sdk}_LIB_SUBDIR}.sdk)
if(NOT TARGET swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk)
file(MAKE_DIRECTORY ${SWIFT_${sdk}_SDK_DIR})
add_custom_target(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk)
endif()
endforeach()

function(add_dependencies_multiple_targets)
cmake_parse_arguments(
ADMT # prefix
Expand Down Expand Up @@ -1551,6 +1562,7 @@ endfunction()
# [IS_STDLIB_CORE]
# [TARGET_LIBRARY]
# [INSTALL_WITH_SHARED]
# [INSTALL_IN_SDK]
# INSTALL_IN_COMPONENT comp
# DEPLOYMENT_VERSION_OSX version
# DEPLOYMENT_VERSION_IOS version
Expand Down Expand Up @@ -1675,6 +1687,7 @@ function(add_swift_target_library name)
SHARED
STATIC
TARGET_LIBRARY
INSTALL_IN_SDK
INSTALL_WITH_SHARED)
set(SWIFTLIB_single_parameter_options
DEPLOYMENT_VERSION_IOS
Expand Down Expand Up @@ -2003,6 +2016,52 @@ function(add_swift_target_library name)
GYB_SOURCES ${SWIFTLIB_GYB_SOURCES}
)

if(SWIFTLIB_INSTALL_IN_SDK)
if(SWIFTLIB_SHARED)
if(${sdk} STREQUAL WINDOWS)
set(target_file ${name}.lib)
else()
set(target_file ${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

add_custom_command(OUTPUT ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${target_file}
DEPENDS ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${target_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${target_file} ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${target_file})
add_custom_target(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}
DEPENDS ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${target_file})

if(SWIFTLIB_IS_STDLIB_CORE)
set(module_name Swift)
else()
string(REPLACE swift "" module_name "${name}")
endif()

add_custom_command(OUTPUT ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftdoc
DEPENDS ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${module_name}.swiftdoc
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${module_name}.swiftdoc ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftdoc)
add_custom_target(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}-swiftdoc
DEPENDS ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftdoc)

add_custom_command(OUTPUT ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftinterface
DEPENDS ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${module_name}.swiftinterface
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${module_name}.swiftinterface ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftinterface)
add_custom_target(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}-swiftinterface
DEPENDS ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftinterface)

add_custom_command(OUTPUT ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftmodule
DEPENDS ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${module_name}.swiftmodule
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${module_name}.swiftmodule ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftmodule)
add_custom_target(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}-swiftmodule
DEPENDS ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/${arch}/${module_name}.swiftmodule)

add_dependencies(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk
swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}
swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}-swiftdoc
swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}-swiftinterface
swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-${name}-${arch}-swiftmodule)
endif()
endif()

if(sdk STREQUAL WINDOWS)
if(SWIFT_COMPILER_IS_MSVC_LIKE)
if (SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY MATCHES MultiThreadedDebugDLL)
Expand Down Expand Up @@ -2151,6 +2210,7 @@ function(add_swift_target_library name)
PERMISSIONS ${file_permissions}
"${optional_arg}")
endif()

if(sdk STREQUAL WINDOWS)
foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES})
if(TARGET ${name}-windows-${arch}_IMPLIB)
Expand Down
9 changes: 6 additions & 3 deletions stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS ALL_APPLE_PLATFORMS

DEPENDS ${darwin_depends})
DEPENDS ${darwin_depends}
INSTALL_IN_SDK)

add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
${swift_platform_sources}
Expand All @@ -39,7 +40,8 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O
SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS ANDROID CYGWIN FREEBSD LINUX HAIKU
DEPENDS glibc_modulemap)
DEPENDS glibc_modulemap
INSTALL_IN_SDK)

add_swift_target_library(swiftMSVCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
msvcrt.swift
Expand All @@ -51,7 +53,8 @@ add_swift_target_library(swiftMSVCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_

SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS WINDOWS)
TARGET_SDKS WINDOWS
INSTALL_IN_SDK)

set(glibc_modulemap_target_list)
foreach(sdk ${SWIFT_SDKS})
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/SwiftOnoneSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ add_swift_target_library(swiftSwiftOnoneSupport ${SWIFT_STDLIB_LIBRARY_BUILD_TYP
# pre-optimization for performance) list them.
SWIFT_COMPILE_FLAGS "-parse-stdlib" "-Xllvm" "-sil-inline-generics=false" "-Xfrontend" "-validate-tbd-against-ir=none" "-Xfrontend" "-check-onone-completeness" "-Xfrontend" "-disable-access-control" "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}" "${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
INSTALL_IN_COMPONENT stdlib)
INSTALL_IN_COMPONENT stdlib
INSTALL_IN_SDK)
if(WINDOWS IN_LIST SWIFT_SDKS)
# When building in Debug mode, the standard library provides the symbols that
# we need and as such SwiftOnoneSupport does not need to provide any exported
Expand Down
24 changes: 21 additions & 3 deletions stdlib/public/SwiftShims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ foreach(input ${sources})
OUTPUT "${output_dir}/${input}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${input}"
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${CMAKE_CURRENT_SOURCE_DIR}/${input}"
"${output_dir}/${input}"
"${CMAKE_COMMAND}" "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${input}" "${output_dir}/${input}"
COMMENT "Copying ${input} to ${output_dir}")
list(APPEND outputs "${output_dir}/${input}")

foreach(sdk ${SWIFT_SDKS})
add_custom_command(OUTPUT ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/shims/${input}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${input}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${input} ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/shims/${input})
add_custom_target(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-shims-${input}
DEPENDS ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/shims/${input})
add_dependencies(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk
swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-shims-${input})
endforeach()
endforeach()
# Put the output dir itself last so that it isn't considered the primary output.
list(APPEND outputs "${output_dir}")
Expand Down Expand Up @@ -123,6 +131,16 @@ add_custom_command_target(unused_var
COMMENT "Symlinking Clang resource headers into ${SWIFTLIB_DIR}/clang")
add_dependencies(copy_shim_headers symlink_clang_headers)

foreach(sdk ${SWIFT_SDKS})
add_custom_command(OUTPUT ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/clang
DEPENDS ${clang_headers_location}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${clang_headers_location} ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/clang)
add_custom_target(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-clang-headers
DEPENDS ${SWIFT_${sdk}_SDK_DIR}/usr/lib/swift/clang)
add_dependencies(swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk
swift-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-sdk-clang-headers)
endforeach()

swift_install_in_component(FILES ${sources}
DESTINATION "lib/swift/shims"
COMPONENT stdlib)
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ add_swift_target_library(swiftWinSDK ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_

SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS WINDOWS)
TARGET_SDKS WINDOWS
INSTALL_IN_SDK)

3 changes: 2 additions & 1 deletion stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,5 @@ add_swift_target_library(swiftCore
FRAMEWORK_DEPENDS
${swift_core_framework_depends}
INSTALL_IN_COMPONENT
stdlib)
stdlib
INSTALL_IN_SDK)