Skip to content
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

Add the apple.no_legacy_swiftinterface feature to disable the automatic library evolution transition on framework rules. #2104

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
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
39 changes: 32 additions & 7 deletions apple/internal/transition_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,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 @@ -293,6 +294,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 @@ -326,7 +328,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 @@ -337,11 +342,33 @@ def _command_line_options_for_xcframework_platform(

return output_dictionary

def _should_emit_swiftinterface(attr, is_xcframework = False):
"""Whether a .swiftinterface file should be emitted 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 @@ -408,7 +435,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 = attr.minimum_os_version,
platform_type = platform_type,
Expand Down Expand Up @@ -482,10 +509,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 @@ -599,6 +623,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
65 changes: 65 additions & 0 deletions test/starlark_tests/targets_under_test/apple/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ objc_library(
swift_library(
name = "swift_lib_for_static_xcfmwk",
srcs = ["DummyFmwk.swift"],
library_evolution = True,
module_name = "ios_static_xcfmwk_with_swift",
tags = common.fixture_tags,
)
Expand All @@ -283,6 +284,7 @@ swift_library(
name = "swift_lib_for_static_xcfmwk_with_headers",
srcs = ["DummyFmwk.swift"],
generates_header = True,
library_evolution = True,
module_name = "ios_static_xcfmwk_with_swift_generated_headers",
tags = common.fixture_tags,
)
Expand All @@ -291,6 +293,7 @@ swift_library(
name = "swift_lib_for_static_xcfmwk_custom_bundle_name",
srcs = ["DummyFmwk.swift"],
generates_header = True,
library_evolution = True,
module_name = "ios_static_xcfmwk_with_custom_bundle_name",
tags = common.fixture_tags,
)
Expand All @@ -300,6 +303,7 @@ swift_library(
srcs = [
"DummyFmwk.swift",
],
library_evolution = True,
module_name = "ios_dynamic_lipoed_swift_xcframework",
tags = common.fixture_tags,
)
Expand All @@ -311,6 +315,9 @@ dummy_test_runner(
apple_xcframework(
name = "ios_dynamic_xcframework",
bundle_id = "com.google.example",
# 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 Expand Up @@ -590,6 +597,9 @@ apple_static_xcframework_import(
apple_xcframework(
name = "tvos_dynamic_xcframework",
bundle_id = "com.google.example",
# 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 Expand Up @@ -618,6 +628,9 @@ apple_xcframework(
apple_xcframework(
name = "ios_dynamic_lipoed_xcframework",
bundle_id = "com.google.example",
# 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 All @@ -644,6 +657,9 @@ apple_xcframework(
apple_xcframework(
name = "ios_dynamic_lipoed_swift_xcframework",
bundle_id = "com.google.example",
# 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 All @@ -669,6 +685,9 @@ apple_xcframework(
families_required = {
"ios": ["ipad"],
},
# 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",
"//test/starlark_tests/resources:Another.plist",
Expand All @@ -690,6 +709,9 @@ apple_xcframework(
apple_xcframework(
name = "ios_dynamic_xcframework_multiple_infoplists",
bundle_id = "com.google.example",
# 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",
"//test/starlark_tests/resources:Another.plist",
Expand All @@ -715,6 +737,9 @@ apple_xcframework(
"//test/starlark_tests/resources:Another.plist",
"//test/starlark_tests/resources:resource_bundle",
],
# 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 All @@ -735,6 +760,9 @@ apple_xcframework(
apple_xcframework(
name = "ios_dynamic_xcframework_with_deps_resource_bundle",
bundle_id = "com.google.example",
# 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 All @@ -761,6 +789,9 @@ apple_xcframework(
exported_symbols_lists = [
"//test/starlark_tests/resources:ExportAnotherFunctionShared.exp",
],
# 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 All @@ -786,6 +817,9 @@ apple_xcframework(
"//test/starlark_tests/resources:ExportAnotherFunctionShared.exp",
"//test/starlark_tests/resources:ExportDontCallMeShared.exp",
],
# 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 All @@ -810,6 +844,9 @@ apple_xcframework(
exported_symbols_lists = [
"//test/starlark_tests/resources:ExportAnotherFunctionShared.exp",
],
# 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 All @@ -832,6 +869,9 @@ apple_xcframework(
name = "ios_swift_xcframework_with_generated_header",
bundle_id = "com.google.example",
bundle_name = "SwiftFmwkWithGenHeader",
# 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 Expand Up @@ -889,6 +929,9 @@ apple_xcframework(
name = "ios_dynamic_xcframework_with_umbrella_header_conflict",
bundle_id = "com.google.example",
bundle_name = "UmbrellaHeaderConflict",
# 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 All @@ -909,6 +952,9 @@ apple_xcframework(

apple_static_xcframework(
name = "ios_static_xcframework_oldest_supported",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
ios = {
"simulator": [
"x86_64",
Expand Down Expand Up @@ -1051,6 +1097,9 @@ apple_static_xcframework(
apple_static_xcframework(
name = "ios_static_xcfmwk_with_avoid_deps",
avoid_deps = [":StaticFmwkLowerLib"],
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
ios = {
"simulator": [
"x86_64",
Expand All @@ -1067,6 +1116,9 @@ apple_static_xcframework(

apple_static_xcframework(
name = "ios_static_xcfmwk_with_objc_sdk_dylibs_and_and_sdk_frameworks",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
ios = {
"device": ["arm64"],
},
Expand All @@ -1082,6 +1134,9 @@ apple_static_xcframework(

apple_static_xcframework(
name = "ios_static_xcfmwk_with_swift",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
ios = {
"device": ["arm64"],
"simulator": [
Expand All @@ -1099,6 +1154,9 @@ apple_static_xcframework(
apple_static_xcframework(
name = "ios_static_xcfmwk_with_swift_and_bundle_name",
bundle_name = "ios_static_xcfmwk_with_custom_bundle_name",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
ios = {
"device": ["arm64"],
"simulator": [
Expand All @@ -1115,6 +1173,9 @@ apple_static_xcframework(

apple_static_xcframework(
name = "ios_static_xcfmwk_with_swift_generated_headers",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
ios = {
"device": ["arm64"],
"simulator": [
Expand All @@ -1134,6 +1195,9 @@ apple_static_xcframework(

apple_static_xcframework(
name = "ios_static_xcframework",
# TODO(b/239957001): Remove this when the rule no longer forces library
# evolution.
features = ["apple.no_legacy_swiftinterface"],
ios = {
"simulator": [
"arm64",
Expand Down Expand Up @@ -1232,6 +1296,7 @@ swift_library(
name = "SwiftFmwkWithGenHeader",
srcs = ["DummyFmwk.swift"],
generates_header = True,
library_evolution = True,
module_name = "SwiftFmwkWithGenHeader",
tags = common.fixture_tags,
)
Expand Down
Loading