Skip to content
Draft
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
1 change: 1 addition & 0 deletions proto/swift_proto_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def compile_swift_protos_for_target(
swift_infos = get_providers(compiler_deps, SwiftInfo),
target_name = target_label.name,
workspace_name = ctx.workspace_name,
minimum_os_version = ctx.attr.minimum_os_version,
)

module_context = compile_result.module_context
Expand Down
9 changes: 9 additions & 0 deletions swift/internal/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ the target as `testonly = True`.
mandatory = False,
),
} if include_dev_srch_paths_attrib else {},
{
"minimum_os_version": attr.string(
doc = """
An optional string indicating the minimum OS version supported by the target,
represented as a dotted version number (for example, "9.0").
""",
mandatory = False,
),
},
)

def swift_config_attrs():
Expand Down
6 changes: 6 additions & 0 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def compile(
target_name,
toolchains = None,
toolchain_type = SWIFT_TOOLCHAIN_TYPE,
minimum_os_version = None,
workspace_name):
"""Compiles a Swift module.

Expand Down Expand Up @@ -413,6 +414,10 @@ def compile(
toolchain_type: The toolchain type of the `swift_toolchain` which is
used for the proper selection of the execution platform inside
`run_toolchain_action`.
minimum_os_version: Overrides the `-target` os version. Either an
explicit dotted version number or the string "oldest", which will
translate to the oldest supported deployment version for the current
SDK.
workspace_name: The name of the workspace for which the code is being
compiled, which is used to determine unique file paths for some
outputs.
Expand Down Expand Up @@ -681,6 +686,7 @@ to use swift_common.compile(include_dev_srch_paths = ...) instead.\
genfiles_dir = feature_configuration._genfiles_dir,
include_dev_srch_paths = include_dev_srch_paths_value,
is_swift = True,
minimum_os_version = minimum_os_version,
module_name = module_name,
original_module_name = original_module_name,
package_name = package_name,
Expand Down
1 change: 1 addition & 0 deletions swift/internal/target_triples.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ target_triples = struct(
normalize_for_swift = _normalize_for_swift,
parse = _parse,
platform_name_for_swift = _platform_name_for_swift,
split_os_version = _split_os_version,
str = _str,
unversioned_os = _unversioned_os,
)
1 change: 1 addition & 0 deletions swift/swift_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def _swift_binary_impl(ctx):
toolchains = toolchains,
target_name = ctx.label.name,
workspace_name = ctx.workspace_name,
minimum_os_version = ctx.attr.minimum_os_version,
)
module_contexts.append(compile_result.module_context)
compilation_outputs = compile_result.compilation_outputs
Expand Down
1 change: 1 addition & 0 deletions swift/swift_compiler_plugin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def _swift_compiler_plugin_impl(ctx):
toolchains = toolchains,
target_name = ctx.label.name,
workspace_name = ctx.workspace_name,
minimum_os_version = ctx.attr.minimum_os_version,
)
module_context = compile_result.module_context
module_contexts.append(module_context)
Expand Down
1 change: 1 addition & 0 deletions swift/swift_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _swift_library_impl(ctx):
toolchains = toolchains,
target_name = ctx.label.name,
workspace_name = ctx.workspace_name,
minimum_os_version = ctx.attr.minimum_os_version,
)

module_context = compile_result.module_context
Expand Down
1 change: 1 addition & 0 deletions swift/swift_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def _do_compile(
toolchains = toolchains,
target_name = name,
workspace_name = workspace_name,
minimum_os_version = ctx.attr.minimum_os_version,
)

def _swift_test_impl(ctx):
Expand Down
54 changes: 52 additions & 2 deletions swift/toolchains/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,54 @@ def _make_resource_directory_configurator(developer_dir):

return _resource_directory_configurator

def _make_target_triple_configurator(base_target_triple, sdk_dir):
"""Creates a configurator that emits the -target and -sdk flags.

This configurator dynamically adjusts the target triple based on
the minimum_os_version prerequisite, if present.

Args:
base_target_triple: The default target triple from the toolchain.
sdk_dir: The SDK directory path.

Returns:
A configurator function.
"""

def _target_triple_configurator(prerequisites, args):
min_os = getattr(prerequisites, "minimum_os_version", None)
if min_os:
os, _ = target_triples.split_os_version(base_target_triple.os)

# Handle the "oldest" sentinel value.
# HACK: this should be collected from the SDK's Info.plist
if min_os == "oldest":
if os == "macos":
version = "10.13"
elif os == "ios":
version = "12.0"
else:
fail(
("Determining oldest deployment version for '{}' is " +
"unsupported").format(os),
)
else:
version = min_os

triple = target_triples.make(
cpu = base_target_triple.cpu,
vendor = base_target_triple.vendor,
os = "{}{}".format(os, version),
environment = base_target_triple.environment,
)
else:
triple = base_target_triple

args.add("-target", target_triples.str(triple))
args.add("-sdk", sdk_dir)

return _target_triple_configurator

def _all_action_configs(
additional_objc_copts,
additional_swiftc_copts,
Expand Down Expand Up @@ -448,8 +496,10 @@ def _all_action_configs(
SWIFT_ACTION_SYNTHESIZE_INTERFACE,
],
configurators = [
add_arg("-target", target_triples.str(target_triple)),
add_arg("-sdk", apple_toolchain.sdk_dir()),
_make_target_triple_configurator(
base_target_triple = target_triple,
sdk_dir = apple_toolchain.sdk_dir(),
),
],
),
]
Expand Down