Skip to content

Commit 73c1ba2

Browse files
committed
Replace SWIFT_SDKS with SWIFT_CROSS_COMPILE_STDLIB_TARGETS
1 parent f727ec0 commit 73c1ba2

File tree

15 files changed

+441
-390
lines changed

15 files changed

+441
-390
lines changed

CMakeLists.txt

Lines changed: 237 additions & 135 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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,9 +1106,9 @@ function(add_swift_library name)
11061106
set(SWIFTLIB_INSTALL_IN_COMPONENT dev)
11071107
endif()
11081108

1109-
# If target SDKs are not specified, build for all known SDKs.
1109+
# If target SDKs are not specified, build for all configured SDKs.
11101110
if("${SWIFTLIB_TARGET_SDKS}" STREQUAL "")
1111-
set(SWIFTLIB_TARGET_SDKS ${SWIFT_SDKS})
1111+
set(SWIFTLIB_TARGET_SDKS ${SWIFT_CONFIGURED_SDKS})
11121112
endif()
11131113

11141114
# All Swift code depends on the standard library, except for the standard
@@ -1162,12 +1162,14 @@ function(add_swift_library name)
11621162
# If we are building this library for targets, loop through the various
11631163
# SDKs building the variants of this library.
11641164
list_intersect(
1165-
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_SDKS}" SWIFTLIB_TARGET_SDKS)
1166-
if(SWIFTLIB_FORCE_BUILD_FOR_HOST_SDK)
1165+
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_CONFIGURED_SDKS}" SWIFTLIB_TARGET_SDKS)
1166+
list_contains("${SWIFT_CONFIGURED_SDKS}" "${SWIFT_HOST_VARIANT_SDK}" IS_BUILDING_HOST)
1167+
if(SWIFTLIB_FORCE_BUILD_FOR_HOST_SDK AND IS_BUILDING_HOST)
11671168
list_union(
11681169
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_HOST_VARIANT_SDK}"
11691170
SWIFTLIB_TARGET_SDKS)
11701171
endif()
1172+
11711173
foreach(sdk ${SWIFTLIB_TARGET_SDKS})
11721174
set(THIN_INPUT_TARGETS)
11731175

@@ -1325,7 +1327,6 @@ function(add_swift_library name)
13251327

13261328
# Determine the subdirectory where this library will be installed.
13271329
set(resource_dir_sdk_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
1328-
13291330
if("${resource_dir_sdk_subdir}" STREQUAL "")
13301331
message(FATAL_ERROR "internal error: the variable should be non-empty")
13311332
endif()
@@ -1621,7 +1622,7 @@ function(add_swift_target_executable name)
16211622
swiftCore)
16221623
endif()
16231624

1624-
foreach(sdk ${SWIFT_SDKS})
1625+
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
16251626
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
16261627
set(VARIANT_SUFFIX "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
16271628
set(VARIANT_NAME "${name}${VARIANT_SUFFIX}")

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 5 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)
@@ -106,6 +106,8 @@ macro(configure_sdk_darwin
106106

107107
# Add this to the list of known SDKs.
108108
list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
109+
set(SWIFT_CONFIGURED_SDKS "${SWIFT_CONFIGURED_SDKS}" CACHE STRING
110+
"The SDKs which have been configured to build")
109111

110112
_report_sdk("${prefix}")
111113
endmacro()
@@ -134,6 +136,8 @@ macro(configure_sdk_unix
134136

135137
# Add this to the list of known SDKs.
136138
list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
139+
set(SWIFT_CONFIGURED_SDKS "${SWIFT_CONFIGURED_SDKS}" CACHE STRING
140+
"The SDKs which have been configured to build")
137141

138142
_report_sdk("${prefix}")
139143
endmacro()

cmake/modules/SwiftList.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@ function(list_union lhs rhs result_var_name)
3030
endforeach()
3131
set("${result_var_name}" "${result}" PARENT_SCOPE)
3232
endfunction()
33+
34+
function(list_contains list item result_var_name)
35+
list(FIND list "${item}" index)
36+
if(${index} EQUAL -1)
37+
set("${result_var_name}" 0 PARENT_SCOPE)
38+
else()
39+
set("${result_var_name}" 1 PARENT_SCOPE)
40+
endif()
41+
endfunction()

stdlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(SWIFT_BUILD_STATIC_STDLIB)
1717
endif()
1818

1919
add_custom_target(swift-stdlib-all)
20-
foreach(SDK ${SWIFT_SDKS})
20+
foreach(SDK ${SWIFT_CONFIGURED_SDKS})
2121
add_custom_target("swift-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
2222
add_custom_target("swift-test-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
2323
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 ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
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} ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_
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: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -74,47 +74,57 @@ class HostSpecificConfiguration(object):
7474
def __init__(self, host_target, invocation):
7575
"""Initialize for the given `host_target`."""
7676

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

114-
# If we aren't actually building this target (only configuring
115-
# it), do nothing else.
116-
if deployment_target_name not in stdlib_targets_to_build:
117-
continue
126+
deployment_platform = deployment_target.platform
127+
name = deployment_target.name
118128

119129
# Compute which actions are desired.
120130
build = (
@@ -139,7 +149,6 @@ class HostSpecificConfiguration(object):
139149
else:
140150
test = False
141151

142-
name = deployment_target.name
143152
if build:
144153
# Validation and long tests require building the full standard
145154
# library, whereas the other targets can build a slightly
@@ -201,7 +210,7 @@ class BuildScriptInvocation(object):
201210
diagnostics.fatal(
202211
"can't find distcc-pump (please install distcc-pump)")
203212

204-
if args.host_target is None or args.stdlib_deployment_targets is None:
213+
if args.host_target is None:
205214
diagnostics.fatal("unknown operating system")
206215

207216
if args.symbols_package:
@@ -397,17 +406,19 @@ class BuildScriptInvocation(object):
397406
args.build_subdir = \
398407
swift_build_support.workspace.compute_build_subdir(args)
399408

400-
# Add optional stdlib-deployment-targets
409+
# Add optional cross-compile-stdlib-deployment-targets
401410
if args.android:
402-
args.stdlib_deployment_targets.append(
411+
args.cross_compile_stdlib_deployment_targets.append(
403412
StdlibDeploymentTarget.Android.armv7.name)
404413

405414
# Infer platform flags from manually-specified configure targets.
406415
# This doesn't apply to Darwin platforms, as they are
407416
# already configured. No building without the platform flag, though.
408417

409-
android_tgts = [tgt for tgt in args.stdlib_deployment_targets
410-
if StdlibDeploymentTarget.Android.contains(tgt)]
418+
android_tgts = \
419+
[tgt for tgt in args.cross_compile_stdlib_deployment_targets
420+
if StdlibDeploymentTarget.Android.contains(tgt)]
421+
411422
if not args.android and len(android_tgts) > 0:
412423
args.android = True
413424
args.skip_build_android = True
@@ -542,8 +553,6 @@ class BuildScriptInvocation(object):
542553
"--build-dir", self.workspace.build_root,
543554
"--install-prefix", args.install_prefix,
544555
"--host-target", args.host_target,
545-
"--stdlib-deployment-targets",
546-
" ".join(args.stdlib_deployment_targets),
547556
"--host-cc", toolchain.cc,
548557
"--host-cxx", toolchain.cxx,
549558
"--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain,
@@ -576,10 +585,24 @@ class BuildScriptInvocation(object):
576585
pipes.quote(arg) for arg in cmake.build_args()),
577586
]
578587

588+
# Specify additional stdlib targets to configure. Remove zero-length
589+
# names.
590+
args.cross_compile_stdlib_deployment_targets = \
591+
[t for t in args.cross_compile_stdlib_deployment_targets
592+
if len(t) > 0]
593+
594+
if args.cross_compile_stdlib_deployment_targets is not None and \
595+
len(args.cross_compile_stdlib_deployment_targets) > 0 and \
596+
'none' not in args.cross_compile_stdlib_deployment_targets:
597+
impl_args += ["--cross-compile-stdlib-deployment-targets",
598+
" ".join(
599+
args.cross_compile_stdlib_deployment_targets)]
600+
# Specify stdlib targets to build
579601
if args.build_stdlib_deployment_targets:
580602
impl_args += [
581603
"--build-stdlib-deployment-targets", " ".join(
582604
args.build_stdlib_deployment_targets)]
605+
# Specify additional hosts to configure + build
583606
if args.cross_compile_hosts:
584607
impl_args += [
585608
"--cross-compile-hosts", " ".join(args.cross_compile_hosts)]
@@ -783,16 +806,18 @@ class BuildScriptInvocation(object):
783806
config = HostSpecificConfiguration(host_target, self)
784807

785808
# Convert into `build-script-impl` style variables.
809+
stdlib_target_names = [t.name for t
810+
in config.stdlib_targets_to_configure]
786811
options[host_target] = {
787-
"SWIFT_SDKS": " ".join(sorted(
788-
config.sdks_to_configure)),
789-
"SWIFT_STDLIB_TARGETS": " ".join(
812+
"SWIFT_CROSS_COMPILE_STDLIB_TARGETS": " ".join(
813+
stdlib_target_names),
814+
"SWIFT_STDLIB_BUILD_TARGETS": " ".join(
790815
config.swift_stdlib_build_targets),
791-
"SWIFT_BENCHMARK_TARGETS": " ".join(
816+
"SWIFT_BENCHMARK_BUILD_TARGETS": " ".join(
792817
config.swift_benchmark_build_targets),
793-
"SWIFT_RUN_BENCHMARK_TARGETS": " ".join(
818+
"SWIFT_BENCHMARK_RUN_TARGETS": " ".join(
794819
config.swift_benchmark_run_targets),
795-
"SWIFT_TEST_TARGETS": " ".join(
820+
"SWIFT_TEST_RUN_TARGETS": " ".join(
796821
config.swift_test_run_targets),
797822
}
798823

@@ -1088,15 +1113,14 @@ details of the setups of other systems or automated environments.""")
10881113
"tools for. Can be used multiple times.",
10891114
action=arguments.action.concat, type=arguments.type.shell_split,
10901115
default=[])
1091-
stdlib_targets = StdlibDeploymentTarget.default_stdlib_deployment_targets()
1116+
default_cross_stdlib_targets = StdlibDeploymentTarget\
1117+
.default_cross_compile_stdlib_targets()
10921118
targets_group.add_argument(
1093-
"--stdlib-deployment-targets",
1094-
help="list of targets to compile or cross-compile the Swift standard "
1119+
"--cross-compile-stdlib-deployment-targets",
1120+
help="list of targets to cross-compile the Swift standard "
10951121
"library for. %(default)s by default.",
10961122
nargs="*",
1097-
default=[
1098-
target.name
1099-
for target in stdlib_targets])
1123+
default=[t.name for t in default_cross_stdlib_targets])
11001124
targets_group.add_argument(
11011125
"--build-stdlib-deployment-targets",
11021126
help="A space-separated list that filters which of the configured "

0 commit comments

Comments
 (0)