Skip to content

Commit

Permalink
Add the apple.no_legacy_swiftinterface feature to disable the automat…
Browse files Browse the repository at this point in the history
…ic library evolution transition on framework rules
  • Loading branch information
sewerynplazuk committed Apr 8, 2024
1 parent 8096c8d commit ed24ce9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
41 changes: 33 additions & 8 deletions apple/internal/transition_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def _resolved_environment_arch_for_arch(*, arch, environment, platform_type):

def _command_line_options_for_xcframework_platform(
*,
attr,
minimum_os_version,
platform_attr,
platform_type,
Expand All @@ -328,6 +329,7 @@ def _command_line_options_for_xcframework_platform(
"""Generates a dictionary of command line options keyed by 1:2+ transition for this platform.
Args:
attr: The attributes passed to the transition function.
minimum_os_version: A string representing the minimum OS version specified for this
platform, represented as a dotted version number (for example, `"9.0"`).
platform_attr: The attribute for the apple platform specifying in dictionary form which
Expand Down Expand Up @@ -361,7 +363,10 @@ def _command_line_options_for_xcframework_platform(
environment = target_environment,
platform_type = platform_type,
): _command_line_options(
emit_swiftinterface = True,
emit_swiftinterface = _should_emit_swiftinterface(
attr,
is_xcframework = True,
),
environment_arch = resolved_environment_arch,
minimum_os_version = minimum_os_version,
platform_type = platform_type,
Expand All @@ -372,11 +377,33 @@ def _command_line_options_for_xcframework_platform(

return output_dictionary

def _should_emit_swiftinterface(attr, is_xcframework = False):
"""Determines if a .swiftinterface file should be generated for Swift dependencies.
This is temporary while we migrate users of the framework rules to enable
library evolution on specific targets instead of having it automatically
applied to the entire dependency subgraph.
"""

# TODO(b/239957001): Delete all this when everyone is migrated to the new
# `library_evolution` attribute on `swift_library`.
features = getattr(attr, "features", [])

# Post cl/558262406, features could be a SelectorList
# TODO: @aranguyen b/297016619
if type(features) == "list" and "apple.no_legacy_swiftinterface" in features:
return False

# iOS and tvOS static frameworks require underlying swift_library targets generate a Swift
# interface file. These rules define a private attribute called `_emitswiftinterface` that
# let's this transition flip rules_swift config down the build graph.
return is_xcframework or hasattr(attr, "_emitswiftinterface")

def _apple_rule_base_transition_impl(settings, attr):
"""Rule transition for Apple rules using Bazel CPUs and a valid Apple split transition."""
platform_type = attr.platform_type
return _command_line_options(
emit_swiftinterface = hasattr(attr, "_emitswiftinterface"),
emit_swiftinterface = _should_emit_swiftinterface(attr),
environment_arch = _environment_archs(platform_type, settings)[0],
minimum_os_version = attr.minimum_os_version,
platform_type = platform_type,
Expand Down Expand Up @@ -447,7 +474,7 @@ def _apple_platforms_rule_base_transition_impl(settings, attr):
environment_arch = _environment_archs(platform_type, settings)[0]
return _command_line_options(
apple_platforms = settings["//command_line_option:apple_platforms"],
emit_swiftinterface = hasattr(attr, "_emitswiftinterface"),
emit_swiftinterface = _should_emit_swiftinterface(attr),
environment_arch = environment_arch,
minimum_os_version = minimum_os_version,
platform_type = platform_type,
Expand All @@ -470,7 +497,7 @@ def _apple_platforms_rule_bundle_output_base_transition_impl(settings, attr):
environment_arch = _environment_archs(platform_type, settings)[0]
return _command_line_options(
apple_platforms = settings["//command_line_option:apple_platforms"],
emit_swiftinterface = hasattr(attr, "_emitswiftinterface"),
emit_swiftinterface = _should_emit_swiftinterface(attr),
environment_arch = environment_arch,
force_bundle_outputs = True,
minimum_os_version = minimum_os_version,
Expand Down Expand Up @@ -547,10 +574,7 @@ def _apple_platform_split_transition_impl(settings, attr):
output_dictionary = {}
invalid_requested_archs = []

# iOS and tvOS static frameworks require underlying swift_library targets generate a Swift
# interface file. These rules define a private attribute called `_emitswiftinterface` that
# let's this transition flip rules_swift config down the build graph.
emit_swiftinterface = hasattr(attr, "_emitswiftinterface")
emit_swiftinterface = _should_emit_swiftinterface(attr)

if settings["//command_line_option:incompatible_enable_apple_toolchain_resolution"]:
platforms = (
Expand Down Expand Up @@ -665,6 +689,7 @@ def _xcframework_transition_impl(settings, attr):
target_environments.append("simulator")

command_line_options = _command_line_options_for_xcframework_platform(
attr = attr,
minimum_os_version = attr.minimum_os_versions.get(platform_type),
platform_attr = getattr(attr, platform_type),
platform_type = platform_type,
Expand Down
3 changes: 0 additions & 3 deletions test/starlark_tests/targets_under_test/apple/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,6 @@ apple_xcframework(
name = "ios_swift_3p_xcframework_with_generated_header",
bundle_id = "com.google.example",
bundle_name = "Swift3PFmwkWithGenHeader",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
infoplists = [
"//test/starlark_tests/resources:Info.plist",
],
Expand Down
3 changes: 0 additions & 3 deletions test/starlark_tests/targets_under_test/ios/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3885,9 +3885,6 @@ ios_static_framework(
ios_static_framework(
name = "static_framework_with_generated_header",
bundle_name = "SwiftStaticFmwkWithGenHeader",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
minimum_os_version = common.min_os_ios.baseline,
tags = common.fixture_tags,
deps = [":SwiftStaticFmwkWithGenHeader"],
Expand Down

0 comments on commit ed24ce9

Please sign in to comment.