@@ -320,6 +320,7 @@ def _resolved_environment_arch_for_arch(*, arch, environment, platform_type):
320320
321321def _command_line_options_for_xcframework_platform (
322322 * ,
323+ attr ,
323324 minimum_os_version ,
324325 platform_attr ,
325326 platform_type ,
@@ -328,6 +329,7 @@ def _command_line_options_for_xcframework_platform(
328329 """Generates a dictionary of command line options keyed by 1:2+ transition for this platform.
329330
330331 Args:
332+ attr: The attributes passed to the transition function.
331333 minimum_os_version: A string representing the minimum OS version specified for this
332334 platform, represented as a dotted version number (for example, `"9.0"`).
333335 platform_attr: The attribute for the apple platform specifying in dictionary form which
@@ -361,7 +363,10 @@ def _command_line_options_for_xcframework_platform(
361363 environment = target_environment ,
362364 platform_type = platform_type ,
363365 ): _command_line_options (
364- emit_swiftinterface = True ,
366+ emit_swiftinterface = _should_emit_swiftinterface (
367+ attr ,
368+ is_xcframework = True ,
369+ ),
365370 environment_arch = resolved_environment_arch ,
366371 minimum_os_version = minimum_os_version ,
367372 platform_type = platform_type ,
@@ -372,11 +377,28 @@ def _command_line_options_for_xcframework_platform(
372377
373378 return output_dictionary
374379
380+ def _should_emit_swiftinterface (attr , is_xcframework = False ):
381+ """Determines if a .swiftinterface file should be generated for Swift dependencies.
382+
383+ Needed until users of the framework rules are allowed to enable
384+ library evolution on specific targets instead of having it automatically
385+ applied to the entire dependency subgraph.
386+ """
387+
388+ features = getattr (attr , "features" , [])
389+ if type (features ) == "list" and "apple.no_legacy_swiftinterface" in features :
390+ return False
391+
392+ # iOS and tvOS static frameworks require underlying swift_library targets generate a Swift
393+ # interface file. These rules define a private attribute called `_emitswiftinterface` that
394+ # let's this transition flip rules_swift config down the build graph.
395+ return is_xcframework or hasattr (attr , "_emitswiftinterface" )
396+
375397def _apple_rule_base_transition_impl (settings , attr ):
376398 """Rule transition for Apple rules using Bazel CPUs and a valid Apple split transition."""
377399 platform_type = attr .platform_type
378400 return _command_line_options (
379- emit_swiftinterface = hasattr (attr , "_emitswiftinterface" ),
401+ emit_swiftinterface = _should_emit_swiftinterface (attr ),
380402 environment_arch = _environment_archs (platform_type , settings )[0 ],
381403 minimum_os_version = attr .minimum_os_version ,
382404 platform_type = platform_type ,
@@ -447,7 +469,7 @@ def _apple_platforms_rule_base_transition_impl(settings, attr):
447469 environment_arch = _environment_archs (platform_type , settings )[0 ]
448470 return _command_line_options (
449471 apple_platforms = settings ["//command_line_option:apple_platforms" ],
450- emit_swiftinterface = hasattr (attr , "_emitswiftinterface" ),
472+ emit_swiftinterface = _should_emit_swiftinterface (attr ),
451473 environment_arch = environment_arch ,
452474 minimum_os_version = minimum_os_version ,
453475 platform_type = platform_type ,
@@ -470,7 +492,7 @@ def _apple_platforms_rule_bundle_output_base_transition_impl(settings, attr):
470492 environment_arch = _environment_archs (platform_type , settings )[0 ]
471493 return _command_line_options (
472494 apple_platforms = settings ["//command_line_option:apple_platforms" ],
473- emit_swiftinterface = hasattr (attr , "_emitswiftinterface" ),
495+ emit_swiftinterface = _should_emit_swiftinterface (attr ),
474496 environment_arch = environment_arch ,
475497 force_bundle_outputs = True ,
476498 minimum_os_version = minimum_os_version ,
@@ -550,7 +572,7 @@ def _apple_platform_split_transition_impl(settings, attr):
550572 # iOS and tvOS static frameworks require underlying swift_library targets generate a Swift
551573 # interface file. These rules define a private attribute called `_emitswiftinterface` that
552574 # let's this transition flip rules_swift config down the build graph.
553- emit_swiftinterface = hasattr (attr , "_emitswiftinterface" )
575+ emit_swiftinterface = _should_emit_swiftinterface (attr )
554576
555577 if settings ["//command_line_option:incompatible_enable_apple_toolchain_resolution" ]:
556578 platforms = (
@@ -665,6 +687,7 @@ def _xcframework_transition_impl(settings, attr):
665687 target_environments .append ("simulator" )
666688
667689 command_line_options = _command_line_options_for_xcframework_platform (
690+ attr = attr ,
668691 minimum_os_version = attr .minimum_os_versions .get (platform_type ),
669692 platform_attr = getattr (attr , platform_type ),
670693 platform_type = platform_type ,
0 commit comments