Skip to content

Commit dd91bc2

Browse files
committed
Install compatibility archive alongside shared libraries.
Although it's a static archive, its use is only relevant to dynamically linked builds of the standard library. (If you're statically linking a Swift runtime into your process, you don't need to worry about compatibility with older runtimes.)
1 parent 6442f3e commit dd91bc2

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ function(_add_swift_library_single target name)
730730
OBJECT_LIBRARY
731731
SHARED
732732
STATIC
733-
TARGET_LIBRARY)
733+
TARGET_LIBRARY
734+
INSTALL_WITH_SHARED)
734735
set(SWIFTLIB_SINGLE_single_parameter_options
735736
ARCHITECTURE
736737
DEPLOYMENT_VERSION_IOS
@@ -1085,18 +1086,24 @@ function(_add_swift_library_single target name)
10851086
BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR}
10861087
LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR})
10871088

1089+
if(SWIFTLIB_INSTALL_WITH_SHARED)
1090+
set(swift_lib_dir ${SWIFTLIB_DIR})
1091+
else()
1092+
set(swift_lib_dir ${SWIFTSTATICLIB_DIR})
1093+
endif()
1094+
10881095
foreach(config ${CMAKE_CONFIGURATION_TYPES})
10891096
string(TOUPPER ${config} config_upper)
10901097
escape_path_for_xcode(
1091-
"${config}" "${SWIFTSTATICLIB_DIR}" config_lib_dir)
1098+
"${config}" "${swift_lib_dir}" config_lib_dir)
10921099
set_target_properties(${target_static} PROPERTIES
10931100
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}
10941101
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR})
10951102
endforeach()
10961103

10971104
set_target_properties(${target_static} PROPERTIES
1098-
LIBRARY_OUTPUT_DIRECTORY ${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}
1099-
ARCHIVE_OUTPUT_DIRECTORY ${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR})
1105+
LIBRARY_OUTPUT_DIRECTORY ${swift_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}
1106+
ARCHIVE_OUTPUT_DIRECTORY ${swift_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR})
11001107
endif()
11011108

11021109
set_target_properties(${target}
@@ -1347,8 +1354,14 @@ function(_add_swift_library_single target name)
13471354
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY
13481355
COMPILE_FLAGS " ${c_compile_flags}")
13491356
# FIXME: The fallback paths here are going to be dynamic libraries.
1357+
1358+
if(SWIFTLIB_INSTALL_WITH_SHARED)
1359+
set(search_base_dir ${SWIFTLIB_DIR})
1360+
else()
1361+
set(search_base_dir ${SWIFTSTATICLIB_DIR})
1362+
endif()
13501363
set(library_search_directories
1351-
"${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}"
1364+
"${search_base_dir}/${SWIFTLIB_SINGLE_SUBDIR}"
13521365
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"
13531366
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
13541367
swift_target_link_search_directories("${target_static}" "${library_search_directories}")
@@ -1477,6 +1490,7 @@ endfunction()
14771490
# [IS_STDLIB]
14781491
# [IS_STDLIB_CORE]
14791492
# [TARGET_LIBRARY]
1493+
# [INSTALL_WITH_SHARED]
14801494
# INSTALL_IN_COMPONENT comp
14811495
# DEPLOYMENT_VERSION_OSX version
14821496
# DEPLOYMENT_VERSION_IOS version
@@ -1583,6 +1597,9 @@ endfunction()
15831597
# DEPLOYMENT_VERSION_WATCHOS
15841598
# The minimum deployment version to build for if this is an WATCHOS library.
15851599
#
1600+
# INSTALL_WITH_SHARED
1601+
# Install a static library target alongside shared libraries
1602+
#
15861603
# source1 ...
15871604
# Sources to add into this library.
15881605
function(add_swift_target_library name)
@@ -1597,7 +1614,8 @@ function(add_swift_target_library name)
15971614
OBJECT_LIBRARY
15981615
SHARED
15991616
STATIC
1600-
TARGET_LIBRARY)
1617+
TARGET_LIBRARY
1618+
INSTALL_WITH_SHARED)
16011619
set(SWIFTLIB_single_parameter_options
16021620
DEPLOYMENT_VERSION_IOS
16031621
DEPLOYMENT_VERSION_OSX
@@ -1882,6 +1900,7 @@ function(add_swift_target_library name)
18821900
${SWIFTLIB_SHARED_keyword}
18831901
${SWIFTLIB_STATIC_keyword}
18841902
${SWIFTLIB_OBJECT_LIBRARY_keyword}
1903+
${SWIFTLIB_INSTALL_WITH_SHARED_keyword}
18851904
${SWIFTLIB_SOURCES}
18861905
MODULE_TARGET ${MODULE_VARIANT_NAME}
18871906
SDK ${sdk}
@@ -1996,7 +2015,7 @@ function(add_swift_target_library name)
19962015
set(resource_dir_sdk_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
19972016
precondition(resource_dir_sdk_subdir)
19982017

1999-
if(SWIFTLIB_SHARED)
2018+
if(SWIFTLIB_SHARED OR SWIFTLIB_INSTALL_WITH_SHARED)
20002019
set(resource_dir "swift")
20012020
set(file_permissions
20022021
OWNER_READ OWNER_WRITE OWNER_EXECUTE
@@ -2058,10 +2077,18 @@ function(add_swift_target_library name)
20582077
list(APPEND THIN_INPUT_TARGETS_STATIC "${TARGET}-static")
20592078
endforeach()
20602079

2080+
if(SWIFTLIB_INSTALL_WITH_SHARED)
2081+
set(install_subdir "swift")
2082+
set(universal_subdir ${SWIFTLIB_DIR})
2083+
else()
2084+
set(install_subdir "swift_static")
2085+
set(universal_subdir ${SWIFTSTATICLIB_DIR})
2086+
endif()
2087+
20612088
set(lipo_target_static
20622089
"${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-static")
20632090
set(UNIVERSAL_LIBRARY_NAME
2064-
"${SWIFTSTATICLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
2091+
"${universal_subdir}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
20652092
_add_swift_lipo_target(SDK
20662093
${sdk}
20672094
TARGET
@@ -2070,7 +2097,7 @@ function(add_swift_target_library name)
20702097
"${UNIVERSAL_LIBRARY_NAME}"
20712098
${THIN_INPUT_TARGETS_STATIC})
20722099
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
2073-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}"
2100+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${install_subdir}/${resource_dir_sdk_subdir}"
20742101
PERMISSIONS
20752102
OWNER_READ OWNER_WRITE
20762103
GROUP_READ
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
set(swift_runtime_compile_flags ${SWIFT_RUNTIME_CORE_CXX_FLAGS})
22
set(swift_runtime_linker_flags ${SWIFT_RUNTIME_CORE_LINK_FLAGS})
33

4-
add_swift_target_library(swiftCompatibility50 TARGET_LIBRARY STATIC
4+
add_swift_target_library(swiftCompatibility50 TARGET_LIBRARY STATIC INSTALL_WITH_SHARED
55
ProtocolConformance.cpp
66
Overrides.cpp
77
C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}
88
LINK_FLAGS ${swift_runtime_linker_flags}
99
TARGET_SDKS ${SWIFT_APPLE_PLATFORMS}
1010
INSTALL_IN_COMPONENT compiler)
11+
12+

0 commit comments

Comments
 (0)