Skip to content

Commit 0b73826

Browse files
committed
[Apple Silicon] [Build] Filter out any architectures that are unsupported by the SDKs
1 parent e5d11ff commit 0b73826

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,38 @@ function(_report_sdk prefix)
8585
message(STATUS "")
8686
endfunction()
8787

88+
# Remove architectures not supported by the SDK from the given list.
89+
function(remove_sdk_unsupported_archs name os sdk_path architectures_var)
90+
execute_process(COMMAND
91+
/usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
92+
OUTPUT_VARIABLE sdk_supported_archs
93+
RESULT_VARIABLE plist_error)
94+
95+
if (NOT plist_error EQUAL 0)
96+
message(STATUS "${os} SDK at ${sdk_path} does not publish its supported architectures")
97+
return()
98+
endif()
99+
100+
set(architectures)
101+
foreach(arch ${${architectures_var}})
102+
if(sdk_supported_archs MATCHES "${arch}\n")
103+
list(APPEND architectures ${arch})
104+
elseif(arch MATCHES "^armv7(s)?$" AND os STREQUAL "iphoneos")
105+
# 32-bit iOS is not listed explicitly in SDK settings.
106+
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
107+
list(APPEND architectures ${arch})
108+
elseif(arch STREQUAL "i386" AND os STREQUAL "iphonesimulator")
109+
# 32-bit iOS simulatoris not listed explicitly in SDK settings.
110+
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
111+
list(APPEND architectures ${arch})
112+
else()
113+
message(STATUS "${name} SDK at ${sdk_path} does not support architecture ${arch}")
114+
endif()
115+
endforeach()
116+
117+
set("${architectures_var}" ${architectures} PARENT_SCOPE)
118+
endfunction()
119+
88120
# Configure an SDK
89121
#
90122
# Usage:
@@ -164,6 +196,9 @@ macro(configure_sdk_darwin
164196
SWIFT_SDK_${prefix}_ARCHITECTURES) # result
165197
endif()
166198

199+
# Remove any architectures not supported by the SDK.
200+
remove_sdk_unsupported_archs(${name} ${xcrun_name} ${SWIFT_SDK_${prefix}_PATH} SWIFT_SDK_${prefix}_ARCHITECTURES)
201+
167202
list_intersect(
168203
"${SWIFT_DARWIN_MODULE_ARCHS}" # lhs
169204
"${architectures}" # rhs

utils/build-script

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,19 @@ def apply_default_arguments(toolchain, args):
350350
target.arch in supported_archs)
351351
]
352352

353+
# Filter out any macOS stdlib deployment targets that are not supported
354+
# by the macOS SDK.
355+
if platform.system() == "Darwin":
356+
targets = StdlibDeploymentTarget.get_targets_by_name(
357+
args.stdlib_deployment_targets)
358+
args.stdlib_deployment_targets = [
359+
target.name
360+
for target in targets
361+
if (target.platform.is_darwin and
362+
target.platform.sdk_supports_architecture(
363+
target.arch, args.darwin_xcrun_toolchain))
364+
]
365+
353366
# Include the Darwin module-only architectures in the CMake options.
354367
if args.swift_darwin_module_archs:
355368
args.extra_cmake_options.append(

utils/swift_build_support/swift_build_support/host_specific_configuration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def __init__(self, host_target, args):
4141
stdlib_targets_to_configure = [host_target]
4242
stdlib_targets_to_build = set(stdlib_targets_to_configure)
4343

44-
if args.stdlib_deployment_targets == []:
44+
if (hasattr(args, 'stdlib_deployment_targets') and
45+
args.stdlib_deployment_targets == []):
4546
stdlib_targets_to_configure = []
4647
stdlib_targets_to_build = []
4748

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
import os
1212
import platform
1313

14+
from . import shell
15+
16+
try:
17+
from build_swift.build_swift.wrappers import xcrun
18+
except ImportError:
19+
from build_swift.wrappers import xcrun
20+
1421

1522
class Platform(object):
1623
"""
@@ -86,6 +93,39 @@ def uses_host_tests(self):
8693
"""
8794
return self.is_embedded and not self.is_simulator
8895

96+
def sdk_supports_architecture(self, arch, toolchain):
97+
"""
98+
Convenience function for checking whether the SDK supports the
99+
target architecture.
100+
"""
101+
102+
# The names match up with the xcrun SDK names.
103+
xcrun_sdk_name = self.name
104+
105+
# 32-bit iOS and iOS simulator are supported, but are not covered
106+
# by the SDK settings. Handle this special case here.
107+
if (xcrun_sdk_name == 'iphoneos' and
108+
(arch == 'armv7' or arch == 'armv7s')):
109+
return True
110+
111+
if (xcrun_sdk_name == 'iphonesimulator' and arch == 'i386'):
112+
return True
113+
114+
sdk_path = xcrun.sdk_path(sdk=xcrun_sdk_name, toolchain=toolchain)
115+
if not sdk_path:
116+
raise RuntimeError('Cannot find SDK path for %s' % xcrun_sdk_name)
117+
118+
# Find the SDKSettings.plist for this sdK
119+
plistCommand = [
120+
'/usr/libexec/PlistBuddy',
121+
'-c',
122+
'Print :SupportedTargets:%s:Archs' % (self.name),
123+
'%s/SDKSettings.plist' % (sdk_path)
124+
]
125+
126+
sdk_archs = shell.capture(plistCommand, dry_run=False, echo=True)
127+
return arch in sdk_archs
128+
89129

90130
class AndroidPlatform(Platform):
91131
@property

0 commit comments

Comments
 (0)