Skip to content

Commit bc6e8d2

Browse files
allevatoluispadron
authored andcommitted
Flip the default fallback value for _building_apple_bundle to True, and manually set it to False for rules that don't bundle.
This ensures that other users of our transitions on custom rules share any actions/configurations with the targets when they are nested under a bundle (the common case for users of the Apple transitions). Cherry-pick: c8de42c
1 parent ad19faa commit bc6e8d2

4 files changed

Lines changed: 35 additions & 7 deletions

File tree

apple/internal/apple_universal_binary.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ binary will be built for all of the specified architectures instead.
105105
This is primarily useful to force macOS tools to be built as universal binaries using
106106
`forced_cpus = ["x86_64", "arm64"]`, without requiring the user to pass additional flags when
107107
invoking Bazel.
108+
""",
109+
),
110+
"_building_apple_bundle": attr.bool(
111+
default = False,
112+
doc = """
113+
Internal attribute read by Apple rule transitions to set the
114+
`building_apple_bundle` build setting.
108115
""",
109116
),
110117
},

apple/internal/macos_rules.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,7 @@ Targets created with `macos_command_line_application` can be executed using
27042704
apple_resource_aspect,
27052705
framework_provider_aspect,
27062706
],
2707+
is_bundling_rule = False,
27072708
is_test_supporting_rule = False,
27082709
requires_legacy_cc_toolchain = True,
27092710
),
@@ -2760,6 +2761,7 @@ macos_dylib = rule_factory.create_apple_rule(
27602761
apple_resource_aspect,
27612762
framework_provider_aspect,
27622763
],
2764+
is_bundling_rule = False,
27632765
is_test_supporting_rule = False,
27642766
requires_legacy_cc_toolchain = True,
27652767
),

apple/internal/rule_attrs.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def _binary_linking_attrs(
147147
*,
148148
deps_cfg,
149149
extra_deps_aspects = [],
150+
is_bundling_rule = True,
150151
is_test_supporting_rule,
151152
requires_legacy_cc_toolchain):
152153
"""Returns dictionary of required attributes for apple_common.link_multi_arch_binary.
@@ -157,6 +158,9 @@ def _binary_linking_attrs(
157158
use the same transition.
158159
extra_deps_aspects: A list of aspects to apply to deps in addition to the defaults.
159160
Optional.
161+
is_bundling_rule: Boolean. Indicates if the binary being linked will be placed inside an
162+
Apple bundle target (as opposed to a standalone binary, like a command line application
163+
or dylib).
160164
is_test_supporting_rule: Boolean. Indicates if this rule is intended to be used as a
161165
dependency of a test rule, such as a test bundle rule generated by an ios_unit_test
162166
macro.
@@ -169,6 +173,20 @@ def _binary_linking_attrs(
169173
deps_aspects.extend(extra_deps_aspects)
170174
extra_attrs = {}
171175

176+
if not is_bundling_rule:
177+
# For bundling rules, the `_building_apple_bundle` attribute will be
178+
# provided by `common_bundle_attrs`. We require adding it manually for
179+
# non-bundling rules so that they can override the fallback value of
180+
# `True` used by the transition (which is needed to prevent spikes in
181+
# configuration/action counts for other users of the transitions).
182+
extra_attrs["_building_apple_bundle"] = attr.bool(
183+
default = False,
184+
doc = """
185+
Internal attribute read by Apple rule transitions to set the
186+
`building_apple_bundle` build setting.
187+
""",
188+
)
189+
172190
default_stamp = -1
173191
if is_test_supporting_rule:
174192
deps_aspects.append(apple_test_info_aspect)

apple/internal/transition_support.bzl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def _is_arch_supported_for_target_tuple(*, environment_arch, minimum_os_version,
304304
def _command_line_options(
305305
*,
306306
apple_platforms = [],
307-
building_apple_bundle = False,
307+
building_apple_bundle,
308308
environment_arch = None,
309309
force_bundle_outputs = False,
310310
minimum_os_version,
@@ -475,7 +475,7 @@ def _apple_rule_base_transition_impl(settings, attr):
475475
"""Rule transition for Apple rules using Bazel CPUs and a valid Apple split transition."""
476476
minimum_os_version = attr.minimum_os_version
477477
platform_type = attr.platform_type
478-
building_apple_bundle = getattr(attr, "_building_apple_bundle", False)
478+
building_apple_bundle = getattr(attr, "_building_apple_bundle", True)
479479
return _command_line_options(
480480
building_apple_bundle = building_apple_bundle,
481481
environment_arch = _environment_archs(platform_type, minimum_os_version, settings)[0],
@@ -539,7 +539,7 @@ def _apple_platforms_rule_base_transition_impl(settings, attr):
539539
"""Rule transition for Apple rules using Bazel platforms and the Starlark split transition."""
540540
minimum_os_version = attr.minimum_os_version
541541
platform_type = attr.platform_type
542-
building_apple_bundle = getattr(attr, "_building_apple_bundle", False)
542+
building_apple_bundle = getattr(attr, "_building_apple_bundle", True)
543543
environment_arch = None
544544
if not settings["//command_line_option:incompatible_enable_apple_toolchain_resolution"]:
545545
# Add fallback to match an anticipated split of Apple cpu-based resolution
@@ -563,7 +563,7 @@ def _apple_platforms_rule_bundle_output_base_transition_impl(settings, attr):
563563
"""Rule transition for Apple rules using Bazel platforms which force bundle outputs."""
564564
minimum_os_version = attr.minimum_os_version
565565
platform_type = attr.platform_type
566-
building_apple_bundle = getattr(attr, "_building_apple_bundle", False)
566+
building_apple_bundle = getattr(attr, "_building_apple_bundle", True)
567567
environment_arch = None
568568
if not settings["//command_line_option:incompatible_enable_apple_toolchain_resolution"]:
569569
# Add fallback to match an anticipated split of Apple cpu-based resolution
@@ -671,7 +671,7 @@ def _apple_platform_split_transition_impl(settings, attr):
671671
if str(platform) not in output_dictionary:
672672
output_dictionary[str(platform)] = _command_line_options(
673673
apple_platforms = apple_platforms,
674-
building_apple_bundle = getattr(attr, "_building_apple_bundle", False),
674+
building_apple_bundle = getattr(attr, "_building_apple_bundle", True),
675675
minimum_os_version = attr.minimum_os_version,
676676
platform_type = attr.platform_type,
677677
settings = settings,
@@ -680,7 +680,7 @@ def _apple_platform_split_transition_impl(settings, attr):
680680
else:
681681
minimum_os_version = attr.minimum_os_version
682682
platform_type = attr.platform_type
683-
building_apple_bundle = getattr(attr, "_building_apple_bundle", False)
683+
building_apple_bundle = getattr(attr, "_building_apple_bundle", True)
684684
for environment_arch in _environment_archs(platform_type, minimum_os_version, settings):
685685
found_cpu = _cpu_string(
686686
environment_arch = environment_arch,
@@ -759,6 +759,7 @@ def _xcframework_base_transition_impl(settings, _):
759759
# incoming settings meant for other platforms overriding the settings for the xcframework rule's
760760
# underlying actions, and allow for toolchain resolution in the future.
761761
return _command_line_options(
762+
building_apple_bundle = False,
762763
environment_arch = _DEFAULT_ARCH,
763764
minimum_os_version = None,
764765
platform_type = "macos",
@@ -790,7 +791,7 @@ def _xcframework_split_transition_impl(settings, attr):
790791
target_environments.append("simulator")
791792

792793
command_line_options = _command_line_options_for_xcframework_platform(
793-
building_apple_bundle = getattr(attr, "_building_apple_bundle", False),
794+
building_apple_bundle = getattr(attr, "_building_apple_bundle", True),
794795
minimum_os_version = attr.minimum_os_versions.get(platform_type),
795796
platform_attr = platform_attr,
796797
platform_type = platform_type,

0 commit comments

Comments
 (0)