Skip to content
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,11 @@ else()
add_subdirectory(stdlib/toolchain)
endif()

if (BUILD_SWIFT_CONCURRENCY_BACK_DEPLOYMENT_LIBRARIES)
# Build the back-deployed concurrency library.
add_subdirectory(stdlib/public/BackDeployConcurrency)
endif()

# Some tools (e.g. swift-reflection-dump) rely on a host swiftReflection, so
# ensure we build that when building tools.
if(SWIFT_INCLUDE_TOOLS)
Expand Down
5 changes: 4 additions & 1 deletion cmake/modules/SwiftComponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
# The set of "defined" swift components are as follows:
#
# * autolink-driver -- the Swift driver support tools
# * back-deployment -- Swift back-deployment libraries
# * compiler -- the Swift compiler and (on supported platforms) the REPL.
# * clang-builtin-headers -- install a copy of Clang builtin headers under
# 'lib/swift/clang'. This is useful when Swift compiler is installed in
Expand All @@ -66,7 +67,7 @@
# * toolchain-dev-tools -- install development tools useful in a shared toolchain
# * dev -- headers and libraries required to use Swift compiler as a library.
set(_SWIFT_DEFINED_COMPONENTS
"autolink-driver;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")

# The default install components include all of the defined components, except
# for the following exceptions.
Expand All @@ -85,6 +86,8 @@ else()
list(REMOVE_ITEM _SWIFT_DEFAULT_COMPONENTS "sourcekit-xpc-service")
endif()
list(REMOVE_ITEM _SWIFT_DEFAULT_COMPONENTS "stdlib-experimental")
# back-deployment libraries are opt-in
list(REMOVE_ITEM _SWIFT_DEFAULT_COMPONENTS "back-deployment")

macro(swift_configure_components)
# Set the SWIFT_INSTALL_COMPONENTS variable to the default value if it is not passed in via -D
Expand Down
3 changes: 2 additions & 1 deletion include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ namespace swift {
bool EnableExperimentalConcurrency = false;

/// Enable experimental back-deployment of the concurrency model.
bool EnableExperimentalBackDeployConcurrency = false;
bool EnableExperimentalBackDeployConcurrency =
SWIFT_ALLOW_BACK_DEPLOY_CONCURRENCY;

/// Enable experimental support for named opaque result types, e.g.
/// `func f() -> <T> T`.
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

#cmakedefine01 SWIFT_ENABLE_GLOBAL_ISEL_ARM64

#cmakedefine01 SWIFT_ALLOW_BACK_DEPLOY_CONCURRENCY

#endif // SWIFT_CONFIG_H
52 changes: 45 additions & 7 deletions stdlib/cmake/modules/AddSwiftStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ function(_add_swift_target_library_single target name)
SDK
DEPLOYMENT_VERSION_MACCATALYST
MACCATALYST_BUILD_FLAVOR
BACK_DEPLOYMENT_LIBRARY
ENABLE_LTO)
set(SWIFTLIB_SINGLE_multiple_parameter_options
C_COMPILE_FLAGS
Expand Down Expand Up @@ -771,6 +772,13 @@ function(_add_swift_target_library_single target name)
-libc;${SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY})
endif()

# Don't install the Swift module content for back-deployment libraries.
if (SWIFTLIB_SINGLE_BACK_DEPLOYMENT_LIBRARY)
set(install_in_component "never_install")
else()
set(install_in_component "${SWIFTLIB_SINGLE_INSTALL_IN_COMPONENT}")
endif()

# FIXME: don't actually depend on the libraries in SWIFTLIB_SINGLE_LINK_LIBRARIES,
# just any swiftmodule files that are associated with them.
handle_swift_sources(
Expand All @@ -796,7 +804,7 @@ function(_add_swift_target_library_single target name)
${embed_bitcode_arg}
${SWIFTLIB_SINGLE_STATIC_keyword}
ENABLE_LTO "${SWIFTLIB_SINGLE_ENABLE_LTO}"
INSTALL_IN_COMPONENT "${SWIFTLIB_SINGLE_INSTALL_IN_COMPONENT}"
INSTALL_IN_COMPONENT "${install_in_component}"
MACCATALYST_BUILD_FLAVOR "${SWIFTLIB_SINGLE_MACCATALYST_BUILD_FLAVOR}")
add_swift_source_group("${SWIFTLIB_SINGLE_EXTERNAL_SOURCES}")

Expand Down Expand Up @@ -941,21 +949,28 @@ function(_add_swift_target_library_single target name)
SUFFIX ${LLVM_PLUGIN_EXT})
endif()

# For back-deployed libraries, install into lib/swift-<version>.
if (SWIFTLIB_SINGLE_BACK_DEPLOYMENT_LIBRARY)
set(swiftlib_prefix "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift-${SWIFTLIB_SINGLE_BACK_DEPLOYMENT_LIBRARY}")
else()
set(swiftlib_prefix ${SWIFTLIB_DIR})
endif()

# Install runtime libraries to lib/swift instead of lib. This works around
# the fact that -isysroot prevents linking to libraries in the system
# /usr/lib if Swift is installed in /usr.
set_target_properties("${target}" PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}
ARCHIVE_OUTPUT_DIRECTORY ${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR})
LIBRARY_OUTPUT_DIRECTORY ${swiftlib_prefix}/${SWIFTLIB_SINGLE_SUBDIR}
ARCHIVE_OUTPUT_DIRECTORY ${swiftlib_prefix}/${SWIFTLIB_SINGLE_SUBDIR})
if(SWIFTLIB_SINGLE_SDK STREQUAL WINDOWS AND SWIFTLIB_SINGLE_IS_STDLIB_CORE
AND libkind STREQUAL SHARED)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${target}> ${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR})
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${target}> ${swiftlib_prefix}/${SWIFTLIB_SINGLE_SUBDIR})
endif()

foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config_upper)
escape_path_for_xcode("${config}" "${SWIFTLIB_DIR}" config_lib_dir)
escape_path_for_xcode("${config}" "${swiftlib_prefix}" config_lib_dir)
set_target_properties(${target} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR})
Expand Down Expand Up @@ -1390,6 +1405,7 @@ endfunction()
# DEPLOYMENT_VERSION_TVOS version
# DEPLOYMENT_VERSION_WATCHOS version
# MACCATALYST_BUILD_FLAVOR flavor
# BACK_DEPLOYMENT_LIBRARY version
# source1 [source2 source3 ...])
#
# name
Expand Down Expand Up @@ -1485,6 +1501,9 @@ endfunction()
# IS_SDK_OVERLAY
# Treat the library as a part of the Swift SDK overlay.
#
# BACK_DEPLOYMENT_LIBRARY
# Treat this as a back-deployment library to the given Swift version
#
# INSTALL_IN_COMPONENT comp
# The Swift installation component that this library belongs to.
#
Expand Down Expand Up @@ -1533,7 +1552,8 @@ function(add_swift_target_library name)
INSTALL_IN_COMPONENT
DARWIN_INSTALL_NAME_DIR
DEPLOYMENT_VERSION_MACCATALYST
MACCATALYST_BUILD_FLAVOR)
MACCATALYST_BUILD_FLAVOR
BACK_DEPLOYMENT_LIBRARY)
set(SWIFTLIB_multiple_parameter_options
C_COMPILE_FLAGS
DEPENDS
Expand Down Expand Up @@ -1970,6 +1990,12 @@ function(add_swift_target_library name)
list(APPEND swiftlib_link_flags_all "-Wl,-soname,lib${name}.so")
endif()

if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY)
set(back_deployment_library_option BACK_DEPLOYMENT_LIBRARY ${SWIFTLIB_BACK_DEPLOYMENT_LIBRARY})
else()
set(back_deployment_library_option)
endif()

# Add this library variant.
_add_swift_target_library_single(
${variant_name}
Expand Down Expand Up @@ -2006,6 +2032,7 @@ function(add_swift_target_library name)
DEPLOYMENT_VERSION_TVOS "${SWIFTLIB_DEPLOYMENT_VERSION_TVOS}"
DEPLOYMENT_VERSION_WATCHOS "${SWIFTLIB_DEPLOYMENT_VERSION_WATCHOS}"
MACCATALYST_BUILD_FLAVOR "${maccatalyst_build_flavor}"
${back_deployment_library_option}
ENABLE_LTO "${SWIFT_STDLIB_ENABLE_LTO}"
GYB_SOURCES ${SWIFTLIB_GYB_SOURCES}
)
Expand Down Expand Up @@ -2106,6 +2133,9 @@ function(add_swift_target_library name)
if("${sdk}" STREQUAL "WINDOWS")
set(UNIVERSAL_LIBRARY_NAME
"${SWIFTLIB_DIR}/${library_subdir}/${name}.dll")
elseif(SWIFTLIB_BACK_DEPLOYMENT_LIBRARY)
set(UNIVERSAL_LIBRARY_NAME
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift-${SWIFTLIB_BACK_DEPLOYMENT_LIBRARY}/${library_subdir}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
else()
set(UNIVERSAL_LIBRARY_NAME
"${SWIFTLIB_DIR}/${library_subdir}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
Expand Down Expand Up @@ -2185,8 +2215,16 @@ function(add_swift_target_library name)
# NOTE: ${UNIVERSAL_LIBRARY_NAME} is the output associated with the target
# ${lipo_target}
add_dependencies(${SWIFTLIB_INSTALL_IN_COMPONENT} ${lipo_target})

if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY)
# Back-deployment libraries get installed into a versioned directory.
set(install_dest "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}-${SWIFTLIB_BACK_DEPLOYMENT_LIBRARY}/${resource_dir_sdk_subdir}")
else()
set(install_dest "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}")
endif()

swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
DESTINATION ${install_dest}
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
PERMISSIONS ${file_permissions}
"${optional_arg}")
Expand Down
8 changes: 7 additions & 1 deletion stdlib/private/StdlibUnittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ if (SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED)
list(APPEND swift_stdlib_unittest_link_libraries "swift_Distributed")
endif()

if (SWIFT_ALLOW_BACK_DEPLOY_CONCURRENCY)
set(swift_concurrency_availability "macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0")
else()
set(swift_concurrency_availability "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0")
endif()

add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
Expand Down Expand Up @@ -55,7 +61,7 @@ add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
SWIFT_MODULE_DEPENDS_WINDOWS CRT WinSDK
SWIFT_COMPILE_FLAGS ${swift_stdlib_unittest_compile_flags} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-Xfrontend -define-availability
-Xfrontend \"SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0\"
-Xfrontend "SwiftStdlib 5.5:${swift_concurrency_availability}"
INSTALL_IN_COMPONENT stdlib-experimental
DARWIN_INSTALL_NAME_DIR "${SWIFT_DARWIN_STDLIB_PRIVATE_INSTALL_NAME_DIR}"
LINK_LIBRARIES ${swift_stdlib_unittest_link_libraries})
Expand Down
44 changes: 44 additions & 0 deletions stdlib/public/BackDeployConcurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#===--- CMakeLists.txt - Back-deployed concurrency support library -------===#
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
#===----------------------------------------------------------------------===#

# This is always build standalone
include("${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules/StandaloneOverlay.cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules")
include(AddSwiftStdlib)

# Don't build the libraries for 32-bit iOS targets; there is no back-deployment
# to them.
list(REMOVE_ITEM SWIFT_SDK_IOS_ARCHITECTURES "armv7" "armv7s")
list(REMOVE_ITEM SWIFT_SDK_IOS_SIMULATOR_ARCHITECTURES "i386")

# The back-deployed library can only be shared.
list(APPEND SWIFT_STDLIB_LIBRARY_BUILD_TYPES SHARED)

# Link aginst the libswiftCore in the SDK. This intentionally avoids using
# the locally-built libswiftCore.
foreach(sdk ${SWIFT_SDKS})
set(sdk_name ${SWIFT_SDK_${sdk}_LIB_SUBDIR})
set(swift_core_target "swiftCore-${sdk_name}")
add_library(${swift_core_target} SHARED IMPORTED GLOBAL)
set_property(TARGET ${swift_core_target}
PROPERTY IMPORTED_LOCATION "${SWIFT_SDK_${sdk}_PUBLIC_PATH}/usr/lib/swift/libswiftCore.tbd")
foreach(arch in ${SWIFT_SDK_${sdk}_ARCHITECTURES})
add_library("${swift_core_target}-${arch}" ALIAS "${swift_core_target}")
endforeach()
endforeach()

# Build the concurrency library for back deployment.
add_compile_definitions(SWIFT_CONCURRENCY_BACK_DEPLOYMENT)
set(swift_concurrency_install_component back-deployment)
set(swift_concurrency_options BACK_DEPLOYMENT_LIBRARY 5.5)

add_subdirectory(../Concurrency stdlib/public/BackDeployConcurrency)
16 changes: 12 additions & 4 deletions stdlib/public/Concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
set(LLVM_OPTIONAL_SOURCES
${swift_concurrency_objc_sources})

set(swift_concurrency_link_libraries
swiftCore)
if (SWIFT_ALLOW_BACK_DEPLOY_CONCURRENCY OR BUILD_SWIFT_CONCURRENCY_BACK_DEPLOYMENT_LIBRARIES)
set(swift_concurrency_availability "macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0")
else()
set(swift_concurrency_availability "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0")
endif()

if(NOT swift_concurrency_install_component)
set(swift_concurrency_install_component stdlib)
endif()

if(SWIFT_CONCURRENCY_USES_DISPATCH)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
Expand Down Expand Up @@ -95,7 +102,8 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
-parse-stdlib
-Xfrontend -enable-experimental-concurrency
-Xfrontend -define-availability
-Xfrontend \"SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0\"
-Xfrontend "SwiftStdlib 5.5:${swift_concurrency_availability}"
LINK_FLAGS "${SWIFT_RUNTIME_CONCURRENCY_SWIFT_LINK_FLAGS}"
INSTALL_IN_COMPONENT stdlib
${swift_concurrency_options}
INSTALL_IN_COMPONENT ${swift_concurrency_install_component}
)
9 changes: 8 additions & 1 deletion stdlib/public/Distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
set(swift_distributed_link_libraries
swiftCore)


if (SWIFT_ALLOW_BACK_DEPLOY_CONCURRENCY)
set(swift_concurrency_availability "macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0")
else()
set(swift_concurrency_availability "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0")
endif()

add_swift_target_library(swift_Distributed ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
AssertDistributed.swift
ActorTransport.swift
Expand All @@ -34,7 +41,7 @@ add_swift_target_library(swift_Distributed ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
-parse-stdlib
-Xfrontend -enable-experimental-distributed
-Xfrontend -define-availability
-Xfrontend \"SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0\"
-Xfrontend "SwiftStdlib 5.5:${swift_concurrency_availability}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

SWIFT_MODULE_DEPENDS _Concurrency
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ normalize_boolean_spelling(SWIFT_BUILD_SYNTAXPARSERLIB)
normalize_boolean_spelling(SWIFT_ENABLE_SOURCEKIT_TESTS)
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY)
normalize_boolean_spelling(SWIFT_ALLOW_BACK_DEPLOY_CONCURRENCY)
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED)
is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED)

Expand Down Expand Up @@ -358,6 +359,10 @@ foreach(SDK ${SWIFT_SDKS})
list(APPEND LIT_ARGS "--param" "concurrency")
endif()

if(SWIFT_ALLOW_BACK_DEPLOY_CONCURRENCY)
list(APPEND LIT_ARGS "--param" "back_deploy_concurrency")
endif()

if(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED)
list(APPEND LIT_ARGS "--param" "distributed")
endif()
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/concurrency_availability.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -parse-stdlib -target x86_64-apple-macosx10.15 -typecheck -verify %s
// RUN: %target-swift-frontend -parse-stdlib -target x86_64-apple-macosx10.14 -typecheck -verify %s
// RUN: %target-swift-frontend -parse-stdlib -target x86_64-apple-macosx12 -typecheck %s
// REQUIRES: OS=macosx

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/async/weak_availability.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-implicit-dynamic -target %target-cpu-apple-macosx11 -Onone -emit-ir %s | %FileCheck --check-prefix=MAYBE-AVAILABLE %s
// RUN: %target-swift-frontend -enable-implicit-dynamic -target %target-cpu-apple-macosx10.14 -Onone -emit-ir %s | %FileCheck --check-prefix=MAYBE-AVAILABLE %s
// REQUIRES: OS=macosx && CPU=x86_64

@available(macOS 12.0, *)
Expand Down
Loading