@@ -561,7 +561,7 @@ def _create_swiftmodule(attrs):
561
561
** kwargs
562
562
)
563
563
564
- def _copy_swiftmodule (ctx , framework_files ):
564
+ def _copy_swiftmodule (ctx , framework_files , virtualize_frameworks ):
565
565
inputs = framework_files .inputs
566
566
outputs = framework_files .outputs
567
567
@@ -578,18 +578,39 @@ def _copy_swiftmodule(ctx, framework_files):
578
578
# original swift module/doc, so that swift can find it.
579
579
swift_module = _create_swiftmodule (inputs )
580
580
581
+ # Setup the `clang` attr of the Swift module for non-vfs case this is required to have it locate the modulemap
582
+ # and headers correctly.
583
+ clang = None
584
+ if not virtualize_frameworks :
585
+ module_map = outputs .modulemaps [0 ] if outputs .modulemaps else None
586
+ clang = swift_common .create_clang_module (
587
+ module_map = module_map ,
588
+ compilation_context = cc_common .create_compilation_context (
589
+ headers = depset (_compact (
590
+ outputs .headers +
591
+ outputs .private_headers +
592
+ [module_map ],
593
+ )),
594
+ ),
595
+ )
596
+
581
597
return [
582
598
# only add the swift module, the objc modulemap is already listed as a header,
583
599
# and it will be discovered via the framework search path
584
- swift_common .create_module (name = swiftmodule_name , swift = swift_module ),
600
+ swift_common .create_module (
601
+ name = swiftmodule_name ,
602
+ clang = clang ,
603
+ swift = swift_module ,
604
+ ),
585
605
]
586
606
587
- def _get_merged_swift_info (ctx , framework_files , transitive_deps ):
607
+ def _get_merged_swift_info (ctx , swift_module_context , framework_files , transitive_deps , virtualize_frameworks ):
588
608
swift_info_fields = {
589
609
"swift_infos" : [dep [SwiftInfo ] for dep in transitive_deps if SwiftInfo in dep ],
610
+ "modules" : [swift_module_context ],
590
611
}
591
612
if framework_files .outputs .swiftmodule :
592
- swift_info_fields ["modules" ] = _copy_swiftmodule (ctx , framework_files )
613
+ swift_info_fields ["modules" ] + = _copy_swiftmodule (ctx , framework_files , virtualize_frameworks )
593
614
return swift_common .create_swift_info (** swift_info_fields )
594
615
595
616
def _merge_root_infoplists (ctx ):
@@ -1051,11 +1072,13 @@ def _apple_framework_packaging_impl(ctx):
1051
1072
# If not virtualizing the framework - then it runs a "clean"
1052
1073
_get_symlinked_framework_clean_action (ctx , framework_files , compilation_context_fields )
1053
1074
1075
+ compilation_context = cc_common .create_compilation_context (
1076
+ ** compilation_context_fields
1077
+ )
1078
+
1054
1079
# Construct the `CcInfo` provider, the linking context here used instead of ObjcProvider in Bazel 7+.
1055
1080
cc_info_provider = CcInfo (
1056
- compilation_context = cc_common .create_compilation_context (
1057
- ** compilation_context_fields
1058
- ),
1081
+ compilation_context = compilation_context ,
1059
1082
linking_context = cc_common .create_linking_context (
1060
1083
linker_inputs = _get_cc_info_linker_inputs (deps = deps ) if is_bazel_7 else depset ([]),
1061
1084
),
@@ -1084,7 +1107,16 @@ def _apple_framework_packaging_impl(ctx):
1084
1107
else :
1085
1108
bundle_outs = _bundle_static_framework (ctx , is_extension_safe = is_extension_safe , current_apple_platform = current_apple_platform , outputs = outputs )
1086
1109
avoid_deps_info = AvoidDepsInfo (libraries = depset (avoid_deps ).to_list (), link_dynamic = False )
1087
- swift_info = _get_merged_swift_info (ctx , framework_files , transitive_deps )
1110
+
1111
+ # rules_swift 2.x no longers takes compilation_context from CcInfo, need to pass it in via SwiftInfo
1112
+ swift_module_context = swift_common .create_module (
1113
+ name = ctx .attr .name ,
1114
+ clang = swift_common .create_clang_module (
1115
+ compilation_context = compilation_context ,
1116
+ module_map = None ,
1117
+ ),
1118
+ )
1119
+ swift_info = _get_merged_swift_info (ctx , swift_module_context , framework_files , transitive_deps , virtualize_frameworks )
1088
1120
1089
1121
# Build out the default info provider
1090
1122
out_files = _compact ([outputs .binary , outputs .swiftmodule , outputs .infoplist ])
0 commit comments