Skip to content

Commit

Permalink
Add apple.no_legacy_swiftinterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
sewerynplazuk committed Mar 20, 2024
1 parent e8d412e commit 0f7c508
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 70 deletions.
6 changes: 0 additions & 6 deletions apple/build_settings/build_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ Enables Bazel's tree artifacts for Apple bundle rules (instead of archives).
""",
default = False,
),
"use_library_evolution": struct(
doc = """
Enables library evolution, allowing for the emission of .swiftinterface files.
""",
default = True,
),
}

_BUILD_SETTING_LABELS = {
Expand Down
21 changes: 11 additions & 10 deletions apple/internal/transition_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ def _command_line_options(
default_platforms = [settings[_CPU_TO_DEFAULT_PLATFORM_FLAG[cpu]]] if _is_bazel_7 else []
return {
build_settings_labels.use_tree_artifacts_outputs: force_bundle_outputs if force_bundle_outputs else settings[build_settings_labels.use_tree_artifacts_outputs],
build_settings_labels.use_library_evolution: settings[build_settings_labels.use_library_evolution],
"//command_line_option:apple configuration distinguisher": "applebin_" + platform_type,
"//command_line_option:apple_platform_type": platform_type,
"//command_line_option:apple_platforms": apple_platforms,
Expand Down Expand Up @@ -321,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 @@ -329,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 @@ -363,7 +364,7 @@ def _command_line_options_for_xcframework_platform(
platform_type = platform_type,
): _command_line_options(
emit_swiftinterface = _should_emit_swiftinterface(
settings,
attr,
is_xcframework = True,
),
environment_arch = resolved_environment_arch,
Expand All @@ -376,15 +377,16 @@ def _command_line_options_for_xcframework_platform(

return output_dictionary

def _should_emit_swiftinterface(settings, is_xcframework = False):
def _should_emit_swiftinterface(attr, is_xcframework = False):
"""Determines if a .swiftinterface file should be generated for Swift dependencies.
By providing the option to disable the emission of these files, it allows consumers to opt out
of library evolution features, offering flexibility in how Swift dependencies are integrated and managed.
"""

# Do not emit swiftinterface file when library evolution is disabled for a given build
if not settings[build_settings_labels.use_library_evolution]:
features = getattr(attr, "features", [])
if type(features) == "list" and "apple.no_legacy_swiftinterface" in features:
return False

# For iOS and tvOS static frameworks, it's historically been required for the underlying swift_library targets
Expand All @@ -397,7 +399,7 @@ 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 = _should_emit_swiftinterface(settings),
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 All @@ -410,7 +412,6 @@ def _apple_rule_base_transition_impl(settings, attr):
# - https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
_apple_rule_common_transition_inputs = [
build_settings_labels.use_tree_artifacts_outputs,
build_settings_labels.use_library_evolution,
"//command_line_option:apple_crosstool_top",
] + _CPU_TO_DEFAULT_PLATFORM_FLAG.values()
_apple_rule_base_transition_inputs = _apple_rule_common_transition_inputs + [
Expand All @@ -429,7 +430,6 @@ _apple_platform_transition_inputs = _apple_platforms_rule_base_transition_inputs
]
_apple_rule_base_transition_outputs = [
build_settings_labels.use_tree_artifacts_outputs,
build_settings_labels.use_library_evolution,
"//command_line_option:apple configuration distinguisher",
"//command_line_option:apple_platform_type",
"//command_line_option:apple_platforms",
Expand Down Expand Up @@ -470,7 +470,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 = _should_emit_swiftinterface(settings),
emit_swiftinterface = _should_emit_swiftinterface(attr),
environment_arch = environment_arch,
minimum_os_version = minimum_os_version,
platform_type = platform_type,
Expand All @@ -493,7 +493,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 = _should_emit_swiftinterface(settings),
emit_swiftinterface = _should_emit_swiftinterface(attr),
environment_arch = environment_arch,
force_bundle_outputs = True,
minimum_os_version = minimum_os_version,
Expand Down Expand Up @@ -570,7 +570,7 @@ def _apple_platform_split_transition_impl(settings, attr):
output_dictionary = {}
invalid_requested_archs = []

emit_swiftinterface = _should_emit_swiftinterface(settings)
emit_swiftinterface = _should_emit_swiftinterface(attr)

if settings["//command_line_option:incompatible_enable_apple_toolchain_resolution"]:
platforms = (
Expand Down Expand Up @@ -685,6 +685,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
7 changes: 0 additions & 7 deletions test/starlark_tests/apple_static_xcframework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ load(
":common.bzl",
"common",
)
load(
"@build_bazel_rules_apple//apple/build_settings:build_settings.bzl",
"build_settings_labels",
)
load(
"//test/starlark_tests/rules:common_verification_tests.bzl",
"archive_contents_test",
Expand Down Expand Up @@ -131,9 +127,6 @@ def apple_static_xcframework_test_suite(name):
name = "{}_swift_generates_header_test".format(name),
build_type = "device",
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_static_xcfmwk_with_swift_generated_headers",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/Info.plist",
"$BUNDLE_ROOT/ios-arm64/ios_static_xcfmwk_with_swift_generated_headers.framework/Headers/ios_static_xcfmwk_with_swift_generated_headers.h",
Expand Down
8 changes: 1 addition & 7 deletions test/starlark_tests/apple_xcframework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ load(
":common.bzl",
"common",
)
load(
"@build_bazel_rules_apple//apple/build_settings:build_settings.bzl",
"build_settings_labels",
)

load(
"//test/starlark_tests/rules:analysis_failure_message_test.bzl",
"analysis_failure_message_test",
Expand Down Expand Up @@ -489,9 +486,6 @@ def apple_xcframework_test_suite(name):
build_type = "simulator",
compilation_mode = "opt",
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_swift_xcframework_with_generated_header",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/ios-arm64_x86_64-simulator/SwiftFmwkWithGenHeader.framework/Headers/SwiftFmwkWithGenHeader.h",
"$BUNDLE_ROOT/ios-arm64_x86_64-simulator/SwiftFmwkWithGenHeader.framework/Modules/module.modulemap",
Expand Down
7 changes: 0 additions & 7 deletions test/starlark_tests/ios_framework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ load(
":common.bzl",
"common",
)
load(
"@build_bazel_rules_apple//apple/build_settings:build_settings.bzl",
"build_settings_labels",
)
load(
"//test/starlark_tests/rules:analysis_failure_message_test.bzl",
"analysis_failure_message_test",
Expand Down Expand Up @@ -415,9 +411,6 @@ def ios_framework_test_suite(name):
name = "{}_static_framework_contains_swiftinterface".format(name),
build_type = "simulator",
target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_static_framework",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/Headers/swift_framework_lib.h",
"$BUNDLE_ROOT/Modules/swift_framework_lib.swiftmodule/x86_64.swiftdoc",
Expand Down
10 changes: 0 additions & 10 deletions test/starlark_tests/ios_static_framework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ load(
":common.bzl",
"common",
)
load(
"@build_bazel_rules_apple//apple/build_settings:build_settings.bzl",
"build_settings_labels",
)
load(
"//test/starlark_tests/rules:analysis_failure_message_test.bzl",
"analysis_failure_message_test",
Expand Down Expand Up @@ -122,9 +118,6 @@ def ios_static_framework_test_suite(name):
build_type = "simulator",
compilation_mode = "opt",
target_under_test = "//test/starlark_tests/targets_under_test/ios:static_fmwk_with_swift_and_avoid_deps",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/Modules/SwiftFmwkUpperLib.swiftmodule/x86_64.swiftdoc",
"$BUNDLE_ROOT/Modules/SwiftFmwkUpperLib.swiftmodule/x86_64.swiftinterface",
Expand Down Expand Up @@ -191,9 +184,6 @@ def ios_static_framework_test_suite(name):
build_type = "simulator",
compilation_mode = "opt",
target_under_test = "//test/starlark_tests/targets_under_test/ios:static_framework_with_generated_header",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/Headers/SwiftStaticFmwkWithGenHeader.h",
"$BUNDLE_ROOT/Modules/module.modulemap",
Expand Down
7 changes: 0 additions & 7 deletions test/starlark_tests/macos_framework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ load(
":common.bzl",
"common",
)
load(
"@build_bazel_rules_apple//apple/build_settings:build_settings.bzl",
"build_settings_labels",
)
load(
"//test/starlark_tests/rules:common_verification_tests.bzl",
"archive_contents_test",
Expand Down Expand Up @@ -341,9 +337,6 @@ def macos_framework_test_suite(name):
name = "{}_static_framework_contains_swiftinterface".format(name),
build_type = "simulator",
target_under_test = "//test/starlark_tests/targets_under_test/macos:swift_static_framework",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/Headers/swift_framework_lib.h",
"$BUNDLE_ROOT/Modules/swift_framework_lib.swiftmodule/x86_64.swiftdoc",
Expand Down
10 changes: 0 additions & 10 deletions test/starlark_tests/macos_static_framework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ load(
":common.bzl",
"common",
)
load(
"@build_bazel_rules_apple//apple/build_settings:build_settings.bzl",
"build_settings_labels",
)
load(
"//test/starlark_tests/rules:analysis_failure_message_test.bzl",
"analysis_failure_message_test",
Expand Down Expand Up @@ -92,9 +88,6 @@ def macos_static_framework_test_suite(name):
build_type = "simulator",
compilation_mode = "opt",
target_under_test = "//test/starlark_tests/targets_under_test/macos:static_fmwk_with_swift_and_avoid_deps",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/Modules/SwiftFmwkUpperLib.swiftmodule/x86_64.swiftdoc",
"$BUNDLE_ROOT/Modules/SwiftFmwkUpperLib.swiftmodule/x86_64.swiftinterface",
Expand Down Expand Up @@ -161,9 +154,6 @@ def macos_static_framework_test_suite(name):
build_type = "simulator",
compilation_mode = "opt",
target_under_test = "//test/starlark_tests/targets_under_test/macos:static_framework_with_generated_header",
build_settings = {
build_settings_labels.use_library_evolution: "True",
},
contains = [
"$BUNDLE_ROOT/Headers/SwiftFmwkWithGenHeader.h",
"$BUNDLE_ROOT/Modules/module.modulemap",
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 @@ -862,9 +862,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 @@ -3868,9 +3868,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 0f7c508

Please sign in to comment.