From 578af2467578e145724f274808bb8b2037724f90 Mon Sep 17 00:00:00 2001 From: Elton Gao Date: Wed, 28 Aug 2024 17:28:44 -0400 Subject: [PATCH] pass in compilation_context to build the clang module and not based on framework_files.output --- rules/framework.bzl | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/rules/framework.bzl b/rules/framework.bzl index d6b9b71d..3508dc71 100644 --- a/rules/framework.bzl +++ b/rules/framework.bzl @@ -561,7 +561,7 @@ def _create_swiftmodule(attrs): **kwargs ) -def _copy_swiftmodule(ctx, framework_files, virtualize_frameworks): +def _copy_swiftmodule(ctx, compilation_context, framework_files, virtualize_frameworks): inputs = framework_files.inputs outputs = framework_files.outputs @@ -578,39 +578,24 @@ def _copy_swiftmodule(ctx, framework_files, virtualize_frameworks): # original swift module/doc, so that swift can find it. swift_module = _create_swiftmodule(inputs) - # Setup the `clang` attr of the Swift module for non-vfs case this is required to have it locate the modulemap - # and headers correctly. - clang = None - if not virtualize_frameworks: - module_map = outputs.modulemaps[0] if outputs.modulemaps else None - clang = swift_common.create_clang_module( - module_map = module_map, - compilation_context = cc_common.create_compilation_context( - headers = depset(_compact( - outputs.headers + - outputs.private_headers + - [module_map], - )), - ), - ) - + clang_module = swift_common.create_clang_module( + compilation_context = compilation_context, + module_map = outputs.modulemaps[0] if not virtualize_frameworks and outputs.modulemaps else None, + ) return [ - # only add the swift module, the objc modulemap is already listed as a header, - # and it will be discovered via the framework search path swift_common.create_module( name = swiftmodule_name, - clang = clang, + clang = clang_module, swift = swift_module, ), ] -def _get_merged_swift_info(ctx, swift_module_context, framework_files, transitive_deps, virtualize_frameworks): +def _get_merged_swift_info(ctx, compilation_context, framework_files, transitive_deps, virtualize_frameworks): swift_info_fields = { "swift_infos": [dep[SwiftInfo] for dep in transitive_deps if SwiftInfo in dep], - "modules": [swift_module_context], } if framework_files.outputs.swiftmodule: - swift_info_fields["modules"] += _copy_swiftmodule(ctx, framework_files, virtualize_frameworks) + swift_info_fields["modules"] = _copy_swiftmodule(ctx, compilation_context, framework_files, virtualize_frameworks) return swift_common.create_swift_info(**swift_info_fields) def _merge_root_infoplists(ctx): @@ -1109,14 +1094,7 @@ def _apple_framework_packaging_impl(ctx): avoid_deps_info = AvoidDepsInfo(libraries = depset(avoid_deps).to_list(), link_dynamic = False) # rules_swift 2.x no longers takes compilation_context from CcInfo, need to pass it in via SwiftInfo - swift_module_context = swift_common.create_module( - name = ctx.attr.name, - clang = swift_common.create_clang_module( - compilation_context = compilation_context, - module_map = None, - ), - ) - swift_info = _get_merged_swift_info(ctx, swift_module_context, framework_files, transitive_deps, virtualize_frameworks) + swift_info = _get_merged_swift_info(ctx, compilation_context, framework_files, transitive_deps, virtualize_frameworks) # Build out the default info provider out_files = _compact([outputs.binary, outputs.swiftmodule, outputs.infoplist])