Skip to content

[CMake] Replace SWIFT_SDKS with SWIFT_CROSS_COMPILE_DEPLOYMENT_TARGETS #2835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
372 changes: 237 additions & 135 deletions CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ endforeach()

set(executable_targets)

if(SWIFT_SDKS)
if(SWIFT_CONFIGURED_SDKS)
set(IS_SWIFT_BUILD true)
endif()

Expand Down
2 changes: 1 addition & 1 deletion benchmark/scripts/generate_harness/CMakeLists.txt_template
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ endforeach()

set(executable_targets)

if(SWIFT_SDKS)
if(SWIFT_CONFIGURED_SDKS)
set(IS_SWIFT_BUILD true)
endif()

Expand Down
13 changes: 7 additions & 6 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,9 @@ function(add_swift_library name)
set(SWIFTLIB_INSTALL_IN_COMPONENT dev)
endif()

# If target SDKs are not specified, build for all known SDKs.
# If target SDKs are not specified, build for all configured SDKs.
if("${SWIFTLIB_TARGET_SDKS}" STREQUAL "")
set(SWIFTLIB_TARGET_SDKS ${SWIFT_SDKS})
set(SWIFTLIB_TARGET_SDKS ${SWIFT_CONFIGURED_SDKS})
endif()

# All Swift code depends on the standard library, except for the standard
Expand Down Expand Up @@ -1162,12 +1162,14 @@ function(add_swift_library name)
# If we are building this library for targets, loop through the various
# SDKs building the variants of this library.
list_intersect(
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_SDKS}" SWIFTLIB_TARGET_SDKS)
if(SWIFTLIB_FORCE_BUILD_FOR_HOST_SDK)
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_CONFIGURED_SDKS}" SWIFTLIB_TARGET_SDKS)
list_contains("${SWIFT_CONFIGURED_SDKS}" "${SWIFT_HOST_VARIANT_SDK}" IS_BUILDING_HOST)
if(SWIFTLIB_FORCE_BUILD_FOR_HOST_SDK AND IS_BUILDING_HOST)
list_union(
"${SWIFTLIB_TARGET_SDKS}" "${SWIFT_HOST_VARIANT_SDK}"
SWIFTLIB_TARGET_SDKS)
endif()

foreach(sdk ${SWIFTLIB_TARGET_SDKS})
set(THIN_INPUT_TARGETS)

Expand Down Expand Up @@ -1325,7 +1327,6 @@ function(add_swift_library name)

# Determine the subdirectory where this library will be installed.
set(resource_dir_sdk_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}")

if("${resource_dir_sdk_subdir}" STREQUAL "")
message(FATAL_ERROR "internal error: the variable should be non-empty")
endif()
Expand Down Expand Up @@ -1621,7 +1622,7 @@ function(add_swift_target_executable name)
swiftCore)
endif()

foreach(sdk ${SWIFT_SDKS})
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
set(VARIANT_SUFFIX "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
set(VARIANT_NAME "${name}${VARIANT_SUFFIX}")
Expand Down
6 changes: 5 additions & 1 deletion cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Each element in this list is an SDK for which the various
# SWIFT_SDK_${name}_* variables are defined. Swift libraries will be
# built for each variant.
set(SWIFT_CONFIGURED_SDKS)
set(SWIFT_CONFIGURED_SDKS "")

# Report the given SDK to the user.
function(_report_sdk prefix)
Expand Down Expand Up @@ -106,6 +106,8 @@ macro(configure_sdk_darwin

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

_report_sdk("${prefix}")
endmacro()
Expand Down Expand Up @@ -134,6 +136,8 @@ macro(configure_sdk_unix

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

_report_sdk("${prefix}")
endmacro()
Expand Down
9 changes: 9 additions & 0 deletions cmake/modules/SwiftList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ function(list_union lhs rhs result_var_name)
endforeach()
set("${result_var_name}" "${result}" PARENT_SCOPE)
endfunction()

function(list_contains list item result_var_name)
list(FIND list "${item}" index)
if(${index} EQUAL -1)
set("${result_var_name}" 0 PARENT_SCOPE)
else()
set("${result_var_name}" 1 PARENT_SCOPE)
endif()
endfunction()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-pick: This could use a new line at the end of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've raised our minimum-supported CMake since I pushed this, so I think it can be replaced with a built-in function now anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nifty. For my own education, whats the builtin in newer cmake that does this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 changes: 1 addition & 1 deletion stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if(SWIFT_BUILD_STATIC_STDLIB)
endif()

add_custom_target(swift-stdlib-all)
foreach(SDK ${SWIFT_SDKS})
foreach(SDK ${SWIFT_CONFIGURED_SDKS})
add_custom_target("swift-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
add_custom_target("swift-test-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftReflectionTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_swift_library(swiftSwiftReflectionTest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
SWIFT_MODULE_DEPENDS Darwin
INSTALL_IN_COMPONENT stdlib-experimental)

foreach(SDK ${SWIFT_SDKS})
foreach(SDK ${SWIFT_CONFIGURED_SDKS})
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
add_dependencies(
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ add_swift_library(${swift_platform_name} ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_
${swift_platform_flags})

set(glibc_modulemap_target_list)
foreach(sdk ${SWIFT_SDKS})
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
if("${sdk}" STREQUAL "LINUX" OR
"${sdk}" STREQUAL "FREEBSD" OR
"${sdk}" STREQUAL "ANDROID" OR
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ if(PYTHONINTERP_FOUND)
only_long
)

foreach(SDK ${SWIFT_SDKS})
foreach(SDK ${SWIFT_CONFIGURED_SDKS})
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
# Configure variables for this subdirectory.
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
Expand Down
7 changes: 5 additions & 2 deletions utils/SwiftBuildSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def get_preset_options(substitutions, preset_file_names, preset_name):
diagnostics.fatal("missing option(s) for preset '" + preset_name +
"': " + ", ".join(missing_opts))

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

build_script_opts.append("--stdlib-deployment-targets=" +
build_script_opts.append("--cross-compile-stdlib-deployment-targets=" +
" ".join([tgt.name for tgt in tgts]))
# Filter the swift-sdks parameter
build_script_impl_opts = [opt for opt in build_script_impl_opts
Expand Down
2 changes: 1 addition & 1 deletion utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ skip-build-tvos
skip-test-tvos
skip-build-watchos
skip-test-watchos
stdlib-deployment-targets=macosx-x86_64
cross-compile-stdlib-deployment-targets=''
swift-primary-variant-sdk=OSX
swift-primary-variant-arch=x86_64

Expand Down
132 changes: 78 additions & 54 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -74,47 +74,57 @@ class HostSpecificConfiguration(object):
def __init__(self, host_target, invocation):
"""Initialize for the given `host_target`."""

# Compute the set of deployment targets to configure/build.
args = invocation.args

# [*] Compute the list of deployment targets to configure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the significance of the [*] here and in the comment below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None. It's a major step in the workflow (as opposed to all of the minor ones) so it's just for emphasis.

#
# We only need to configure cross-compiled stdlib targets.
# The host_target is implicitly configured by CMake.

self.host_target = StdlibDeploymentTarget\
.get_target_for_name(host_target)
if self.host_target is None:
diagnostics.fatal("unknown host target: %r" % (
host_target))

self.stdlib_targets_to_configure = []
# FIXME: Cross-compiled hosts don't support cross-compiled targets
# or filtering build lists, only because we don't
# have an argument structure to define them for NxM hosts and targets.
if host_target == args.host_target:
# This host is the user's desired product, so honor the requested
# set of targets to configure/build.
stdlib_targets_to_configure = args.stdlib_deployment_targets
if "all" in args.build_stdlib_deployment_targets:
stdlib_targets_to_build = set(stdlib_targets_to_configure)
else:
stdlib_targets_to_build = set(
args.build_stdlib_deployment_targets).intersection(
set(args.stdlib_deployment_targets))
else:
# Otherwise, this is a host we are building as part of
# cross-compiling, so we only need the target itself.
stdlib_targets_to_configure = [host_target]
stdlib_targets_to_build = set(stdlib_targets_to_configure)

# Compute the lists of **CMake** targets for each use case (configure
# vs. build vs. run) and the SDKs to configure with.
self.sdks_to_configure = set()
for name in args.cross_compile_stdlib_deployment_targets:
dpymt_target = StdlibDeploymentTarget.get_target_for_name(name)
if dpymt_target is None:
diagnostics.fatal("unknown stdlib target: %r" % (
name))
else:
self.stdlib_targets_to_configure.append(dpymt_target)

# [*] Compute the list of deployment targets to build.
#
# Even though we don't need to configure host_target, we do need
# to explicitly build it.
# So by default, build all configured targets + the host

self.stdlib_targets_to_build = [self.host_target]
self.stdlib_targets_to_build += self.stdlib_targets_to_configure

if host_target == args.host_target and \
"all" not in args.build_stdlib_deployment_targets:
self.stdlib_targets_to_build = \
[t for t in self.stdlib_targets_to_build
if t.name in args.build_stdlib_deployment_targets]

# [*] Compute the lists of **CMake** build/run targets

self.swift_stdlib_build_targets = []
self.swift_test_run_targets = []
self.swift_benchmark_build_targets = []
self.swift_benchmark_run_targets = []
for deployment_target_name in stdlib_targets_to_configure:
# Get the target object.
deployment_target = StdlibDeploymentTarget.get_target_for_name(
deployment_target_name)
if deployment_target is None:
diagnostics.fatal("unknown target: %r" % (
deployment_target_name,))

# Add the SDK to use.
deployment_platform = deployment_target.platform
self.sdks_to_configure.add(deployment_platform.sdk_name)
for deployment_target in self.stdlib_targets_to_build:

# If we aren't actually building this target (only configuring
# it), do nothing else.
if deployment_target_name not in stdlib_targets_to_build:
continue
deployment_platform = deployment_target.platform
name = deployment_target.name

# Compute which actions are desired.
build = (
Expand All @@ -139,7 +149,6 @@ class HostSpecificConfiguration(object):
else:
test = False

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

if args.host_target is None or args.stdlib_deployment_targets is None:
if args.host_target is None:
diagnostics.fatal("unknown operating system")

if args.symbols_package:
Expand Down Expand Up @@ -397,17 +406,19 @@ class BuildScriptInvocation(object):
args.build_subdir = \
swift_build_support.workspace.compute_build_subdir(args)

# Add optional stdlib-deployment-targets
# Add optional cross-compile-stdlib-deployment-targets
if args.android:
args.stdlib_deployment_targets.append(
args.cross_compile_stdlib_deployment_targets.append(
StdlibDeploymentTarget.Android.armv7.name)

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

android_tgts = [tgt for tgt in args.stdlib_deployment_targets
if StdlibDeploymentTarget.Android.contains(tgt)]
android_tgts = \
[tgt for tgt in args.cross_compile_stdlib_deployment_targets
if StdlibDeploymentTarget.Android.contains(tgt)]

if not args.android and len(android_tgts) > 0:
args.android = True
args.skip_build_android = True
Expand Down Expand Up @@ -542,8 +553,6 @@ class BuildScriptInvocation(object):
"--build-dir", self.workspace.build_root,
"--install-prefix", args.install_prefix,
"--host-target", args.host_target,
"--stdlib-deployment-targets",
" ".join(args.stdlib_deployment_targets),
"--host-cc", toolchain.cc,
"--host-cxx", toolchain.cxx,
"--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain,
Expand Down Expand Up @@ -576,10 +585,24 @@ class BuildScriptInvocation(object):
pipes.quote(arg) for arg in cmake.build_args()),
]

# Specify additional stdlib targets to configure. Remove zero-length
# names.
args.cross_compile_stdlib_deployment_targets = \
[t for t in args.cross_compile_stdlib_deployment_targets
if len(t) > 0]

if args.cross_compile_stdlib_deployment_targets is not None and \
len(args.cross_compile_stdlib_deployment_targets) > 0 and \
'none' not in args.cross_compile_stdlib_deployment_targets:
impl_args += ["--cross-compile-stdlib-deployment-targets",
" ".join(
args.cross_compile_stdlib_deployment_targets)]
# Specify stdlib targets to build
if args.build_stdlib_deployment_targets:
impl_args += [
"--build-stdlib-deployment-targets", " ".join(
args.build_stdlib_deployment_targets)]
# Specify additional hosts to configure + build
if args.cross_compile_hosts:
impl_args += [
"--cross-compile-hosts", " ".join(args.cross_compile_hosts)]
Expand Down Expand Up @@ -783,16 +806,18 @@ class BuildScriptInvocation(object):
config = HostSpecificConfiguration(host_target, self)

# Convert into `build-script-impl` style variables.
stdlib_target_names = [t.name for t
in config.stdlib_targets_to_configure]
options[host_target] = {
"SWIFT_SDKS": " ".join(sorted(
config.sdks_to_configure)),
"SWIFT_STDLIB_TARGETS": " ".join(
"SWIFT_CROSS_COMPILE_STDLIB_TARGETS": " ".join(
stdlib_target_names),
"SWIFT_STDLIB_BUILD_TARGETS": " ".join(
config.swift_stdlib_build_targets),
"SWIFT_BENCHMARK_TARGETS": " ".join(
"SWIFT_BENCHMARK_BUILD_TARGETS": " ".join(
config.swift_benchmark_build_targets),
"SWIFT_RUN_BENCHMARK_TARGETS": " ".join(
"SWIFT_BENCHMARK_RUN_TARGETS": " ".join(
config.swift_benchmark_run_targets),
"SWIFT_TEST_TARGETS": " ".join(
"SWIFT_TEST_RUN_TARGETS": " ".join(
config.swift_test_run_targets),
}

Expand Down Expand Up @@ -1088,15 +1113,14 @@ details of the setups of other systems or automated environments.""")
"tools for. Can be used multiple times.",
action=arguments.action.concat, type=arguments.type.shell_split,
default=[])
stdlib_targets = StdlibDeploymentTarget.default_stdlib_deployment_targets()
default_cross_stdlib_targets = StdlibDeploymentTarget\
.default_cross_compile_stdlib_targets()
targets_group.add_argument(
"--stdlib-deployment-targets",
help="list of targets to compile or cross-compile the Swift standard "
"--cross-compile-stdlib-deployment-targets",
help="list of targets to cross-compile the Swift standard "
"library for. %(default)s by default.",
nargs="*",
default=[
target.name
for target in stdlib_targets])
default=[t.name for t in default_cross_stdlib_targets])
targets_group.add_argument(
"--build-stdlib-deployment-targets",
help="A space-separated list that filters which of the configured "
Expand Down
Loading