Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove apple_common.Objc provider linking #1872

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apple/apple_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def _apple_binary_impl(ctx):
providers.append(
apple_common.new_executable_binary_provider(
cc_info = link_result.cc_info,
objc = link_result.objc,
binary = binary_artifact,
),
)
Expand Down
3 changes: 0 additions & 3 deletions apple/apple_static_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ Expected Apple platform type of "{platform_type}", but that was not found in {to
link_result.output_groups,
]

if link_result.objc:
providers.append(link_result.objc)

return providers

apple_static_library = rule(
Expand Down
38 changes: 3 additions & 35 deletions apple/internal/apple_framework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,6 @@ def _apple_dynamic_framework_import_impl(ctx):
),
))

# Create apple_common.Objc provider.
transitive_objc_providers = [
dep[apple_common.Objc]
for dep in deps
if apple_common.Objc in dep
]
objc_provider = framework_import_support.objc_provider_with_dependencies(
additional_objc_providers = transitive_objc_providers,
dynamic_framework_file = [] if ctx.attr.bundle_only else framework.binary_imports,
)
providers.append(objc_provider)

# Create CcInfo provider.
cc_info = framework_import_support.cc_info_with_dependencies(
actions = actions,
Expand All @@ -269,7 +257,6 @@ def _apple_dynamic_framework_import_impl(ctx):
framework_groups = _grouped_framework_files(framework_imports)
framework_dirs_set = depset(framework_groups.keys())
providers.append(apple_common.new_dynamic_framework_provider(
objc = objc_provider,
cc_info = cc_info,
framework_dirs = framework_dirs_set,
framework_files = depset(framework_imports),
Expand Down Expand Up @@ -343,8 +330,6 @@ def _apple_static_framework_import_impl(ctx):

# Collect transitive Objc/CcInfo providers from Swift toolchain
additional_cc_infos = []
additional_objc_providers = []
additional_objc_provider_fields = {}
if framework.swift_interface_imports or framework.swift_module_imports or has_swift:
toolchain = ctx.attr._swift_toolchain[SwiftToolchainInfo]
providers.append(SwiftUsageInfo())
Expand All @@ -354,34 +339,17 @@ def _apple_static_framework_import_impl(ctx):
# rare case that a binary has a Swift framework import dependency but
# no other Swift dependencies, make sure we pick those up so that it
# links to the standard libraries correctly.
additional_objc_providers.extend(toolchain.implicit_deps_providers.objc_infos)
additional_cc_infos.extend(toolchain.implicit_deps_providers.cc_infos)

if _is_debugging(compilation_mode):
swiftmodule = _swiftmodule_for_cpu(
framework.swift_module_imports,
target_triplet.architecture,
)
# TODO: fix
if swiftmodule:
additional_objc_provider_fields.update(_ensure_swiftmodule_is_embedded(swiftmodule))

# Create apple_common.Objc provider
additional_objc_providers.extend([
dep[apple_common.Objc]
for dep in deps
if apple_common.Objc in dep
])
providers.append(
framework_import_support.objc_provider_with_dependencies(
additional_objc_provider_fields = additional_objc_provider_fields,
additional_objc_providers = additional_objc_providers,
alwayslink = alwayslink,
sdk_dylib = sdk_dylibs,
sdk_framework = sdk_frameworks,
static_framework_file = framework.binary_imports,
weak_sdk_framework = weak_sdk_frameworks,
),
)
pass
# additional_objc_provider_fields.update(_ensure_swiftmodule_is_embedded(swiftmodule))

linkopts = []
if sdk_dylibs:
Expand Down
31 changes: 0 additions & 31 deletions apple/internal/apple_xcframework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -478,17 +478,6 @@ def _apple_dynamic_xcframework_import_impl(ctx):
)
providers.append(apple_framework_import_info)

# Create Objc provider
objc_provider = framework_import_support.objc_provider_with_dependencies(
additional_objc_providers = [
dep[apple_common.Objc]
for dep in deps
if apple_common.Objc in dep
],
dynamic_framework_file = [] if ctx.attr.bundle_only else [xcframework_library.binary],
)
providers.append(objc_provider)

# Create CcInfo provider
cc_info = framework_import_support.cc_info_with_dependencies(
actions = actions,
Expand All @@ -509,7 +498,6 @@ def _apple_dynamic_xcframework_import_impl(ctx):

# Create AppleDynamicFrameworkInfo provider
apple_dynamic_framework_info = apple_common.new_dynamic_framework_provider(
objc = objc_provider,
cc_info = cc_info,
)
providers.append(apple_dynamic_framework_info)
Expand Down Expand Up @@ -588,7 +576,6 @@ def _apple_static_xcframework_import_impl(ctx):
providers.append(apple_framework_import_info)

additional_cc_infos = []
additional_objc_providers = []
if xcframework.files_by_category.swift_interface_imports or \
xcframework.files_by_category.swift_module_imports or \
has_swift:
Expand All @@ -601,23 +588,6 @@ def _apple_static_xcframework_import_impl(ctx):
# no other Swift dependencies, make sure we pick those up so that it
# links to the standard libraries correctly.
additional_cc_infos.extend(swift_toolchain.implicit_deps_providers.cc_infos)
additional_objc_providers.extend(swift_toolchain.implicit_deps_providers.objc_infos)

# Create Objc provider
additional_objc_providers.extend([
dep[apple_common.Objc]
for dep in deps
if apple_common.Objc in dep
])
objc_provider = framework_import_support.objc_provider_with_dependencies(
additional_objc_providers = additional_objc_providers,
alwayslink = alwayslink,
sdk_dylib = ctx.attr.sdk_dylibs,
sdk_framework = ctx.attr.sdk_frameworks,
weak_sdk_framework = ctx.attr.weak_sdk_frameworks,
static_framework_file = [xcframework_library.binary],
)
providers.append(objc_provider)

sdk_linkopts = []
for dylib in ctx.attr.sdk_dylibs:
Expand Down Expand Up @@ -757,7 +727,6 @@ Unnecssary and ignored, will be removed in the future.
AppleFrameworkImportInfo,
CcInfo,
apple_common.AppleDynamicFramework,
apple_common.Objc,
],
toolchains = use_cpp_toolchain(),
)
Expand Down
53 changes: 0 additions & 53 deletions apple/internal/framework_import_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -400,58 +400,6 @@ def _get_swift_module_files_with_target_triplet(target_triplet, swift_module_fil

return filtered_files

def _objc_provider_with_dependencies(
*,
additional_objc_provider_fields = {},
additional_objc_providers = [],
alwayslink = False,
library = None,
dynamic_framework_file = None,
sdk_dylib = None,
sdk_framework = None,
static_framework_file = None,
weak_sdk_framework = None):
"""Returns a new Objc provider which includes transitive Objc dependencies.

Args:
additional_objc_provider_fields: Additional fields to set for the Objc provider constructor.
additional_objc_providers: Additional Objc providers to merge with this target provider.
alwayslink: Boolean to indicate if force_load_library should be set with the static
framework file.
library: File referencing a static library.
dynamic_framework_file: File referencing a framework dynamic library.
sdk_dylib: List of Apple SDK dylibs to link. Defaults to None.
sdk_framework: List of Apple SDK frameworks to link. Defaults to None.
static_framework_file: File referencing a framework static library.
weak_sdk_framework: List of Apple SDK frameworks to weakly link. Defaults to None.
Returns:
apple_common.Objc provider
"""
objc_provider_fields = {}
objc_provider_fields["providers"] = additional_objc_providers

if library:
objc_provider_fields["library"] = depset(library)

if dynamic_framework_file:
objc_provider_fields["dynamic_framework_file"] = depset(dynamic_framework_file)

if static_framework_file:
objc_provider_fields["imported_library"] = depset(static_framework_file)

if alwayslink:
objc_provider_fields["force_load_library"] = depset(static_framework_file)

if sdk_dylib:
objc_provider_fields["sdk_dylib"] = depset(sdk_dylib)
if sdk_framework:
objc_provider_fields["sdk_framework"] = depset(sdk_framework)
if weak_sdk_framework:
objc_provider_fields["weak_sdk_framework"] = depset(weak_sdk_framework)

objc_provider_fields.update(**additional_objc_provider_fields)
return apple_common.new_objc_provider(**objc_provider_fields)

def _swift_info_from_module_interface(
*,
actions,
Expand Down Expand Up @@ -522,7 +470,6 @@ framework_import_support = struct(
classify_framework_imports = _classify_framework_imports,
framework_import_info_with_dependencies = _framework_import_info_with_dependencies,
get_swift_module_files_with_target_triplet = _get_swift_module_files_with_target_triplet,
objc_provider_with_dependencies = _objc_provider_with_dependencies,
swift_info_from_module_interface = _swift_info_from_module_interface,
swift_interop_info_with_dependencies = _swift_interop_info_with_dependencies,
)
5 changes: 0 additions & 5 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def _ios_application_impl(ctx):
apple_common.new_executable_binary_provider(
binary = binary_artifact,
cc_info = link_result.cc_info,
objc = link_result.objc,
),
# TODO(b/228856372): Remove when downstream users are migrated off this provider.
link_result.debug_outputs_provider,
Expand Down Expand Up @@ -668,7 +667,6 @@ def _ios_app_clip_impl(ctx):
apple_common.new_executable_binary_provider(
binary = binary_artifact,
cc_info = link_result.cc_info,
objc = link_result.objc,
),
# TODO(b/228856372): Remove when downstream users are migrated off this provider.
link_result.debug_outputs_provider,
Expand Down Expand Up @@ -825,7 +823,6 @@ def _ios_framework_impl(ctx):
cc_features = cc_features,
cc_info = link_result.cc_info,
cc_toolchain = cc_toolchain,
objc_provider = link_result.objc,
rule_label = label,
),
partials.resources_partial(
Expand Down Expand Up @@ -1113,7 +1110,6 @@ def _ios_extension_impl(ctx):
IosExtensionBundleInfo(),
apple_common.new_executable_binary_provider(
binary = binary_artifact,
objc = link_result.objc,
),
OutputGroupInfo(
**outputs.merge_output_groups(
Expand Down Expand Up @@ -1292,7 +1288,6 @@ def _ios_dynamic_framework_impl(ctx):
cc_features = cc_features,
cc_info = link_result.cc_info,
cc_toolchain = cc_toolchain,
objc_provider = link_result.objc,
rule_label = label,
),
partials.resources_partial(
Expand Down
22 changes: 5 additions & 17 deletions apple/internal/linking_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def _debug_outputs_by_architecture(link_outputs):
linkmaps = linkmaps,
)

def _sectcreate_objc_provider(label, segname, sectname, file):
"""Returns an objc provider that propagates a section in a linked binary.
def _sectcreate_cc_info(label, segname, sectname, file):
"""Returns a CcInfo that propagates a section in a linked binary.

This function creates a new objc provider that contains the necessary linkopts
This function creates a new CcInfo that contains the necessary linkopts
to create a new section in the binary to which the provider is propagated; it
is equivalent to the `ld` flag `-sectcreate segname sectname file`. This can
be used, for example, to embed entitlements in a simulator executable (since
Expand All @@ -73,17 +73,11 @@ def _sectcreate_objc_provider(label, segname, sectname, file):
file: The file whose contents will be used as the content of the section.

Returns:
An objc provider that propagates the section linkopts.
A CcInfo that propagates the section linkopts.
"""

# linkopts get deduped, so use a single option to pass then through as a
# set.
linkopts = ["-Wl,-sectcreate,%s,%s,%s" % (segname, sectname, file.path)]
return [
apple_common.new_objc_provider(
linkopt = depset(linkopts, order = "topological"),
link_inputs = depset([file]),
),
CcInfo(
linking_context = cc_common.create_linking_context(
linker_inputs = depset([
Expand Down Expand Up @@ -145,8 +139,6 @@ def _register_binary_linking_action(
is a new universal (fat) binary obtained by invoking `lipo`.
* `cc_info`: The CcInfo provider containing information about the targets that were
linked.
* `objc`: The `apple_common.Objc` provider containing information about the targets
that were linked.
* `outputs`: A `list` of `struct`s containing the single-architecture binaries and
debug outputs, with identifying information about the target platform, architecture,
and environment that each was built for.
Expand Down Expand Up @@ -237,7 +229,6 @@ def _register_binary_linking_action(
binary = fat_binary,
cc_info = linking_outputs.cc_info,
debug_outputs_provider = linking_outputs.debug_outputs_provider,
objc = getattr(linking_outputs, "objc", None),
outputs = linking_outputs.outputs,
output_groups = linking_outputs.output_groups,
)
Expand All @@ -255,8 +246,6 @@ def _register_static_library_linking_action(ctx):
* `library`: The final library `File` that was linked. If only one architecture was
requested, then it is a symlink to that single architecture binary. Otherwise, it
is a new universal (fat) library obtained by invoking `lipo`.
* `objc`: The `apple_common.Objc` provider containing information about the targets
that were linked.
* `outputs`: A `list` of `struct`s containing the single-architecture binaries and
debug outputs, with identifying information about the target platform, architecture,
and environment that each was built for.
Expand All @@ -277,7 +266,6 @@ def _register_static_library_linking_action(ctx):

return struct(
library = fat_library,
objc = getattr(linking_outputs, "objc", None),
outputs = linking_outputs.outputs,
output_groups = linking_outputs.output_groups,
)
Expand Down Expand Up @@ -444,5 +432,5 @@ linking_support = struct(
lipo_or_symlink_inputs = _lipo_or_symlink_inputs,
register_binary_linking_action = _register_binary_linking_action,
register_static_library_linking_action = _register_static_library_linking_action,
sectcreate_objc_provider = _sectcreate_objc_provider,
sectcreate_cc_info = _sectcreate_cc_info,
)
4 changes: 2 additions & 2 deletions apple/internal/macos_binary_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _macos_binary_infoplist_impl(ctx):
version = ctx.attr.version,
)

return linking_support.sectcreate_objc_provider(
return linking_support.sectcreate_cc_info(
rule_label,
"__TEXT",
"__info_plist",
Expand Down Expand Up @@ -181,7 +181,7 @@ def _macos_command_line_launchdplist_impl(ctx):
rule_label = rule_label,
)

return linking_support.sectcreate_objc_provider(
return linking_support.sectcreate_cc_info(
rule_label,
"__TEXT",
"__launchd_plist",
Expand Down
5 changes: 0 additions & 5 deletions apple/internal/macos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ def _macos_application_impl(ctx):
apple_common.new_executable_binary_provider(
binary = binary_artifact,
cc_info = link_result.cc_info,
objc = link_result.objc,
),
# TODO(b/228856372): Remove when downstream users are migrated off this provider.
link_result.debug_outputs_provider,
Expand Down Expand Up @@ -781,7 +780,6 @@ def _macos_extension_impl(ctx):
MacosExtensionBundleInfo(),
apple_common.new_executable_binary_provider(
binary = binary_artifact,
objc = link_result.objc,
),
OutputGroupInfo(
**outputs.merge_output_groups(
Expand Down Expand Up @@ -1700,7 +1698,6 @@ def _macos_command_line_application_impl(ctx):
apple_common.new_executable_binary_provider(
binary = output_file,
cc_info = link_result.cc_info,
objc = link_result.objc,
),
# TODO(b/228856372): Remove when downstream users are migrated off this provider.
link_result.debug_outputs_provider,
Expand Down Expand Up @@ -2043,7 +2040,6 @@ def _macos_framework_impl(ctx):
cc_features = cc_features,
cc_info = link_result.cc_info,
cc_toolchain = cc_toolchain,
objc_provider = link_result.objc,
rule_label = label,
),
partials.resources_partial(
Expand Down Expand Up @@ -2284,7 +2280,6 @@ def _macos_dynamic_framework_impl(ctx):
cc_features = cc_features,
cc_info = link_result.cc_info,
cc_toolchain = cc_toolchain,
objc_provider = link_result.objc,
rule_label = label,
),
partials.resources_partial(
Expand Down
Loading