From 0f7c50885905f0b156db45d6f94e40ae59c61251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seweryn=20Plaz=CC=87uk?= Date: Wed, 20 Mar 2024 16:04:57 +0100 Subject: [PATCH] Add apple.no_legacy_swiftinterface. --- apple/build_settings/build_settings.bzl | 6 ------ apple/internal/transition_support.bzl | 21 ++++++++++--------- .../apple_static_xcframework_tests.bzl | 7 ------- .../apple_xcframework_tests.bzl | 8 +------ test/starlark_tests/ios_framework_tests.bzl | 7 ------- .../ios_static_framework_tests.bzl | 10 --------- test/starlark_tests/macos_framework_tests.bzl | 7 ------- .../macos_static_framework_tests.bzl | 10 --------- .../targets_under_test/apple/BUILD | 3 --- .../targets_under_test/ios/BUILD | 3 --- 10 files changed, 12 insertions(+), 70 deletions(-) diff --git a/apple/build_settings/build_settings.bzl b/apple/build_settings/build_settings.bzl index 8ed886a0eb..8858ac1980 100644 --- a/apple/build_settings/build_settings.bzl +++ b/apple/build_settings/build_settings.bzl @@ -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 = { diff --git a/apple/internal/transition_support.bzl b/apple/internal/transition_support.bzl index 9b08466af5..efa26621e9 100644 --- a/apple/internal/transition_support.bzl +++ b/apple/internal/transition_support.bzl @@ -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, @@ -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, @@ -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 @@ -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, @@ -376,7 +377,7 @@ 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 @@ -384,7 +385,8 @@ def _should_emit_swiftinterface(settings, is_xcframework = False): """ # 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 @@ -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, @@ -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 + [ @@ -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", @@ -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, @@ -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, @@ -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 = ( @@ -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, diff --git a/test/starlark_tests/apple_static_xcframework_tests.bzl b/test/starlark_tests/apple_static_xcframework_tests.bzl index f7eac9400b..11afc4eebb 100644 --- a/test/starlark_tests/apple_static_xcframework_tests.bzl +++ b/test/starlark_tests/apple_static_xcframework_tests.bzl @@ -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", @@ -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", diff --git a/test/starlark_tests/apple_xcframework_tests.bzl b/test/starlark_tests/apple_xcframework_tests.bzl index 7dcd0cac69..f28a17961d 100644 --- a/test/starlark_tests/apple_xcframework_tests.bzl +++ b/test/starlark_tests/apple_xcframework_tests.bzl @@ -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", @@ -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", diff --git a/test/starlark_tests/ios_framework_tests.bzl b/test/starlark_tests/ios_framework_tests.bzl index ccc993a2c5..6dea2db93b 100644 --- a/test/starlark_tests/ios_framework_tests.bzl +++ b/test/starlark_tests/ios_framework_tests.bzl @@ -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", @@ -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", diff --git a/test/starlark_tests/ios_static_framework_tests.bzl b/test/starlark_tests/ios_static_framework_tests.bzl index 9af34f72f1..c4596f458d 100644 --- a/test/starlark_tests/ios_static_framework_tests.bzl +++ b/test/starlark_tests/ios_static_framework_tests.bzl @@ -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", @@ -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", @@ -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", diff --git a/test/starlark_tests/macos_framework_tests.bzl b/test/starlark_tests/macos_framework_tests.bzl index 829a4bea3f..9a0caeb799 100644 --- a/test/starlark_tests/macos_framework_tests.bzl +++ b/test/starlark_tests/macos_framework_tests.bzl @@ -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", @@ -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", diff --git a/test/starlark_tests/macos_static_framework_tests.bzl b/test/starlark_tests/macos_static_framework_tests.bzl index e3edb3f467..9ca0d0fcba 100644 --- a/test/starlark_tests/macos_static_framework_tests.bzl +++ b/test/starlark_tests/macos_static_framework_tests.bzl @@ -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", @@ -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", @@ -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", diff --git a/test/starlark_tests/targets_under_test/apple/BUILD b/test/starlark_tests/targets_under_test/apple/BUILD index f3f0fd9716..337ecb7e76 100644 --- a/test/starlark_tests/targets_under_test/apple/BUILD +++ b/test/starlark_tests/targets_under_test/apple/BUILD @@ -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", ], diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 9a96320f6b..6dbfa3546b 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -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"],