Skip to content

Commit 0b6790c

Browse files
committed
SDK Autodetection now happens in build script
The old 'swift-sdks' option is migrated for presets
1 parent 9d822cd commit 0b6790c

File tree

5 files changed

+164
-104
lines changed

5 files changed

+164
-104
lines changed

CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,11 @@ function(is_sdk_requested name result_var_name)
469469
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${name}")
470470
set("${result_var_name}" "TRUE" PARENT_SCOPE)
471471
else()
472-
if("${SWIFT_SDKS}" STREQUAL "")
473-
set("${result_var_name}" "TRUE" PARENT_SCOPE)
472+
list(FIND SWIFT_SDKS "${name}" sdk_index)
473+
if(${sdk_index} EQUAL -1)
474+
set("${result_var_name}" "FALSE" PARENT_SCOPE)
474475
else()
475-
list(FIND SWIFT_SDKS "${name}" sdk_index)
476-
if(${sdk_index} EQUAL -1)
477-
set("${result_var_name}" "FALSE" PARENT_SCOPE)
478-
else()
479-
set("${result_var_name}" "TRUE" PARENT_SCOPE)
480-
endif()
476+
set("${result_var_name}" "TRUE" PARENT_SCOPE)
481477
endif()
482478
endif()
483479
endfunction()

utils/SwiftBuildSupport.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,35 @@ def get_preset_options(substitutions, preset_file_names, preset_name):
194194
"': " + ", ".join(missing_opts))
195195
sys.exit(1)
196196

197+
# Migrate 'swift-sdks' parameter to 'stdlib-deployment-targets'
198+
for opt in build_script_impl_opts:
199+
if opt.startswith("--swift-sdks"):
200+
sdksToConfigure = opt.split("=")[1].split(";")
201+
tgts = []
202+
# Expand SDKs in to their deployment targets
203+
from swift_build_support.targets import StdlibDeploymentTarget
204+
for sdk in sdksToConfigure:
205+
if sdk == "OSX":
206+
tgts += StdlibDeploymentTarget.OSX.allArchs
207+
elif sdk == "IOS":
208+
tgts += StdlibDeploymentTarget.iOS.allArchs
209+
elif sdk == "IOS_SIMULATOR":
210+
tgts += StdlibDeploymentTarget.iOSSimulator.allArchs
211+
elif sdk == "TVOS":
212+
tgts += StdlibDeploymentTarget.AppleTV.allArchs
213+
elif sdk == "TVOS_SIMULATOR":
214+
tgts += StdlibDeploymentTarget.AppleTVSimulator.allArchs
215+
elif sdk == "WATCHOS":
216+
tgts += StdlibDeploymentTarget.AppleWatch.allArchs
217+
elif sdk == "WATCHOS_SIMULATOR":
218+
tgts += StdlibDeploymentTarget.AppleWatchSimulator.allArchs
219+
220+
build_script_opts.append("--stdlib-deployment-targets=" +
221+
" ".join(tgts))
222+
# Filter the swift-sdks parameter
223+
build_script_impl_opts = [opt for opt in build_script_impl_opts
224+
if not opt.startswith("--swift-sdks")]
225+
197226
return build_script_opts + ["--"] + build_script_impl_opts
198227

199228

utils/build-script

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ from swift_build_support import products # noqa (E402)
4747
from swift_build_support import shell # noqa (E402)
4848
import swift_build_support.tar # noqa (E402)
4949
import swift_build_support.targets # noqa (E402)
50+
from swift_build_support.targets import StdlibDeploymentTarget # noqa (E402)
5051
from swift_build_support.cmake import CMake # noqa (E402)
5152
from swift_build_support.workspace import Workspace # noqa(E402)
5253
from swift_build_support.workspace import compute_build_subdir # noqa(E402)
@@ -353,13 +354,13 @@ details of the setups of other systems or automated environments.""")
353354
help="The host target. LLVM, Clang, and Swift will be built for this "
354355
"target. The built LLVM and Clang will be used to compile Swift "
355356
"for the cross-compilation targets.",
356-
default=swift_build_support.targets.host_target())
357+
default=StdlibDeploymentTarget.host_target())
357358
targets_group.add_argument(
358359
"--stdlib-deployment-targets",
359360
help="list of targets to compile or cross-compile the Swift standard "
360361
"library for. %(default)s by default.",
361362
nargs="*",
362-
default=swift_build_support.targets.stdlib_deployment_targets())
363+
default=StdlibDeploymentTarget.default_stdlib_deployment_targets())
363364

364365
projects_group = parser.add_argument_group(
365366
title="Options to select projects")
@@ -1226,6 +1227,11 @@ details of the setups of other systems or automated environments.""")
12261227
if args.build_subdir is None:
12271228
args.build_subdir = compute_build_subdir(args)
12281229

1230+
# Add optional stdlib-deployment-targets
1231+
if args.android:
1232+
args.stdlib_deployment_targets.append(
1233+
StdlibDeploymentTarget.Android.armv7)
1234+
12291235
workspace = Workspace(
12301236
source_root=SWIFT_SOURCE_ROOT,
12311237
build_root=os.path.join(SWIFT_BUILD_ROOT, args.build_subdir))

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 121 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,98 +12,127 @@
1212
import platform
1313

1414

15-
def host_target():
16-
"""
17-
Return the build target for the current host machine, if it is one of the
18-
recognized targets. Otherwise, return None.
19-
"""
20-
system = platform.system()
21-
machine = platform.machine()
22-
23-
if system == 'Linux':
24-
if machine == 'x86_64':
25-
return 'linux-x86_64'
26-
elif machine.startswith('armv7'):
27-
# linux-armv7* is canonicalized to 'linux-armv7'
28-
return 'linux-armv7'
29-
elif machine.startswith('armv6'):
30-
# linux-armv6* is canonicalized to 'linux-armv6'
31-
return 'linux-armv6'
32-
elif machine == 'aarch64':
33-
return 'linux-aarch64'
34-
elif machine == 'ppc64':
35-
return 'linux-powerpc64'
36-
elif machine == 'ppc64le':
37-
return 'linux-powerpc64le'
38-
elif machine == 's390x':
39-
return 'linux-s390x'
40-
41-
elif system == 'Darwin':
42-
if machine == 'x86_64':
43-
return 'macosx-x86_64'
44-
45-
elif system == 'FreeBSD':
46-
if machine == 'amd64':
47-
return 'freebsd-x86_64'
48-
49-
elif system == 'CYGWIN_NT-10.0':
50-
if machine == 'x86_64':
51-
return 'cygwin-x86_64'
52-
53-
return None
54-
55-
56-
def stdlib_deployment_targets():
57-
"""
58-
Return deployment targets for the Swift stdlib, based on the host machine.
59-
If the host machine is not one of the recognized ones, return None.
60-
"""
61-
system = platform.system()
62-
machine = platform.machine()
63-
64-
if system == 'Linux':
65-
if machine == 'x86_64':
66-
return [
67-
'linux-x86_64',
68-
'android-armv7',
69-
]
70-
elif machine.startswith('armv6'):
71-
# linux-armv6* is canonicalized to 'linux-armv6'
72-
return ['linux-armv6']
73-
elif machine.startswith('armv7'):
74-
# linux-armv7* is canonicalized to 'linux-armv7'
75-
return ['linux-armv7']
76-
elif machine == 'aarch64':
77-
return ['linux-aarch64']
78-
elif machine == 'ppc64':
79-
return ['linux-powerpc64']
80-
elif machine == 'ppc64le':
81-
return ['linux-powerpc64le']
82-
elif machine == 's390x':
83-
return ['linux-s390x']
84-
elif system == 'Darwin':
85-
if machine == 'x86_64':
86-
return [
87-
'macosx-x86_64',
88-
'iphonesimulator-i386',
89-
'iphonesimulator-x86_64',
90-
'appletvsimulator-x86_64',
91-
'watchsimulator-i386',
92-
# Put iOS native targets last so that we test them last
93-
# (it takes a long time).
94-
'iphoneos-arm64',
95-
'iphoneos-armv7',
96-
'appletvos-arm64',
97-
'watchos-armv7k',
98-
]
99-
elif system == 'FreeBSD':
100-
if machine == 'amd64':
101-
return ['freebsd-x86_64']
102-
elif system == 'CYGWIN_NT-10.0':
103-
if machine == 'x86_64':
104-
return ['cygwin-x86_64']
105-
106-
return None
15+
class StdlibDeploymentTarget(object):
16+
17+
class OSX(object):
18+
x86_64 = 'macosx-x86_64'
19+
allArchs = [x86_64]
20+
21+
class iOS(object):
22+
armv7 = 'iphoneos-armv7'
23+
armv7s = 'iphoneos-armv7s'
24+
arm64 = 'iphoneos-arm64'
25+
allArchs = [armv7, armv7s, arm64]
26+
27+
class iOSSimulator(object):
28+
i386 = 'iphonesimulator-i386'
29+
x86_64 = 'iphonesimulator-x86_64'
30+
allArchs = [i386, x86_64]
31+
32+
class AppleTV(object):
33+
arm64 = 'appletvos-arm64'
34+
allArchs = [arm64]
35+
36+
class AppleTVSimulator(object):
37+
x86_64 = 'appletvsimulator-x86_64'
38+
allArchs = [x86_64]
39+
40+
class AppleWatch(object):
41+
armv7k = 'watchos-armv7k'
42+
allArchs = [armv7k]
43+
44+
class AppleWatchSimulator(object):
45+
i386 = 'watchsimulator-i386'
46+
allArchs = [i386]
47+
48+
class Linux(object):
49+
x86_64 = 'linux-x86_64'
50+
armv6 = 'linux-armv6'
51+
armv7 = 'linux-armv7'
52+
aarch64 = 'linux-aarch64'
53+
ppc64 = 'linux-ppc64'
54+
ppc64le = 'linux-ppc64le'
55+
s390x = 'linux-s390x'
56+
allArchs = [x86_64, armv6, armv7, aarch64, ppc64, ppc64le, s390x]
57+
58+
class FreeBSD(object):
59+
amd64 = 'freebsd-x86_64'
60+
allArchs = [amd64]
61+
62+
class Cygwin(object):
63+
x86_64 = 'cygwin-x86_64'
64+
allArchs = [x86_64]
65+
66+
class Android(object):
67+
armv7 = 'android-armv7'
68+
allArchs = [armv7]
69+
70+
@staticmethod
71+
def host_target():
72+
"""
73+
Return the host target for the build machine, if it is one of
74+
the recognized targets. Otherwise, return None.
75+
"""
76+
system = platform.system()
77+
machine = platform.machine()
78+
79+
if system == 'Linux':
80+
if machine == 'x86_64':
81+
return StdlibDeploymentTarget.Linux.x86_64
82+
elif machine.startswith('armv7'):
83+
# linux-armv7* is canonicalized to 'linux-armv7'
84+
return StdlibDeploymentTarget.Linux.armv7
85+
elif machine.startswith('armv6'):
86+
# linux-armv6* is canonicalized to 'linux-armv6'
87+
return StdlibDeploymentTarget.Linux.armv6
88+
elif machine == 'aarch64':
89+
return StdlibDeploymentTarget.Linux.aarch64
90+
elif machine == 'ppc64':
91+
return StdlibDeploymentTarget.Linux.ppc64
92+
elif machine == 'ppc64le':
93+
return StdlibDeploymentTarget.Linux.ppc64le
94+
elif machine == 's390x':
95+
return StdlibDeploymentTarget.Linux.s390x
96+
97+
elif system == 'Darwin':
98+
if machine == 'x86_64':
99+
return StdlibDeploymentTarget.OSX.x86_64
100+
101+
elif system == 'FreeBSD':
102+
if machine == 'amd64':
103+
return StdlibDeploymentTarget.FreeBSD.amd64
104+
105+
elif system == 'CYGWIN_NT-10.0':
106+
if machine == 'x86_64':
107+
return StdlibDeploymentTarget.Cygwin.x86_64
108+
109+
return None
110+
111+
@staticmethod
112+
def default_stdlib_deployment_targets():
113+
"""
114+
Return targets for the Swift stdlib, based on the build machine.
115+
If the build machine is not one of the recognized ones, return None.
116+
"""
117+
118+
host_target = StdlibDeploymentTarget.host_target()
119+
if host_target is None:
120+
return None
121+
122+
# OSX build machines configure all Darwin platforms by default.
123+
# Put iOS native targets last so that we test them last
124+
# (it takes a long time).
125+
if host_target == StdlibDeploymentTarget.OSX.x86_64:
126+
return [host_target] + \
127+
StdlibDeploymentTarget.iOSSimulator.allArchs + \
128+
StdlibDeploymentTarget.AppleTVSimulator.allArchs + \
129+
StdlibDeploymentTarget.AppleWatchSimulator.allArchs + \
130+
StdlibDeploymentTarget.iOS.allArchs + \
131+
StdlibDeploymentTarget.AppleTV.allArchs + \
132+
StdlibDeploymentTarget.AppleWatch.allArchs
133+
else:
134+
# All other machines only configure their host stdlib by default.
135+
return [host_target]
107136

108137

109138
def install_prefix():

utils/swift_build_support/tests/test_targets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
import unittest
1212

13-
from swift_build_support.targets import host_target
13+
from swift_build_support.targets import StdlibDeploymentTarget
1414

1515

1616
class HostTargetTestCase(unittest.TestCase):
1717
def test_is_not_none_on_this_platform(self):
18-
self.assertIsNotNone(host_target())
18+
self.assertIsNotNone(StdlibDeploymentTarget.host_target())
1919

2020

2121
if __name__ == '__main__':

0 commit comments

Comments
 (0)