Skip to content

Commit

Permalink
[rules_apple] Add framework linking info to CcInfo of {ios,tvos}_fram…
Browse files Browse the repository at this point in the history
…ework

PiperOrigin-RevId: 487572609
(cherry picked from commit d8ab65d)
  • Loading branch information
googlewalt authored and keith committed Feb 23, 2023
1 parent bf31ad8 commit 4fc3570
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apple/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ bzl_library(
"//apple:providers",
"//apple/internal/utils:clang_rt_dylibs",
"@bazel_skylib//lib:collections",
"@bazel_skylib//rules:common_settings",
"@build_bazel_rules_swift//swift",
],
)
Expand Down Expand Up @@ -593,6 +594,7 @@ bzl_library(
":transition_support",
"//apple:providers",
"//apple/internal/utils:clang_rt_dylibs",
"@bazel_skylib//rules:common_settings",
"@build_bazel_rules_swift//swift",
],
)
Expand Down
11 changes: 11 additions & 0 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ load(
"IosStickerPackExtensionBundleInfo",
)
load("@bazel_skylib//lib:collections.bzl", "collections")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")

def _ios_application_impl(ctx):
"""Experimental implementation of ios_application."""
Expand Down Expand Up @@ -690,6 +691,14 @@ def _ios_framework_impl(ctx):
bundle_id = ctx.attr.bundle_id
bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx)
executable_name = bundling_support.executable_name(ctx)
cc_toolchain = find_cpp_toolchain(ctx)
cc_features = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
language = "objc",
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)
features = features_support.compute_enabled_features(
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
Expand Down Expand Up @@ -828,7 +837,9 @@ def _ios_framework_impl(ctx):
binary_artifact = binary_artifact,
bundle_name = bundle_name,
bundle_only = ctx.attr.bundle_only,
cc_features = cc_features,
cc_info = link_result.cc_info,
cc_toolchain = cc_toolchain,
objc_provider = link_result.objc,
rule_label = label,
),
Expand Down
31 changes: 30 additions & 1 deletion apple/internal/partials/framework_provider.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def _framework_provider_partial_impl(
binary_artifact,
bundle_name,
bundle_only,
cc_features,
cc_info,
cc_toolchain,
objc_provider,
rule_label):
"""Implementation for the framework provider partial."""
Expand Down Expand Up @@ -61,9 +63,30 @@ def _framework_provider_partial_impl(
providers = [objc_provider],
)

library_to_link = cc_common.create_library_to_link(
actions = actions,
cc_toolchain = cc_toolchain,
feature_configuration = cc_features,
dynamic_library = binary_artifact,
)
linker_input = cc_common.create_linker_input(
owner = rule_label,
libraries = depset([library_to_link]),
)
wrapper_cc_info = cc_common.merge_cc_infos(
cc_infos = [
CcInfo(
linking_context = cc_common.create_linking_context(
linker_inputs = depset(direct = [linker_input]),
),
),
cc_info,
],
)

framework_provider = apple_common.new_dynamic_framework_provider(
binary = binary_artifact,
cc_info = cc_info,
cc_info = wrapper_cc_info,
framework_dirs = depset([absolute_framework_dir]),
framework_files = depset([framework_file]),
objc = legacy_objc_provider,
Expand All @@ -80,7 +103,9 @@ def framework_provider_partial(
binary_artifact,
bundle_name,
bundle_only,
cc_features,
cc_info,
cc_toolchain,
objc_provider,
rule_label):
"""Constructor for the framework provider partial.
Expand All @@ -96,8 +121,10 @@ def framework_provider_partial(
binary_artifact: The linked dynamic framework binary.
bundle_name: The name of the output bundle.
bundle_only: Only include the bundle but do not link the framework
cc_features: List of enabled C++ features.
cc_info: The CcInfo provider containing information about the
targets linked into the dynamic framework.
cc_toolchain: The C++ toolchain to use.
objc_provider: The `apple_common.Objc` provider containing information
about the targets linked into the dynamic framework.
rule_label: The label of the target being analyzed.
Expand All @@ -114,7 +141,9 @@ def framework_provider_partial(
binary_artifact = binary_artifact,
bundle_name = bundle_name,
bundle_only = bundle_only,
cc_features = cc_features,
cc_info = cc_info,
cc_toolchain = cc_toolchain,
objc_provider = objc_provider,
rule_label = rule_label,
)
11 changes: 11 additions & 0 deletions apple/internal/tvos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ load(
"TvosFrameworkBundleInfo",
"TvosStaticFrameworkBundleInfo",
)
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")

def _tvos_application_impl(ctx):
"""Experimental implementation of tvos_application."""
Expand Down Expand Up @@ -393,6 +394,14 @@ def _tvos_dynamic_framework_impl(ctx):
bundle_id = ctx.attr.bundle_id
bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx)
executable_name = bundling_support.executable_name(ctx)
cc_toolchain = find_cpp_toolchain(ctx)
cc_features = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
language = "objc",
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)
features = features_support.compute_enabled_features(
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
Expand Down Expand Up @@ -750,7 +759,9 @@ def _tvos_framework_impl(ctx):
binary_artifact = binary_artifact,
bundle_name = bundle_name,
bundle_only = ctx.attr.bundle_only,
cc_features = cc_features,
cc_info = link_result.cc_info,
cc_toolchain = cc_toolchain,
objc_provider = link_result.objc,
rule_label = label,
),
Expand Down

0 comments on commit 4fc3570

Please sign in to comment.