From 46535afcec837dcdaf216a3e94dff72e1f14c7a7 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 5 Nov 2024 05:15:25 -0800 Subject: [PATCH] No public description PiperOrigin-RevId: 693308877 --- apple/apple_binary.bzl | 9 ++++- apple/internal/BUILD | 3 ++ apple/internal/apple_framework_import.bzl | 7 +++- apple/internal/apple_xcframework_import.bzl | 8 +++- apple/internal/ios_rules.bzl | 5 ++- apple/internal/linking_support.bzl | 25 ++++++++---- apple/internal/macos_rules.bzl | 8 ++-- apple/internal/partials/BUILD | 1 + .../internal/partials/framework_provider.bzl | 6 ++- apple/internal/providers.bzl | 32 ++++++++++++++++ apple/internal/providers/BUILD | 10 +++++ .../apple_dynamic_framework_info.bzl | 38 +++++++++++++++++++ .../testing/apple_test_bundle_support.bzl | 3 +- apple/internal/tvos_rules.bzl | 3 +- apple/internal/visionos_rules.bzl | 3 +- apple/providers.bzl | 4 ++ 16 files changed, 143 insertions(+), 22 deletions(-) create mode 100644 apple/internal/providers/apple_dynamic_framework_info.bzl diff --git a/apple/apple_binary.bzl b/apple/apple_binary.bzl index 9f886a51f2..059ed3e354 100644 --- a/apple/apple_binary.bzl +++ b/apple/apple_binary.bzl @@ -18,6 +18,11 @@ load( "@build_bazel_rules_apple//apple/internal:linking_support.bzl", "linking_support", ) +load( + "@build_bazel_rules_apple//apple/internal:providers.bzl", + "AppleExecutableBinaryInfo", + "new_appleexecutablebinaryinfo", +) load( "@build_bazel_rules_apple//apple/internal:rule_attrs.bzl", "rule_attrs", @@ -118,7 +123,7 @@ Resolved Xcode is version {xcode_version}. # so that bundles can use it as their loader. if binary_type == "executable": providers.append( - apple_common.new_executable_binary_provider( + new_appleexecutablebinaryinfo( cc_info = link_result.cc_info, binary = binary_artifact, ), @@ -178,7 +183,7 @@ The target representing the executable that will be loading this bundle. Undefined symbols from the bundle are checked against this execuable during linking as if it were one of the dynamic libraries the bundle was linked with. """, - providers = [apple_common.AppleExecutableBinary], + providers = [AppleExecutableBinaryInfo], ), "data": attr.label_list(allow_files = True), "sdk_dylibs": attr.string_list( diff --git a/apple/internal/BUILD b/apple/internal/BUILD index 3f5c98c553..a1942653dd 100644 --- a/apple/internal/BUILD +++ b/apple/internal/BUILD @@ -291,6 +291,8 @@ bzl_library( ], deps = [ ":entitlements_support", + ":providers", + "//apple/internal/providers:apple_dynamic_framework_info", "@build_bazel_apple_support//lib:lipo", ], ) @@ -383,6 +385,7 @@ bzl_library( "//apple/internal/partials:swift_dylibs", "//apple/internal/partials:swift_framework", "//apple/internal/partials:watchos_stub", + "//apple/internal/providers:apple_dynamic_framework_info", ], ) diff --git a/apple/internal/apple_framework_import.bzl b/apple/internal/apple_framework_import.bzl index 8ef06c9df4..ae2f32686d 100644 --- a/apple/internal/apple_framework_import.bzl +++ b/apple/internal/apple_framework_import.bzl @@ -67,6 +67,10 @@ load( "@build_bazel_rules_apple//apple/internal/aspects:swift_usage_aspect.bzl", "SwiftUsageInfo", ) +load( + "@build_bazel_rules_apple//apple/internal/providers:apple_dynamic_framework_info.bzl", + "AppleDynamicFrameworkInfo", +) load( "@build_bazel_rules_apple//apple/internal/toolchains:apple_toolchains.bzl", "apple_toolchain_utils", @@ -200,7 +204,8 @@ There should only be one valid framework binary, given a name that matches its f # Create AppleDynamicFramework provider. framework_groups = _grouped_framework_files(framework_imports) framework_dirs_set = depset(framework_groups.keys()) - providers.append(apple_common.new_dynamic_framework_provider( + + providers.append(AppleDynamicFrameworkInfo( cc_info = cc_info, framework_dirs = framework_dirs_set, framework_files = depset(framework_imports), diff --git a/apple/internal/apple_xcframework_import.bzl b/apple/internal/apple_xcframework_import.bzl index be8b6b1c45..cb701cbd9e 100644 --- a/apple/internal/apple_xcframework_import.bzl +++ b/apple/internal/apple_xcframework_import.bzl @@ -40,6 +40,10 @@ load( "@build_bazel_rules_apple//apple/internal/aspects:swift_usage_aspect.bzl", "SwiftUsageInfo", ) +load( + "@build_bazel_rules_apple//apple/internal/providers:apple_dynamic_framework_info.bzl", + "AppleDynamicFrameworkInfo", +) load( "@build_bazel_rules_apple//apple/internal/toolchains:apple_toolchains.bzl", "apple_toolchain_utils", @@ -770,7 +774,7 @@ def _apple_dynamic_xcframework_import_impl(ctx): providers.append(cc_info) # Create AppleDynamicFrameworkInfo provider - apple_dynamic_framework_info = apple_common.new_dynamic_framework_provider( + apple_dynamic_framework_info = AppleDynamicFrameworkInfo( cc_info = cc_info, ) providers.append(apple_dynamic_framework_info) @@ -1007,7 +1011,7 @@ on this target. provides = [ AppleFrameworkImportInfo, CcInfo, - apple_common.AppleDynamicFramework, + AppleDynamicFrameworkInfo, ], toolchains = use_cpp_toolchain(), ) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 19f2808dc1..1c89c98513 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -74,6 +74,7 @@ load( "IosFrameworkBundleInfo", "IosImessageExtensionBundleInfo", "WatchosApplicationBundleInfo", + "new_appleexecutablebinaryinfo", "new_appleframeworkbundleinfo", "new_iosappclipbundleinfo", "new_iosapplicationbundleinfo", @@ -511,7 +512,7 @@ def _ios_application_impl(ctx): processor_result.output_groups, ) ), - apple_common.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -811,7 +812,7 @@ def _ios_app_clip_impl(ctx): processor_result.output_groups, ) ), - apple_common.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 16ebe97351..b935a45b3f 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -24,6 +24,15 @@ load( "get_split_target_triplet", "subtract_linking_contexts", ) +load( + "@build_bazel_rules_apple//apple/internal:providers.bzl", + "AppleExecutableBinaryInfo", + "new_appledebugoutputsinfo", +) +load( + "@build_bazel_rules_apple//apple/internal/providers:apple_dynamic_framework_info.bzl", + "AppleDynamicFrameworkInfo", +) ObjcInfo = apple_common.Objc @@ -183,14 +192,14 @@ def _link_multi_arch_binary( )) avoid_cc_infos = [ - dep[apple_common.AppleDynamicFramework].cc_info + dep[AppleDynamicFrameworkInfo].cc_info for dep in avoid_deps - if apple_common.AppleDynamicFramework in dep + if AppleDynamicFrameworkInfo in dep ] avoid_cc_infos.extend([ - dep[apple_common.AppleExecutableBinary].cc_info + dep[AppleExecutableBinaryInfo].cc_info for dep in avoid_deps - if apple_common.AppleExecutableBinary in dep + if AppleExecutableBinaryInfo in dep ]) avoid_cc_infos.extend([dep[CcInfo] for dep in avoid_deps if CcInfo in dep]) avoid_cc_linking_contexts = [dep.linking_context for dep in avoid_cc_infos] @@ -307,7 +316,7 @@ def _link_multi_arch_binary( cc_info = cc_common.merge_cc_infos(direct_cc_infos = cc_infos), output_groups = output_groups, outputs = outputs, - debug_outputs_provider = apple_common.AppleDebugOutputs(outputs_map = legacy_debug_outputs), + debug_outputs_provider = new_appledebugoutputsinfo(outputs_map = legacy_debug_outputs), ) def _debug_outputs_by_architecture(link_outputs): @@ -389,11 +398,11 @@ def _register_binary_linking_action( avoid_deps: A list of `Target`s representing dependencies of the binary but whose symbols should not be linked into it. bundle_loader: For Mach-O bundles, the `Target` whose binary will load this bundle. - This target must propagate the `apple_common.AppleExecutableBinary` provider. + This target must propagate the `AppleExecutableBinaryInfo` provider. This simplifies the process of passing the bundle loader to all the arguments that need it: the binary will automatically be added to the linker inputs, its path will be added to linkopts via `-bundle_loader`, and the `apple_common.Objc` - provider of its dependencies (obtained from the `AppleExecutableBinary` provider) + provider of its dependencies (obtained from the `AppleExecutableBinaryInfo` provider) will be passed as an additional `avoid_dep` to ensure that those dependencies are subtracted when linking the bundle's binary. entitlements: An optional `File` that provides the processed entitlements for the @@ -488,7 +497,7 @@ def _register_binary_linking_action( all_avoid_deps = list(avoid_deps) if bundle_loader: - bundle_loader_file = bundle_loader[apple_common.AppleExecutableBinary].binary + bundle_loader_file = bundle_loader[AppleExecutableBinaryInfo].binary all_avoid_deps.append(bundle_loader) linkopts.extend(["-bundle_loader", bundle_loader_file.path]) link_inputs.append(bundle_loader_file) diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 750fbb7317..4fb495ebb2 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -71,9 +71,11 @@ load( "@build_bazel_rules_apple//apple/internal:providers.bzl", "AppleBundleInfo", "AppleBundleVersionInfo", + "AppleExecutableBinaryInfo", "MacosExtensionBundleInfo", "MacosXPCServiceBundleInfo", "new_applebinaryinfo", + "new_appleexecutablebinaryinfo", "new_macosapplicationbundleinfo", "new_macosbundlebundleinfo", "new_macosextensionbundleinfo", @@ -424,7 +426,7 @@ def _macos_application_impl(ctx): processor_result.output_groups, ) ), - apple_common.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -2071,7 +2073,7 @@ def _macos_command_line_application_impl(ctx): processor_result.output_groups, ) ), - apple_common.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = output_file, cc_info = link_result.cc_info, ), @@ -2401,7 +2403,7 @@ The target representing the executable that will be loading this bundle. Undefin bundle are checked against this execuable during linking as if it were one of the dynamic libraries the bundle was linked with. """, - providers = [apple_common.AppleExecutableBinary], + providers = [AppleExecutableBinaryInfo], ), }, ], diff --git a/apple/internal/partials/BUILD b/apple/internal/partials/BUILD index 158f944083..2c74baf2df 100644 --- a/apple/internal/partials/BUILD +++ b/apple/internal/partials/BUILD @@ -219,6 +219,7 @@ bzl_library( "//apple/internal:__pkg__", ], deps = [ + "//apple/internal/providers:apple_dynamic_framework_info", "@bazel_skylib//lib:partial", "@bazel_skylib//lib:paths", ], diff --git a/apple/internal/partials/framework_provider.bzl b/apple/internal/partials/framework_provider.bzl index 16bcafd789..1bd3cc5e0e 100644 --- a/apple/internal/partials/framework_provider.bzl +++ b/apple/internal/partials/framework_provider.bzl @@ -22,6 +22,10 @@ load( "@bazel_skylib//lib:paths.bzl", "paths", ) +load( + "@build_bazel_rules_apple//apple/internal/providers:apple_dynamic_framework_info.bzl", + "AppleDynamicFrameworkInfo", +) visibility("//apple/...") @@ -77,7 +81,7 @@ def _framework_provider_partial_impl( ], ) - framework_provider = apple_common.new_dynamic_framework_provider( + framework_provider = AppleDynamicFrameworkInfo( binary = binary_artifact, cc_info = wrapper_cc_info, framework_dirs = depset([absolute_framework_dir]), diff --git a/apple/internal/providers.bzl b/apple/internal/providers.bzl index a88e0cf573..f4c7a12c9e 100644 --- a/apple/internal/providers.bzl +++ b/apple/internal/providers.bzl @@ -221,6 +221,21 @@ target if one was generated. init = make_banned_init(provider_name = "AppleCodesigningDossierInfo"), ) +AppleDebugOutputsInfo, new_appledebugoutputsinfo = provider( + """ +Holds debug outputs of an Apple binary rule. + +This provider is DEPRECATED. Preferably use `AppleDsymBundleInfo` instead. + +The only field is `output_map`, which is a dictionary of: + `{ arch: { "dsym_binary": File, "linkmap": File }` + +Where `arch` is any Apple architecture such as "arm64" or "armv7". +""", + fields = ["outputs_map"], + init = make_banned_init(provider_name = "AppleDebugOutputsInfo"), +) + AppleDsymBundleInfo, new_appledsymbundleinfo = provider( doc = "Provides information for an Apple dSYM bundle.", fields = { @@ -236,6 +251,23 @@ dependencies of the given target if any were generated. init = make_banned_init(provider_name = "AppleDsymBundleInfo"), ) +AppleExecutableBinaryInfo, new_appleexecutablebinaryinfo = provider( + doc = """ +Contains the executable binary output that was built using +`link_multi_arch_binary` with the `executable` binary type. +""", + fields = { + "binary": """\ +The executable binary artifact output by `link_multi_arch_binary`. +""", + "cc_info": """\ +A `CcInfo` which contains information about the transitive dependencies linked +into the binary. +""", + }, + init = make_banned_init(provider_name = "AppleExecutableBinaryInfo"), +) + AppleExtraOutputsInfo, new_appleextraoutputsinfo = provider( doc = """ Provides information about extra outputs that should be produced from the build. diff --git a/apple/internal/providers/BUILD b/apple/internal/providers/BUILD index 6b21babaf8..308115cd3d 100644 --- a/apple/internal/providers/BUILD +++ b/apple/internal/providers/BUILD @@ -33,6 +33,16 @@ bzl_library( ], ) +bzl_library( + name = "apple_dynamic_framework_info", + srcs = ["apple_dynamic_framework_info.bzl"], + visibility = [ + # Visibility set to subpackages since this provider is used + # by a number of rules in `internal`. + "//apple/internal:__subpackages__", + ], +) + bzl_library( name = "apple_resource_hint_info", srcs = ["apple_resource_hint_info.bzl"], diff --git a/apple/internal/providers/apple_dynamic_framework_info.bzl b/apple/internal/providers/apple_dynamic_framework_info.bzl new file mode 100644 index 0000000000..47f76ebb6d --- /dev/null +++ b/apple/internal/providers/apple_dynamic_framework_info.bzl @@ -0,0 +1,38 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""AppleDynamicFrameworkInfo provider implementation.""" + +visibility([ + "//apple/internal/...", +]) + +AppleDynamicFrameworkInfo = provider( + doc = "Contains information about an Apple dynamic framework.", + fields = { + "framework_dirs": """\ +The framework path names used as link inputs in order to link against the +dynamic framework. +""", + "framework_files": """\ +The full set of artifacts that should be included as inputs to link against the +dynamic framework. +""", + "binary": "The dylib binary artifact of the dynamic framework.", + "cc_info": """\ +A `CcInfo` which contains information about the transitive dependencies linked +into the binary. +""", + }, +) diff --git a/apple/internal/testing/apple_test_bundle_support.bzl b/apple/internal/testing/apple_test_bundle_support.bzl index bc3a64c673..fc3d6c8c51 100644 --- a/apple/internal/testing/apple_test_bundle_support.bzl +++ b/apple/internal/testing/apple_test_bundle_support.bzl @@ -57,6 +57,7 @@ load( load( "@build_bazel_rules_apple//apple/internal:providers.bzl", "AppleBundleInfo", + "AppleExecutableBinaryInfo", "AppleTestInfo", "new_appleextraoutputsinfo", "new_appletestinfo", @@ -387,7 +388,7 @@ def _apple_test_bundle_impl(*, ctx, product_type): # is never passed as the bundle loader, because the host application is loaded out-of-process.) if ( rule_descriptor.product_type == apple_product_type.unit_test_bundle and - test_host and apple_common.AppleExecutableBinary in test_host + test_host and AppleExecutableBinaryInfo in test_host ): bundle_loader = test_host else: diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index e70f0e6401..e2662b5fc4 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -70,6 +70,7 @@ load( "ApplePlatformInfo", "TvosExtensionBundleInfo", "TvosFrameworkBundleInfo", + "new_appleexecutablebinaryinfo", "new_appleframeworkbundleinfo", "new_tvosapplicationbundleinfo", "new_tvosextensionbundleinfo", @@ -440,7 +441,7 @@ def _tvos_application_impl(ctx): ) ), new_tvosapplicationbundleinfo(), - apple_common.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), diff --git a/apple/internal/visionos_rules.bzl b/apple/internal/visionos_rules.bzl index e888a97ce1..18ed173113 100644 --- a/apple/internal/visionos_rules.bzl +++ b/apple/internal/visionos_rules.bzl @@ -57,6 +57,7 @@ load( ) load( "@build_bazel_rules_apple//apple/internal:providers.bzl", + "new_appleexecutablebinaryinfo", "new_visionosapplicationbundleinfo", ) load( @@ -365,7 +366,7 @@ Resolved Xcode is version {xcode_version}. ) ), new_visionosapplicationbundleinfo(), - apple_common.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), diff --git a/apple/providers.bzl b/apple/providers.bzl index eb8ed9dd9b..a764e6b48a 100644 --- a/apple/providers.bzl +++ b/apple/providers.bzl @@ -31,7 +31,9 @@ load( _AppleBundleInfo = "AppleBundleInfo", _AppleBundleVersionInfo = "AppleBundleVersionInfo", _AppleCodesigningDossierInfo = "AppleCodesigningDossierInfo", + _AppleDebugOutputsInfo = "AppleDebugOutputsInfo", _AppleDsymBundleInfo = "AppleDsymBundleInfo", + _AppleExecutableBinaryInfo = "AppleExecutableBinaryInfo", _AppleExtraOutputsInfo = "AppleExtraOutputsInfo", _AppleFrameworkBundleInfo = "AppleFrameworkBundleInfo", _AppleFrameworkImportInfo = "AppleFrameworkImportInfo", @@ -87,7 +89,9 @@ AppleBundleInfo = _AppleBundleInfo AppleBinaryInfo = _AppleBinaryInfo AppleBundleVersionInfo = _AppleBundleVersionInfo AppleCodesigningDossierInfo = _AppleCodesigningDossierInfo +AppleDebugOutputsInfo = _AppleDebugOutputsInfo AppleDsymBundleInfo = _AppleDsymBundleInfo +AppleExecutableBinaryInfo = _AppleExecutableBinaryInfo AppleExtraOutputsInfo = _AppleExtraOutputsInfo AppleFrameworkBundleInfo = _AppleFrameworkBundleInfo AppleFrameworkImportInfo = _AppleFrameworkImportInfo