Skip to content

Commit bf75c8f

Browse files
committed
[build-script] Create explicit Platform and Target types.
- This is so that we can have a place to attach the additional metadata we need on platform or target specific behaviors.
1 parent ca2d64a commit bf75c8f

File tree

3 files changed

+72
-68
lines changed

3 files changed

+72
-68
lines changed

utils/SwiftBuildSupport.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,22 @@ def get_preset_options(substitutions, preset_file_names, preset_name):
151151
from swift_build_support.targets import StdlibDeploymentTarget
152152
for sdk in sdks_to_configure:
153153
if sdk == "OSX":
154-
tgts += StdlibDeploymentTarget.OSX.allArchs
154+
tgts += StdlibDeploymentTarget.OSX.targets
155155
elif sdk == "IOS":
156-
tgts += StdlibDeploymentTarget.iOS.allArchs
156+
tgts += StdlibDeploymentTarget.iOS.targets
157157
elif sdk == "IOS_SIMULATOR":
158-
tgts += StdlibDeploymentTarget.iOSSimulator.allArchs
158+
tgts += StdlibDeploymentTarget.iOSSimulator.targets
159159
elif sdk == "TVOS":
160-
tgts += StdlibDeploymentTarget.AppleTV.allArchs
160+
tgts += StdlibDeploymentTarget.AppleTV.targets
161161
elif sdk == "TVOS_SIMULATOR":
162-
tgts += StdlibDeploymentTarget.AppleTVSimulator.allArchs
162+
tgts += StdlibDeploymentTarget.AppleTVSimulator.targets
163163
elif sdk == "WATCHOS":
164-
tgts += StdlibDeploymentTarget.AppleWatch.allArchs
164+
tgts += StdlibDeploymentTarget.AppleWatch.targets
165165
elif sdk == "WATCHOS_SIMULATOR":
166-
tgts += StdlibDeploymentTarget.AppleWatchSimulator.allArchs
166+
tgts += StdlibDeploymentTarget.AppleWatchSimulator.targets
167167

168168
build_script_opts.append("--stdlib-deployment-targets=" +
169-
" ".join(tgts))
169+
" ".join([tgt.name for tgt in tgts]))
170170
# Filter the swift-sdks parameter
171171
build_script_impl_opts = [opt for opt in build_script_impl_opts
172172
if not opt.startswith("--swift-sdks")]

utils/build-script

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ details of the setups of other systems or automated environments.""")
837837
help="The host target. LLVM, Clang, and Swift will be built for this "
838838
"target. The built LLVM and Clang will be used to compile Swift "
839839
"for the cross-compilation targets.",
840-
default=StdlibDeploymentTarget.host_target())
840+
default=StdlibDeploymentTarget.host_target().name)
841841
targets_group.add_argument(
842842
"--cross-compile-hosts",
843843
help="A space separated list of targets to cross-compile host Swift "
@@ -849,7 +849,10 @@ details of the setups of other systems or automated environments.""")
849849
help="list of targets to compile or cross-compile the Swift standard "
850850
"library for. %(default)s by default.",
851851
nargs="*",
852-
default=StdlibDeploymentTarget.default_stdlib_deployment_targets())
852+
default=[
853+
target.name
854+
for target in
855+
StdlibDeploymentTarget.default_stdlib_deployment_targets()])
853856

854857
projects_group = parser.add_argument_group(
855858
title="Options to select projects")

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,61 @@
1212
import platform
1313

1414

15+
class Platform(object):
16+
"""
17+
Abstract representation of a platform Swift can run on.
18+
"""
19+
20+
def __init__(self, name, archs):
21+
"""
22+
Create a platform with the given name and list of architectures.
23+
"""
24+
self.name = name
25+
self.targets = [Target(self, arch) for arch in archs]
26+
27+
# Add a property for each arch.
28+
for target in self.targets:
29+
setattr(self, target.arch, target)
30+
31+
32+
class Target(object):
33+
"""
34+
Abstract representation of a target Swift can run on.
35+
"""
36+
37+
def __init__(self, platform, arch):
38+
self.platform = platform
39+
self.arch = arch
40+
41+
@property
42+
def name(self):
43+
return "{}-{}".format(self.platform.name, self.arch)
44+
45+
1546
class StdlibDeploymentTarget(object):
47+
OSX = Platform("macosx", archs=["x86_64"])
48+
49+
iOS = Platform("iphoneos", archs=["armv7", "armv7s", "arm64"])
50+
iOSSimulator = Platform("iphonesimulator", archs=["i386", "x86_64"])
51+
52+
AppleTV = Platform("appletvos", archs=["arm64"])
53+
AppleTVSimulator = Platform("appletvsimulator", archs=["x86_64"])
54+
55+
AppleWatch = Platform("watchos", archs=["armv7k"])
56+
AppleWatchSimulator = Platform("watchsimulator", archs=["i386"])
57+
58+
Linux = Platform("linux", archs=[
59+
"x86_64",
60+
"armv6",
61+
"armv7",
62+
"aarch64",
63+
"ppc64",
64+
"ppc64le",
65+
"s390x"])
66+
67+
FreeBSD = Platform("freebsd", archs=["x86_64"])
1668

17-
class OSX(object):
18-
x86_64 = 'macosx-x86_64'
19-
allArchs = [x86_64]
20-
21-
class iOS(object): # noqa
22-
armv7 = 'iphoneos-armv7'
23-
armv7s = 'iphoneos-armv7s'
24-
arm64 = 'iphoneos-arm64'
25-
allArchs = [armv7, armv7s, arm64]
26-
27-
class iOSSimulator(object): # noqa
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+
Cygwin = Platform("cygwin", archs=["x86_64"])
6970

7071
@staticmethod
7172
def host_target():
@@ -124,12 +125,12 @@ def default_stdlib_deployment_targets():
124125
# (it takes a long time).
125126
if host_target == StdlibDeploymentTarget.OSX.x86_64:
126127
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
128+
StdlibDeploymentTarget.iOSSimulator.targets + \
129+
StdlibDeploymentTarget.AppleTVSimulator.targets + \
130+
StdlibDeploymentTarget.AppleWatchSimulator.targets + \
131+
StdlibDeploymentTarget.iOS.targets + \
132+
StdlibDeploymentTarget.AppleTV.targets + \
133+
StdlibDeploymentTarget.AppleWatch.targets
133134
else:
134135
# All other machines only configure their host stdlib by default.
135136
return [host_target]

0 commit comments

Comments
 (0)