Skip to content

Commit

Permalink
Handle ObjcProvider.module_map removal
Browse files Browse the repository at this point in the history
Handle https://github.com/bazelbuild/rules_apple/pull/1552/files or bazelbuild/rules_apple@5d7d31d by self-identifying the `modulemap` file(s) since the forwarding of them in `ObjcProvider` was removed.
  • Loading branch information
mattrobmattrob committed Jan 9, 2023
1 parent c997703 commit 4fc8630
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
24 changes: 20 additions & 4 deletions rules/apple_patched.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ load(
apple_dynamic_framework_import_original = "apple_dynamic_framework_import",
apple_static_framework_import_original = "apple_static_framework_import",
)
load(
"@build_bazel_rules_apple//apple/internal:framework_import_support.bzl",
"framework_import_support",
)
load("@build_bazel_rules_apple//apple:providers.bzl", "AppleFrameworkImportInfo")
load("@build_bazel_rules_swift//swift/internal:providers.bzl", "SwiftUsageInfo")
load("//rules/framework:vfs_overlay.bzl", "make_vfsoverlay")
Expand All @@ -30,6 +34,7 @@ def apple_dynamic_framework_import(name, **kwargs):
_apple_framework_import_modulemap(
name = name,
legacy_target = legacy_target_label,
framework_imports = kwargs.get("framework_imports", []),
visibility = visibility,
tags = tags,
)
Expand All @@ -53,6 +58,7 @@ def apple_static_framework_import(name, **kwargs):
_apple_framework_import_modulemap(
name = name,
legacy_target = legacy_target_label,
framework_imports = kwargs.get("framework_imports", []),
visibility = visibility,
tags = tags,
)
Expand All @@ -66,7 +72,7 @@ def _find_imported_framework_name(outputs):
return fw_name
return None

def _get_framework_info_providers(ctx, old_cc_info, old_objc_provider):
def _get_framework_info_providers(ctx, old_cc_info, modulemap_list):
virtualize_frameworks = feature_names.virtualize_frameworks in ctx.features
if not virtualize_frameworks:
return []
Expand All @@ -81,7 +87,6 @@ def _get_framework_info_providers(ctx, old_cc_info, old_objc_provider):
if not imported_framework_name:
return []

modulemap_list = old_objc_provider.module_map.to_list()
vfs = make_vfsoverlay(
ctx,
hdrs = hdrs_list,
Expand Down Expand Up @@ -112,15 +117,22 @@ def _apple_framework_import_modulemap_impl(ctx):
objc_provider = legacy_target[apple_common.Objc]
old_cc_info = legacy_target[CcInfo]

# Pull the `.modulemap` files out of the `framework_imports` since the
# propagation of this was removed from `ObjcProvider`.
framework_imports_by_category = framework_import_support.classify_file_imports(
ctx.var,
ctx.files.framework_imports,
)

# Merge providers
new_cc_info = cc_common.merge_cc_infos(
cc_infos = [
old_cc_info,
CcInfo(compilation_context = cc_common.create_compilation_context(headers = objc_provider.module_map)),
CcInfo(compilation_context = cc_common.create_compilation_context(headers = depset(framework_imports_by_category.module_map_imports))),
],
)

additional_providers = _get_framework_info_providers(ctx, old_cc_info, objc_provider)
additional_providers = _get_framework_info_providers(ctx, old_cc_info, framework_imports_by_category.module_map_imports)

# Seems that there is no way to iterate on the existing providers, so what is possible instead
# is to list here the keys to all of them (you can see the keys for the existing providers of a
Expand All @@ -138,6 +150,10 @@ _apple_framework_import_modulemap = rule(
mandatory = True,
doc = "The legacy target to patch",
),
"framework_imports": attr.label_list(
allow_files = True,
doc = "The list of files under a `.framework` directory for `legacy_target`.",
),
"_cc_toolchain": attr.label(
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
doc = """\
Expand Down
5 changes: 3 additions & 2 deletions tests/ios/unit-test/test-imports-app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ apple_framework_packaging(
"xcodeproj-ignore-as-target",
],
transitive_deps = [
"@TensorFlowLiteC//:TensorFlowLiteC",
"@TensorFlowLiteC//:TensorFlowLiteCCoreML",
":SomeFramework",
"@GoogleMobileAdsSDK//:GoogleMobileAds",
"@TensorFlowLiteC",
"@TensorFlowLiteC//:TensorFlowLiteCCoreML",
],
visibility = ["//visibility:public"],
deps = [
Expand Down

0 comments on commit 4fc8630

Please sign in to comment.