@@ -304,6 +304,7 @@ def _is_arch_supported_for_target_tuple(*, environment_arch, minimum_os_version,
304304def _command_line_options (
305305 * ,
306306 apple_platforms = [],
307+ building_apple_bundle = False ,
307308 environment_arch = None ,
308309 force_bundle_outputs = False ,
309310 minimum_os_version ,
@@ -318,6 +319,8 @@ def _command_line_options(
318319 first element will be applied to `platforms` as that will be what is resolved by the
319320 underlying rule. Defaults to an empty list, which will signal to Bazel that platform
320321 mapping can take place as a fallback measure.
322+ building_apple_bundle: Indicates if the rule is building a bundle (rather than a
323+ standalone executable or library).
321324 environment_arch: A valid Apple environment when applicable with its architecture as a
322325 string (for example `sim_arm64` from `ios_sim_arm64`, or `arm64` from `ios_arm64`), or
323326 None to infer a value from command line options passed through settings.
@@ -343,6 +346,7 @@ def _command_line_options(
343346
344347 default_platforms = [settings [_CPU_TO_DEFAULT_PLATFORM_FLAG [cpu ]]] if _is_bazel_7 else []
345348 return {
349+ build_settings_labels .building_apple_bundle : building_apple_bundle ,
346350 build_settings_labels .use_tree_artifacts_outputs : force_bundle_outputs if force_bundle_outputs else settings [build_settings_labels .use_tree_artifacts_outputs ],
347351 "//command_line_option:apple_platform_type" : platform_type ,
348352 "//command_line_option:apple_platforms" : apple_platforms ,
@@ -411,6 +415,7 @@ def _resolved_environment_arch_for_arch(*, arch, environment, platform_type):
411415
412416def _command_line_options_for_xcframework_platform (
413417 * ,
418+ building_apple_bundle ,
414419 minimum_os_version ,
415420 platform_attr ,
416421 platform_type ,
@@ -419,6 +424,8 @@ def _command_line_options_for_xcframework_platform(
419424 """Generates a dictionary of command line options keyed by 1:2+ transition for this platform.
420425
421426 Args:
427+ building_apple_bundle: Indicates if the rule is building a bundle (rather than a
428+ standalone executable or library).
422429 minimum_os_version: A string representing the minimum OS version specified for this
423430 platform, represented as a dotted version number (for example, `"9.0"`).
424431 platform_attr: The attribute for the apple platform specifying in dictionary form which
@@ -453,6 +460,7 @@ def _command_line_options_for_xcframework_platform(
453460 environment = target_environment ,
454461 platform_type = platform_type ,
455462 ): _command_line_options (
463+ building_apple_bundle = building_apple_bundle ,
456464 environment_arch = resolved_environment_arch ,
457465 minimum_os_version = minimum_os_version ,
458466 platform_type = platform_type ,
@@ -467,7 +475,9 @@ def _apple_rule_base_transition_impl(settings, attr):
467475 """Rule transition for Apple rules using Bazel CPUs and a valid Apple split transition."""
468476 minimum_os_version = attr .minimum_os_version
469477 platform_type = attr .platform_type
478+ building_apple_bundle = getattr (attr , "_building_apple_bundle" , False )
470479 return _command_line_options (
480+ building_apple_bundle = building_apple_bundle ,
471481 environment_arch = _environment_archs (platform_type , minimum_os_version , settings )[0 ],
472482 minimum_os_version = minimum_os_version ,
473483 platform_type = platform_type ,
@@ -496,6 +506,7 @@ _apple_platform_transition_inputs = _apple_platforms_rule_base_transition_inputs
496506 "//command_line_option:platforms" ,
497507]
498508_apple_rule_base_transition_outputs = [
509+ build_settings_labels .building_apple_bundle ,
499510 build_settings_labels .use_tree_artifacts_outputs ,
500511 "//command_line_option:apple_platform_type" ,
501512 "//command_line_option:apple_platforms" ,
@@ -528,12 +539,14 @@ def _apple_platforms_rule_base_transition_impl(settings, attr):
528539 """Rule transition for Apple rules using Bazel platforms and the Starlark split transition."""
529540 minimum_os_version = attr .minimum_os_version
530541 platform_type = attr .platform_type
542+ building_apple_bundle = getattr (attr , "_building_apple_bundle" , False )
531543 environment_arch = None
532544 if not settings ["//command_line_option:incompatible_enable_apple_toolchain_resolution" ]:
533545 # Add fallback to match an anticipated split of Apple cpu-based resolution
534546 environment_arch = _environment_archs (platform_type , minimum_os_version , settings )[0 ]
535547 return _command_line_options (
536548 apple_platforms = settings ["//command_line_option:apple_platforms" ],
549+ building_apple_bundle = building_apple_bundle ,
537550 environment_arch = environment_arch ,
538551 minimum_os_version = minimum_os_version ,
539552 platform_type = platform_type ,
@@ -550,6 +563,7 @@ def _apple_platforms_rule_bundle_output_base_transition_impl(settings, attr):
550563 """Rule transition for Apple rules using Bazel platforms which force bundle outputs."""
551564 minimum_os_version = attr .minimum_os_version
552565 platform_type = attr .platform_type
566+ building_apple_bundle = getattr (attr , "_building_apple_bundle" , False )
553567 environment_arch = None
554568 if not settings ["//command_line_option:incompatible_enable_apple_toolchain_resolution" ]:
555569 # Add fallback to match an anticipated split of Apple cpu-based resolution
@@ -560,6 +574,7 @@ def _apple_platforms_rule_bundle_output_base_transition_impl(settings, attr):
560574 )
561575 return _command_line_options (
562576 apple_platforms = settings ["//command_line_option:apple_platforms" ],
577+ building_apple_bundle = building_apple_bundle ,
563578 environment_arch = environment_arch [0 ],
564579 force_bundle_outputs = True ,
565580 minimum_os_version = minimum_os_version ,
@@ -656,6 +671,7 @@ def _apple_platform_split_transition_impl(settings, attr):
656671 if str (platform ) not in output_dictionary :
657672 output_dictionary [str (platform )] = _command_line_options (
658673 apple_platforms = apple_platforms ,
674+ building_apple_bundle = getattr (attr , "_building_apple_bundle" , False ),
659675 minimum_os_version = attr .minimum_os_version ,
660676 platform_type = attr .platform_type ,
661677 settings = settings ,
@@ -664,6 +680,7 @@ def _apple_platform_split_transition_impl(settings, attr):
664680 else :
665681 minimum_os_version = attr .minimum_os_version
666682 platform_type = attr .platform_type
683+ building_apple_bundle = getattr (attr , "_building_apple_bundle" , False )
667684 for environment_arch in _environment_archs (platform_type , minimum_os_version , settings ):
668685 found_cpu = _cpu_string (
669686 environment_arch = environment_arch ,
@@ -704,6 +721,7 @@ def _apple_platform_split_transition_impl(settings, attr):
704721 continue
705722
706723 output_dictionary [found_cpu ] = _command_line_options (
724+ building_apple_bundle = building_apple_bundle ,
707725 environment_arch = environment_arch ,
708726 minimum_os_version = minimum_os_version ,
709727 platform_type = platform_type ,
@@ -772,6 +790,7 @@ def _xcframework_split_transition_impl(settings, attr):
772790 target_environments .append ("simulator" )
773791
774792 command_line_options = _command_line_options_for_xcframework_platform (
793+ building_apple_bundle = getattr (attr , "_building_apple_bundle" , False ),
775794 minimum_os_version = attr .minimum_os_versions .get (platform_type ),
776795 platform_attr = platform_attr ,
777796 platform_type = platform_type ,
0 commit comments