Skip to content

Commit d9ba41d

Browse files
committed
Replace SWIFT_SDKS with SWIFT_CROSS_COMPILE_STDLIB_TARGETS
1 parent 2db3e7e commit d9ba41d

File tree

14 files changed

+425
-384
lines changed

14 files changed

+425
-384
lines changed

CMakeLists.txt

Lines changed: 217 additions & 129 deletions
Large diffs are not rendered by default.

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ endforeach()
199199

200200
set(executable_targets)
201201

202-
if(SWIFT_SDKS)
202+
if(SWIFT_CONFIGURED_SDKS)
203203
set(IS_SWIFT_BUILD true)
204204
endif()
205205

benchmark/scripts/generate_harness/CMakeLists.txt_template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ endforeach()
137137

138138
set(executable_targets)
139139

140-
if(SWIFT_SDKS)
140+
if(SWIFT_CONFIGURED_SDKS)
141141
set(IS_SWIFT_BUILD true)
142142
endif()
143143

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,9 @@ function(add_swift_library name)
10341034
set(SWIFTLIB_INSTALL_IN_COMPONENT dev)
10351035
endif()
10361036

1037-
# If target SDKs are not specified, build for all known SDKs.
1037+
# If target SDKs are not specified, build for all configured SDKs.
10381038
if("${SWIFTLIB_TARGET_SDKS}" STREQUAL "")
1039-
set(SWIFTLIB_TARGET_SDKS ${SWIFT_SDKS})
1039+
set(SWIFTLIB_TARGET_SDKS ${SWIFT_CONFIGURED_SDKS})
10401040
endif()
10411041

10421042
# All Swift code depends on the standard library, except for the standard
@@ -1083,12 +1083,13 @@ function(add_swift_library name)
10831083
# If we are building this library for targets, loop through the various
10841084
# SDKs building the variants of this library.
10851085
list_intersect(
1086-
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_SDKS}" SWIFTLIB_TARGET_SDKS)
1087-
if(SWIFTLIB_HOST_LIBRARY)
1086+
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_CONFIGURED_SDKS}" SWIFTLIB_TARGET_SDKS)
1087+
if(SWIFTLIB_HOST_LIBRARY AND NOT SWIFT_SKIP_HOST_STDLIB)
10881088
list_union(
10891089
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_HOST_VARIANT_SDK}"
10901090
SWIFTLIB_TARGET_SDKS)
10911091
endif()
1092+
10921093
foreach(sdk ${SWIFTLIB_TARGET_SDKS})
10931094
set(THIN_INPUT_TARGETS)
10941095

@@ -1245,7 +1246,6 @@ function(add_swift_library name)
12451246

12461247
# Determine the subdirectory where this library will be installed.
12471248
set(resource_dir_sdk_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
1248-
12491249
if("${resource_dir_sdk_subdir}" STREQUAL "")
12501250
message(FATAL_ERROR "internal error: the variable should be non-empty")
12511251
endif()
@@ -1538,7 +1538,7 @@ function(add_swift_target_executable name)
15381538
swiftCore)
15391539
endif()
15401540

1541-
foreach(sdk ${SWIFT_SDKS})
1541+
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
15421542
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
15431543
set(VARIANT_SUFFIX "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
15441544
set(VARIANT_NAME "${name}${VARIANT_SUFFIX}")

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Each element in this list is an SDK for which the various
44
# SWIFT_SDK_${name}_* variables are defined. Swift libraries will be
55
# built for each variant.
6-
set(SWIFT_CONFIGURED_SDKS)
6+
set(SWIFT_CONFIGURED_SDKS "")
77

88
# Report the given SDK to the user.
99
function(_report_sdk prefix)
@@ -61,6 +61,22 @@ macro(configure_sdk_darwin
6161
# Note: this has to be implemented as a macro because it sets global
6262
# variables.
6363

64+
# Because we calculate our own triple, we need to validate
65+
# architectures here.
66+
67+
set(OSX_VALID_ARCHITECTURES "x86_64")
68+
set(IOS_VALID_ARCHITECTURES "armv7;armv7s;arm64")
69+
set(TVOS_VALID_ARCHITECTURES "arm64")
70+
set(WATCHOS_VALID_ARCHITECTURES "armv7k")
71+
set(IOS_SIMULATOR_VALID_ARCHITECTURES "i386;x86_64")
72+
set(TVOS_SIMULATOR_VALID_ARCHITECTURES "x86_64")
73+
set(WATCHOS_SIMULATOR_VALID_ARCHITECTURES "i386")
74+
75+
list_subtract("${architectures}" "${${prefix}_VALID_ARCHITECTURES}" invalid_archs)
76+
if(invalid_archs)
77+
message(FATAL_ERROR "${invalid_archs} are not recognised architectures for ${name}")
78+
endif()
79+
6480
# Find the SDK
6581
set(SWIFT_SDK_${prefix}_PATH "" CACHE PATH "Path to the ${name} SDK")
6682

@@ -104,6 +120,8 @@ macro(configure_sdk_darwin
104120

105121
# Add this to the list of known SDKs.
106122
list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
123+
set(SWIFT_CONFIGURED_SDKS "${SWIFT_CONFIGURED_SDKS}" CACHE STRING
124+
"The SDKs which have been configured to build")
107125

108126
_report_sdk("${prefix}")
109127
endmacro()
@@ -127,6 +145,8 @@ macro(configure_sdk_unix
127145

128146
# Add this to the list of known SDKs.
129147
list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
148+
set(SWIFT_CONFIGURED_SDKS "${SWIFT_CONFIGURED_SDKS}" CACHE STRING
149+
"The SDKs which have been configured to build")
130150

131151
_report_sdk("${prefix}")
132152
endmacro()

stdlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ else()
1111
endif()
1212

1313
add_custom_target(swift-stdlib-all)
14-
foreach(SDK ${SWIFT_SDKS})
14+
foreach(SDK ${SWIFT_CONFIGURED_SDKS})
1515
add_custom_target("swift-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
1616
add_custom_target("swift-test-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
1717
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})

stdlib/private/SwiftReflectionTest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ add_swift_library(swiftSwiftReflectionTest SHARED IS_STDLIB
33
SWIFT_MODULE_DEPENDS Darwin
44
INSTALL_IN_COMPONENT stdlib-experimental)
55

6-
foreach(SDK ${SWIFT_SDKS})
6+
foreach(SDK ${SWIFT_CONFIGURED_SDKS})
77
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
88
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
99
add_dependencies(

stdlib/public/Platform/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ add_swift_library(${swift_platform_name} IS_SDK_OVERLAY
2929
${swift_platform_flags})
3030

3131
set(glibc_modulemap_target_list)
32-
foreach(sdk ${SWIFT_SDKS})
32+
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
3333
if("${sdk}" STREQUAL "LINUX" OR
3434
"${sdk}" STREQUAL "FREEBSD" OR
3535
"${sdk}" STREQUAL "ANDROID" OR

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ if(PYTHONINTERP_FOUND)
139139
only_long
140140
)
141141

142-
foreach(SDK ${SWIFT_SDKS})
142+
foreach(SDK ${SWIFT_CONFIGURED_SDKS})
143143
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
144144
# Configure variables for this subdirectory.
145145
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")

utils/SwiftBuildSupport.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def get_preset_options(substitutions, preset_file_names, preset_name):
142142
diagnostics.fatal("missing option(s) for preset '" + preset_name +
143143
"': " + ", ".join(missing_opts))
144144

145-
# Migrate 'swift-sdks' parameter to 'stdlib-deployment-targets'
145+
# Migrate 'swift-sdks' parameter to
146+
# 'cross-compile-stdlib-deployment-targets'
146147
for opt in build_script_impl_opts:
147148
if opt.startswith("--swift-sdks"):
148149
sdks_to_configure = opt.split("=")[1].split(";")
@@ -164,8 +165,10 @@ def get_preset_options(substitutions, preset_file_names, preset_name):
164165
tgts += StdlibDeploymentTarget.AppleWatch.targets
165166
elif sdk == "WATCHOS_SIMULATOR":
166167
tgts += StdlibDeploymentTarget.AppleWatchSimulator.targets
168+
tgts = [x for x in tgts
169+
if x != StdlibDeploymentTarget.host_target()]
167170

168-
build_script_opts.append("--stdlib-deployment-targets=" +
171+
build_script_opts.append("--cross-compile-stdlib-deployment-targets=" +
169172
" ".join([tgt.name for tgt in tgts]))
170173
# Filter the swift-sdks parameter
171174
build_script_impl_opts = [opt for opt in build_script_impl_opts

utils/build-presets.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ skip-build-tvos
7474
skip-test-tvos
7575
skip-build-watchos
7676
skip-test-watchos
77-
stdlib-deployment-targets=macosx-x86_64
77+
cross-compile-stdlib-deployment-targets=''
7878
swift-primary-variant-sdk=OSX
7979
swift-primary-variant-arch=x86_64
8080

utils/build-script

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -71,47 +71,57 @@ class HostSpecificConfiguration(object):
7171
def __init__(self, host_target, invocation):
7272
"""Initialize for the given `host_target`."""
7373

74-
# Compute the set of deployment targets to configure/build.
7574
args = invocation.args
75+
76+
# [*] Compute the list of deployment targets to configure.
77+
#
78+
# We only need to configure cross-compiled stdlib targets.
79+
# The host_target is implicitly configured by CMake.
80+
81+
self.host_target = StdlibDeploymentTarget\
82+
.get_target_for_name(host_target)
83+
if self.host_target is None:
84+
diagnostics.fatal("unknown host target: %r" % (
85+
host_target))
86+
87+
self.stdlib_targets_to_configure = []
88+
# FIXME: Cross-compiled hosts don't support cross-compiled targets
89+
# or filtering build lists, only because we don't
90+
# have an argument structure to define them for NxM hosts and targets.
7691
if host_target == args.host_target:
77-
# This host is the user's desired product, so honor the requested
78-
# set of targets to configure/build.
79-
stdlib_targets_to_configure = args.stdlib_deployment_targets
80-
if "all" in args.build_stdlib_deployment_targets:
81-
stdlib_targets_to_build = set(stdlib_targets_to_configure)
82-
else:
83-
stdlib_targets_to_build = set(
84-
args.build_stdlib_deployment_targets).intersect(
85-
set(args.stdlib_deployment_targets))
86-
else:
87-
# Otherwise, this is a host we are building as part of
88-
# cross-compiling, so we only need the target itself.
89-
stdlib_targets_to_configure = [host_target]
90-
stdlib_targets_to_build = set(stdlib_targets_to_configure)
91-
92-
# Compute the lists of **CMake** targets for each use case (configure
93-
# vs. build vs. run) and the SDKs to configure with.
94-
self.sdks_to_configure = set()
92+
for name in args.cross_compile_stdlib_deployment_targets:
93+
dpymt_target = StdlibDeploymentTarget.get_target_for_name(name)
94+
if dpymt_target is None:
95+
diagnostics.fatal("unknown stdlib target: %r" % (
96+
name))
97+
else:
98+
self.stdlib_targets_to_configure.append(dpymt_target)
99+
100+
# [*] Compute the list of deployment targets to build.
101+
#
102+
# Even though we don't need to configure host_target, we do need
103+
# to explicitly build it.
104+
# So by default, build all configured targets + the host
105+
106+
self.stdlib_targets_to_build = [self.host_target]
107+
self.stdlib_targets_to_build += self.stdlib_targets_to_configure
108+
109+
if host_target == args.host_target and \
110+
"all" not in args.build_stdlib_deployment_targets:
111+
self.stdlib_targets_to_build = \
112+
[t for t in self.stdlib_targets_to_build
113+
if t.name in args.build_stdlib_deployment_targets]
114+
115+
# [*] Compute the lists of **CMake** build/run targets
116+
95117
self.swift_stdlib_build_targets = []
96118
self.swift_test_run_targets = []
97119
self.swift_benchmark_build_targets = []
98120
self.swift_benchmark_run_targets = []
99-
for deployment_target_name in stdlib_targets_to_configure:
100-
# Get the target object.
101-
deployment_target = StdlibDeploymentTarget.get_target_for_name(
102-
deployment_target_name)
103-
if deployment_target is None:
104-
diagnostics.fatal("unknown target: %r" % (
105-
deployment_target_name,))
106-
107-
# Add the SDK to use.
108-
deployment_platform = deployment_target.platform
109-
self.sdks_to_configure.add(deployment_platform.sdk_name)
121+
for deployment_target in self.stdlib_targets_to_build:
110122

111-
# If we aren't actually building this target (only configuring
112-
# it), do nothing else.
113-
if deployment_target_name not in stdlib_targets_to_build:
114-
continue
123+
deployment_platform = deployment_target.platform
124+
name = deployment_target.name
115125

116126
# Compute which actions are desired.
117127
build = (
@@ -130,19 +140,18 @@ class HostSpecificConfiguration(object):
130140
deployment_platform.is_embedded and \
131141
not deployment_platform.is_simulator:
132142
if deployment_platform not in \
133-
invocation.platforms_to_skip_test_host:
143+
invocation.platforms_to_skip_test_host:
134144
test_host_only = True
135145
test = True
136146
else:
137147
test = False
138148

139-
name = deployment_target.name
140149
if build:
141150
# Validation and long tests require building the full standard
142151
# library, whereas the other targets can build a slightly
143152
# smaller subset which is faster to build.
144153
if args.build_swift_stdlib_unittest_extra or \
145-
args.validation_test or args.long_test:
154+
args.validation_test or args.long_test:
146155
self.swift_stdlib_build_targets.append(
147156
"swift-stdlib-" + name)
148157
else:
@@ -198,7 +207,7 @@ class BuildScriptInvocation(object):
198207
diagnostics.fatal(
199208
"can't find distcc-pump (please install distcc-pump)")
200209

201-
if args.host_target is None or args.stdlib_deployment_targets is None:
210+
if args.host_target is None:
202211
diagnostics.fatal("unknown operating system")
203212

204213
if args.symbols_package:
@@ -390,9 +399,9 @@ class BuildScriptInvocation(object):
390399
args.build_subdir = \
391400
swift_build_support.workspace.compute_build_subdir(args)
392401

393-
# Add optional stdlib-deployment-targets
402+
# Add optional cross-compile-stdlib-deployment-targets
394403
if args.android:
395-
args.stdlib_deployment_targets.append(
404+
args.cross_compile_stdlib_deployment_targets.append(
396405
StdlibDeploymentTarget.Android.armv7.name)
397406

398407
def __init__(self, toolchain, args):
@@ -525,8 +534,6 @@ class BuildScriptInvocation(object):
525534
"--build-dir", self.workspace.build_root,
526535
"--install-prefix", args.install_prefix,
527536
"--host-target", args.host_target,
528-
"--stdlib-deployment-targets",
529-
" ".join(args.stdlib_deployment_targets),
530537
"--host-cc", toolchain.cc,
531538
"--host-cxx", toolchain.cxx,
532539
"--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain,
@@ -559,10 +566,24 @@ class BuildScriptInvocation(object):
559566
pipes.quote(arg) for arg in cmake.build_args()),
560567
]
561568

569+
# Specify additional stdlib targets to configure. Remove zero-length
570+
# names.
571+
args.cross_compile_stdlib_deployment_targets = \
572+
[t for t in args.cross_compile_stdlib_deployment_targets
573+
if len(t) > 0]
574+
575+
if args.cross_compile_stdlib_deployment_targets is not None and \
576+
len(args.cross_compile_stdlib_deployment_targets) > 0 and \
577+
'none' not in args.cross_compile_stdlib_deployment_targets:
578+
impl_args += ["--cross-compile-stdlib-deployment-targets",
579+
" ".join(
580+
args.cross_compile_stdlib_deployment_targets)]
581+
# Specify stdlib targets to build
562582
if args.build_stdlib_deployment_targets:
563583
impl_args += [
564584
"--build-stdlib-deployment-targets", " ".join(
565585
args.build_stdlib_deployment_targets)]
586+
# Specify additional hosts to configure + build
566587
if args.cross_compile_hosts:
567588
impl_args += [
568589
"--cross-compile-hosts", " ".join(args.cross_compile_hosts)]
@@ -759,16 +780,18 @@ class BuildScriptInvocation(object):
759780
config = HostSpecificConfiguration(host_target, self)
760781

761782
# Convert into `build-script-impl` style variables.
783+
stdlib_target_names = [t.name for t
784+
in config.stdlib_targets_to_configure]
762785
options[host_target] = {
763-
"SWIFT_SDKS": " ".join(sorted(
764-
config.sdks_to_configure)),
765-
"SWIFT_STDLIB_TARGETS": " ".join(
786+
"SWIFT_CROSS_COMPILE_STDLIB_TARGETS": " ".join(
787+
stdlib_target_names),
788+
"SWIFT_STDLIB_BUILD_TARGETS": " ".join(
766789
config.swift_stdlib_build_targets),
767-
"SWIFT_BENCHMARK_TARGETS": " ".join(
790+
"SWIFT_BENCHMARK_BUILD_TARGETS": " ".join(
768791
config.swift_benchmark_build_targets),
769-
"SWIFT_RUN_BENCHMARK_TARGETS": " ".join(
792+
"SWIFT_BENCHMARK_RUN_TARGETS": " ".join(
770793
config.swift_benchmark_run_targets),
771-
"SWIFT_TEST_TARGETS": " ".join(
794+
"SWIFT_TEST_RUN_TARGETS": " ".join(
772795
config.swift_test_run_targets),
773796
}
774797

@@ -1057,15 +1080,14 @@ details of the setups of other systems or automated environments.""")
10571080
"tools for. Can be used multiple times.",
10581081
action=arguments.action.concat, type=arguments.type.shell_split,
10591082
default=[])
1060-
stdlib_targets = StdlibDeploymentTarget.default_stdlib_deployment_targets()
1083+
default_cross_stdlib_targets = StdlibDeploymentTarget\
1084+
.default_cross_compile_stdlib_targets()
10611085
targets_group.add_argument(
1062-
"--stdlib-deployment-targets",
1063-
help="list of targets to compile or cross-compile the Swift standard "
1086+
"--cross-compile-stdlib-deployment-targets",
1087+
help="list of targets to cross-compile the Swift standard "
10641088
"library for. %(default)s by default.",
10651089
nargs="*",
1066-
default=[
1067-
target.name
1068-
for target in stdlib_targets])
1090+
default=[t.name for t in default_cross_stdlib_targets])
10691091
targets_group.add_argument(
10701092
"--build-stdlib-deployment-targets",
10711093
help="A space-separated list that filters which of the configured "

0 commit comments

Comments
 (0)