Skip to content

Commit a4537e8

Browse files
committed
[SR-237] Move stdlib deployment targets to Python
Migrate the logic that determines which platforms to build the stdlib for to Python. This is applies both as an effort to migrate more of the build script to Python (https://bugs.swift.org/browse/SR-237), but also as a means of splitting up the work necessary to cross-compile the Swift stdlib from OS X to Linux.
1 parent 4bf4fba commit a4537e8

File tree

3 files changed

+63
-71
lines changed

3 files changed

+63
-71
lines changed

utils/build-script

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ details of the setups of other systems or automated environments.""")
306306
"target. The built LLVM and Clang will be used to compile Swift "
307307
"for the cross-compilation targets.",
308308
default=swift_build_support.targets.host_target())
309+
targets_group.add_argument(
310+
"--stdlib-deployment-targets",
311+
help="list of targets to compile or cross-compile the Swift standard "
312+
"library for. %(default)s by default.",
313+
nargs="*",
314+
default=swift_build_support.targets.stdlib_deployment_targets())
309315

310316
projects_group = parser.add_argument_group(
311317
title="Options to select projects")
@@ -756,6 +762,7 @@ the number of parallel build jobs to use""",
756762
'--darwin-xcrun-toolchain',
757763
'--cmake',
758764
'--host-target',
765+
'--stdlib-deployment-targets',
759766
'--skip-build',
760767
'--show-sdks',
761768
'--install-prefix',
@@ -772,7 +779,7 @@ the number of parallel build jobs to use""",
772779
'--skip-test-watchos-host',
773780
]))
774781

775-
if args.host_target is None:
782+
if args.host_target is None or args.stdlib_deployment_targets is None:
776783
print_with_argv0("Unknown operating system.")
777784
return 1
778785

@@ -1110,6 +1117,8 @@ the number of parallel build jobs to use""",
11101117
"--build-dir", build_dir,
11111118
"--install-prefix", os.path.abspath(args.install_prefix),
11121119
"--host-target", args.host_target,
1120+
"--stdlib-deployment-targets",
1121+
" ".join(args.stdlib_deployment_targets),
11131122
"--host-cc", host_clang.cc,
11141123
"--host-cxx", host_clang.cxx,
11151124
"--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain,

utils/build-script-impl

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ KNOWN_SETTINGS=(
186186
install-libdispatch "" "whether to install libdispatch"
187187
darwin-install-extract-symbols "" "whether to extract symbols with dsymutil during installations"
188188
host-target "" "The host target. LLVM, Clang, and Swift will be built for this target. The built LLVM and Clang will be used to compile Swift for the cross-compilation targets. **This argument is required**"
189+
stdlib-deployment-targets "" "space-separated list of targets to compile or cross-compile the Swift standard library for"
189190
cross-compile-tools-deployment-targets "" "space-separated list of targets to cross-compile host Swift tools for"
190191
skip-merge-lipo-cross-compile-tools "" "set to skip running merge-lipo after installing cross-compiled host Swift tools"
191192
darwin-deployment-version-osx "10.9" "minimum deployment target version for OS X"
@@ -897,76 +898,6 @@ function is_cross_tools_deployment_target() {
897898
done
898899
}
899900

900-
# A list of deployment targets that we compile or cross-compile the
901-
# Swift standard library for.
902-
STDLIB_DEPLOYMENT_TARGETS=()
903-
case "$(uname -s -m)" in
904-
Linux\ x86_64)
905-
STDLIB_DEPLOYMENT_TARGETS=(
906-
"linux-x86_64"
907-
"android-armv7"
908-
)
909-
;;
910-
Linux\ armv6*)
911-
STDLIB_DEPLOYMENT_TARGETS=(
912-
"linux-armv6"
913-
)
914-
;;
915-
Linux\ armv7*)
916-
STDLIB_DEPLOYMENT_TARGETS=(
917-
"linux-armv7"
918-
)
919-
;;
920-
Linux\ aarch64)
921-
STDLIB_DEPLOYMENT_TARGETS=(
922-
"linux-aarch64"
923-
)
924-
;;
925-
Linux\ ppc64)
926-
STDLIB_DEPLOYMENT_TARGETS=(
927-
"linux-powerpc64"
928-
)
929-
;;
930-
Linux\ ppc64le)
931-
STDLIB_DEPLOYMENT_TARGETS=(
932-
"linux-powerpc64le"
933-
)
934-
;;
935-
Darwin\ x86_64)
936-
STDLIB_DEPLOYMENT_TARGETS=(
937-
"macosx-x86_64"
938-
"iphonesimulator-i386"
939-
"iphonesimulator-x86_64"
940-
"appletvsimulator-x86_64"
941-
"watchsimulator-i386"
942-
943-
# Put iOS native targets last so that we test them last (it takes a
944-
# long time).
945-
"iphoneos-arm64"
946-
"iphoneos-armv7"
947-
"appletvos-arm64"
948-
"watchos-armv7k"
949-
)
950-
;;
951-
952-
FreeBSD\ amd64)
953-
STDLIB_DEPLOYMENT_TARGETS=(
954-
"freebsd-x86_64"
955-
)
956-
;;
957-
958-
CYGWIN_NT-10.0\ x86_64)
959-
STDLIB_DEPLOYMENT_TARGETS=(
960-
"cygwin-x86_64"
961-
)
962-
;;
963-
964-
*)
965-
echo "Unknown operating system"
966-
exit 1
967-
;;
968-
esac
969-
970901
#
971902
# Calculate source directories for each product.
972903
#
@@ -1058,6 +989,7 @@ SWIFT_STDLIB_TARGETS=()
1058989
SWIFT_BENCHMARK_TARGETS=()
1059990
SWIFT_RUN_BENCHMARK_TARGETS=()
1060991
SWIFT_TEST_TARGETS=()
992+
STDLIB_DEPLOYMENT_TARGETS=($STDLIB_DEPLOYMENT_TARGETS)
1061993
for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
1062994
build_for_this_target=1
1063995
test_this_target=1

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,57 @@ def host_target():
5151
return None
5252

5353

54+
def stdlib_deployment_targets():
55+
"""
56+
Return deployment targets for the Swift stdlib, based on the host machine.
57+
If the host machine is not one of the recognized ones, return None.
58+
"""
59+
system = platform.system()
60+
machine = platform.machine()
61+
62+
if system == 'Linux':
63+
if machine == 'x86_64':
64+
return [
65+
'linux-x86_64',
66+
'android-armv7',
67+
]
68+
elif machine.startswith('armv6'):
69+
# linux-armv6* is canonicalized to 'linux-armv6'
70+
return ['linux-armv6']
71+
elif machine.startswith('armv7'):
72+
# linux-armv7* is canonicalized to 'linux-armv7'
73+
return ['linux-armv7']
74+
elif machine == 'aarch64':
75+
return ['linux-aarch64']
76+
elif machine == 'ppc64':
77+
return ['linux-ppc64']
78+
elif machine == 'ppc64le':
79+
return ['linux-ppc64le']
80+
elif system == 'Darwin':
81+
if machine == 'x86_64':
82+
return [
83+
'macosx-x86_64',
84+
'iphonesimulator-i386',
85+
'iphonesimulator-x86_64',
86+
'appletvsimulator-x86_64',
87+
'watchsimulator-i386',
88+
# Put iOS native targets last so that we test them last
89+
# (it takes a long time).
90+
'iphoneos-arm64',
91+
'iphoneos-armv7',
92+
'appletvos-arm64',
93+
'watchos-armv7k',
94+
]
95+
elif system == 'FreeBSD':
96+
if machine == 'amd64':
97+
return ['freebsd-x86_64']
98+
elif system == 'CYGWIN_NT-10.0':
99+
if machine == 'x86_64':
100+
return ['cygwin-x86_64']
101+
102+
return None
103+
104+
54105
def install_prefix():
55106
"""
56107
Returns the default path at which built Swift products (like bin, lib,

0 commit comments

Comments
 (0)