Skip to content

Commit bd289bd

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 4f48d5e + 8db65b3 commit bd289bd

File tree

8 files changed

+166
-10
lines changed

8 files changed

+166
-10
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ option(SWIFT_STDLIB_ENABLE_SIB_TARGETS
223223
"Should we generate sib targets for the stdlib or not?"
224224
FALSE)
225225

226+
227+
set(SWIFT_DARWIN_SUPPORTED_ARCHS "" CACHE STRING
228+
"Semicolon-separated list of architectures to configure on Darwin platforms. \
229+
If left empty all default architectures are configured.")
230+
231+
set(SWIFT_DARWIN_MODULE_ARCHS "" CACHE STRING
232+
"Semicolon-separated list of architectures to configure Swift module-only \
233+
targets on Darwin platforms. These targets are in addition to the full \
234+
library targets.")
235+
236+
226237
#
227238
# User-configurable Android specific options.
228239
#

cmake/modules/AddSwift.cmake

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,17 @@ function(_add_swift_library_single target name)
927927
endif()
928928
endif()
929929

930+
# Only build the modules for any arch listed in the *_MODULE_ARCHITECTURES.
931+
if(SWIFTLIB_SINGLE_SDK IN_LIST SWIFT_APPLE_PLATFORMS
932+
AND SWIFTLIB_SINGLE_ARCHITECTURE IN_LIST SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_MODULE_ARCHITECTURES)
933+
# Create dummy target to hook up the module target dependency.
934+
add_custom_target("${target}"
935+
DEPENDS
936+
"${swift_module_dependency_target}")
937+
938+
return()
939+
endif()
940+
930941
set(SWIFTLIB_INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS)
931942
foreach(object_library ${SWIFTLIB_SINGLE_INCORPORATE_OBJECT_LIBRARIES})
932943
list(APPEND SWIFTLIB_INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS
@@ -1846,8 +1857,13 @@ function(add_swift_target_library name)
18461857
list(APPEND swiftlib_link_flags_all "-Wl,-z,defs")
18471858
endif()
18481859

1860+
set(sdk_supported_archs
1861+
${SWIFT_SDK_${sdk}_ARCHITECTURES}
1862+
${SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES})
1863+
list(REMOVE_DUPLICATES sdk_supported_archs)
1864+
18491865
# For each architecture supported by this SDK
1850-
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
1866+
foreach(arch ${sdk_supported_archs})
18511867
# Configure variables for this subdirectory.
18521868
set(VARIANT_SUFFIX "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
18531869
set(VARIANT_NAME "${name}${VARIANT_SUFFIX}")
@@ -1969,11 +1985,38 @@ function(add_swift_target_library name)
19691985
endforeach()
19701986
endif()
19711987

1972-
# Note this thin library.
1973-
list(APPEND THIN_INPUT_TARGETS ${VARIANT_NAME})
1988+
if(arch IN_LIST SWIFT_SDK_${sdk}_ARCHITECTURES)
1989+
# Note this thin library.
1990+
list(APPEND THIN_INPUT_TARGETS ${VARIANT_NAME})
1991+
endif()
19741992
endif()
19751993
endforeach()
19761994

1995+
# Configure module-only targets
1996+
if(NOT SWIFT_SDK_${sdk}_ARCHITECTURES
1997+
AND SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES)
1998+
set(_target "${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
1999+
2000+
# Create unified sdk target
2001+
add_custom_target("${_target}")
2002+
2003+
foreach(_arch ${SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES})
2004+
set(_variant_suffix "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${_arch}")
2005+
set(_module_variant_name "${name}-swiftmodule-${_variant_suffix}")
2006+
2007+
add_dependencies("${_target}" ${_module_variant_name})
2008+
2009+
# Add Swift standard library targets as dependencies to the top-level
2010+
# convenience target.
2011+
if(TARGET "swift-stdlib${_variant_suffix}")
2012+
add_dependencies("swift-stdlib${_variant_suffix}"
2013+
"${_target}")
2014+
endif()
2015+
endforeach()
2016+
2017+
return()
2018+
endif()
2019+
19772020
if(NOT SWIFTLIB_OBJECT_LIBRARY)
19782021
# Determine the name of the universal library.
19792022
if(SWIFTLIB_SHARED)
@@ -2064,12 +2107,35 @@ function(add_swift_target_library name)
20642107
endforeach()
20652108
endif()
20662109

2067-
swift_is_installing_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" is_installing)
2068-
if(NOT is_installing)
2069-
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${VARIANT_NAME})
2070-
else()
2071-
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${VARIANT_NAME})
2072-
endif()
2110+
swift_is_installing_component(
2111+
"${SWIFTLIB_INSTALL_IN_COMPONENT}"
2112+
is_installing)
2113+
2114+
# Add the arch-specific library targets to the global exports.
2115+
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
2116+
set(_variant_name "${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
2117+
if(NOT TARGET "${_variant_name}")
2118+
continue()
2119+
endif()
2120+
2121+
if(is_installing)
2122+
set_property(GLOBAL APPEND
2123+
PROPERTY SWIFT_EXPORTS ${_variant_name})
2124+
else()
2125+
set_property(GLOBAL APPEND
2126+
PROPERTY SWIFT_BUILDTREE_EXPORTS ${_variant_name})
2127+
endif()
2128+
endforeach()
2129+
2130+
# Add the swiftmodule-only targets to the lipo target depdencies.
2131+
foreach(arch ${SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES})
2132+
set(_variant_name "${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
2133+
if(NOT TARGET "${_variant_name}")
2134+
continue()
2135+
endif()
2136+
2137+
add_dependencies("${lipo_target}" "${_variant_name}")
2138+
endforeach()
20732139

20742140
# If we built static variants of the library, create a lipo target for
20752141
# them.

cmake/modules/StandaloneOverlay.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ option(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES
6565
set(SWIFT_STDLIB_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
6666
"Build type for the Swift standard library and SDK overlays.")
6767

68+
set(SWIFT_DARWIN_SUPPORTED_ARCHS "" CACHE STRING
69+
"Semicolon-separated list of architectures to configure on Darwin platforms. \
70+
If left empty all default architectures are configured.")
71+
72+
set(SWIFT_DARWIN_MODULE_ARCHS "" CACHE STRING
73+
"Semicolon-separated list of architectures to configure Swift module-only \
74+
targets on Darwin platforms. These targets are in addition to the full \
75+
library targets.")
76+
77+
6878
# -----------------------------------------------------------------------------
6979
# Constants
7080

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ function(_report_sdk prefix)
5151
message(STATUS " Triple name: ${SWIFT_SDK_${prefix}_TRIPLE_NAME}")
5252
endif()
5353
message(STATUS " Architectures: ${SWIFT_SDK_${prefix}_ARCHITECTURES}")
54+
if(SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES)
55+
message(STATUS " Module Architectures: ${SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES}")
56+
endif()
5457
if(NOT prefix IN_LIST SWIFT_APPLE_PLATFORMS)
5558
if(SWIFT_BUILD_STDLIB)
5659
foreach(arch ${SWIFT_SDK_${prefix}_ARCHITECTURES})
@@ -141,9 +144,30 @@ macro(configure_sdk_darwin
141144
set(SWIFT_SDK_${prefix}_LIB_SUBDIR "${xcrun_name}")
142145
set(SWIFT_SDK_${prefix}_VERSION_MIN_NAME "${version_min_name}")
143146
set(SWIFT_SDK_${prefix}_TRIPLE_NAME "${triple_name}")
144-
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
145147
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "MACHO")
146148

149+
set(SWIFT_SDK_${prefix}_ARCHITECTURES ${architectures})
150+
if(SWIFT_DARWIN_SUPPORTED_ARCHS)
151+
list_intersect(
152+
"${architectures}" # lhs
153+
"${SWIFT_DARWIN_SUPPORTED_ARCHS}" # rhs
154+
SWIFT_SDK_${prefix}_ARCHITECTURES) # result
155+
endif()
156+
157+
list_intersect(
158+
"${SWIFT_DARWIN_MODULE_ARCHS}" # lhs
159+
"${architectures}" # rhs
160+
SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES) # result
161+
162+
# Ensure the architectures and module-only architectures lists are mutually
163+
# exclusive.
164+
list_subtract(
165+
"${SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES}" # lhs
166+
"${SWIFT_SDK_${prefix}_ARCHITECTURES}" # rhs
167+
SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES) # result
168+
169+
# Configure variables for _all_ architectures even if we aren't "building"
170+
# them because they aren't supported.
147171
foreach(arch ${architectures})
148172
# On Darwin, all archs share the same SDK path.
149173
set(SWIFT_SDK_${prefix}_ARCH_${arch}_PATH "${SWIFT_SDK_${prefix}_PATH}")

utils/build-script

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,31 @@ class BuildScriptInvocation(object):
189189
args.android = True
190190
args.build_android = False
191191

192+
# Include the Darwin supported architectures in the CMake options.
193+
if args.swift_darwin_supported_archs:
194+
args.extra_cmake_options.append(
195+
'-DSWIFT_DARWIN_SUPPORTED_ARCHS:STRING={}'.format(
196+
args.swift_darwin_supported_archs))
197+
198+
# Remove unsupported Darwin archs from the standard library
199+
# deployment targets.
200+
supported_archs = args.swift_darwin_supported_archs.split(';')
201+
targets = StdlibDeploymentTarget.get_targets_by_name(
202+
args.stdlib_deployment_targets)
203+
204+
args.stdlib_deployment_targets = [
205+
target.name
206+
for target in targets
207+
if (target.platform.is_darwin and
208+
target.arch in supported_archs)
209+
]
210+
211+
# Include the Darwin module-only architectures in the CMake options.
212+
if args.swift_darwin_module_archs:
213+
args.extra_cmake_options.append(
214+
'-DSWIFT_DARWIN_MODULE_ARCHS:STRING={}'.format(
215+
args.swift_darwin_module_archs))
216+
192217
# ---
193218

194219
def __init__(self, toolchain, args):

utils/build_swift/driver_arguments.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,18 @@ def create_argument_parser():
522522
help='A space-separated list that filters which of the configured '
523523
'targets to build the Swift standard library for, or "all".')
524524

525+
option('--swift-darwin-supported-archs', store,
526+
metavar='ARCHS',
527+
help='Semicolon-separated list of architectures to configure on '
528+
'Darwin platforms. If left empty all default architectures '
529+
'are configured.')
530+
531+
option('--swift-darwin-module-archs', store,
532+
metavar='ARCHS',
533+
help='Semicolon-separated list of architectures to configure Swift '
534+
'module-only targets on Darwin platforms. These targets are '
535+
'in addition to the full library targets.')
536+
525537
# -------------------------------------------------------------------------
526538
in_group('Options to select projects')
527539

utils/build_swift/tests/expected_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@
171171
'swift_assertions': True,
172172
'swift_build_variant': 'Debug',
173173
'swift_compiler_version': None,
174+
'swift_darwin_module_archs': None,
175+
'swift_darwin_supported_archs': None,
174176
'swift_stdlib_assertions': True,
175177
'swift_stdlib_build_variant': 'Debug',
176178
'swift_tools_max_parallel_lto_link_jobs':
@@ -533,6 +535,8 @@ class IgnoreOption(_BaseOption):
533535
StrOption('--host-target'),
534536
StrOption('--lit-args'),
535537
StrOption('--llvm-targets-to-build'),
538+
StrOption('--swift-darwin-module-archs'),
539+
StrOption('--swift-darwin-supported-archs'),
536540

537541
PathOption('--android-deploy-device-path'),
538542
PathOption('--android-icu-i18n'),

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ def default_stdlib_deployment_targets():
258258
def get_target_for_name(cls, name):
259259
return cls._targets_by_name.get(name)
260260

261+
@classmethod
262+
def get_targets_by_name(cls, names):
263+
return [cls.get_target_for_name(name) for name in names]
264+
261265

262266
def install_prefix():
263267
"""

0 commit comments

Comments
 (0)