From d97dad9a838a100befabc21a2c6bdc8f8e7b202b Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 28 Oct 2024 04:41:35 -0700 Subject: [PATCH 01/23] Move apple specific linking logic from bazel Cherry picked from 2f3f608b8a8e59e9f06d030012649c1959c8cfc6 --- apple/internal/BUILD | 5 +- apple/internal/linking_support.bzl | 296 ++++++++++++++++++- apple/internal/multi_arch_binary_support.bzl | 104 +++++++ 3 files changed, 398 insertions(+), 7 deletions(-) create mode 100644 apple/internal/multi_arch_binary_support.bzl diff --git a/apple/internal/BUILD b/apple/internal/BUILD index f676fa27fc..0b1787636f 100644 --- a/apple/internal/BUILD +++ b/apple/internal/BUILD @@ -330,7 +330,10 @@ bzl_library( bzl_library( name = "linking_support", - srcs = ["linking_support.bzl"], + srcs = [ + "linking_support.bzl", + "multi_arch_binary_support.bzl", + ], visibility = [ "//apple:__subpackages__", ], diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 7e15ec15ec..8732cb30c8 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -23,6 +23,291 @@ load( "//apple/internal:entitlements_support.bzl", "entitlements_support", ) +load( + "@build_bazel_rules_apple//apple/internal:multi_arch_binary_support.bzl", + "get_split_target_triplet", + "subtract_linking_contexts", +) + +ObjcInfo = apple_common.Objc + +def _link_multi_arch_static_library(ctx): + """Links a (potentially multi-architecture) static library targeting Apple platforms. + + Rule context is a required parameter due to usage of the cc_common.configure_features API. + + Args: + ctx: The Starlark rule context. + + Returns: + A Starlark struct containing the following attributes: + - output_groups: OutputGroupInfo provider from transitive CcInfo validation_artifacts. + - outputs: List of structs containing the following attributes: + - library: Artifact representing a linked static library. + - architecture: Linked static library architecture (e.g. 'arm64', 'x86_64'). + - platform: Linked static library target Apple platform (e.g. 'ios', 'macos'). + - environment: Linked static library environment (e.g. 'device', 'simulator'). + """ + + split_target_triplets = get_split_target_triplet(ctx) + + split_deps = ctx.split_attr.deps + split_avoid_deps = ctx.split_attr.avoid_deps + child_configs_and_toolchains = ctx.split_attr._child_configuration_dummy + + outputs = [] + + for split_transition_key, child_toolchain in child_configs_and_toolchains.items(): + cc_toolchain = child_toolchain[cc_common.CcToolchainInfo] + common_variables = apple_common.compilation_support.build_common_variables( + ctx = ctx, + toolchain = cc_toolchain, + use_pch = True, + deps = split_deps[split_transition_key], + ) + + avoid_objc_providers = [] + avoid_cc_providers = [] + avoid_cc_linking_contexts = [] + + if len(split_avoid_deps.keys()): + for dep in split_avoid_deps[split_transition_key]: + if ObjcInfo in dep: + avoid_objc_providers.append(dep[ObjcInfo]) + if CcInfo in dep: + avoid_cc_providers.append(dep[CcInfo]) + avoid_cc_linking_contexts.append(dep[CcInfo].linking_context) + + name = ctx.label.name + "-" + cc_toolchain.target_gnu_system_name + "-fl" + + cc_linking_context = subtract_linking_contexts( + owner = ctx.label, + linking_contexts = common_variables.objc_linking_context.cc_linking_contexts, + avoid_dep_linking_contexts = avoid_cc_linking_contexts, + ) + linking_outputs = apple_common.compilation_support.register_fully_link_action( + name = name, + common_variables = common_variables, + cc_linking_context = cc_linking_context, + ) + + output = { + "library": linking_outputs.library_to_link.static_library, + } + + if split_target_triplets != None: + target_triplet = split_target_triplets.get(split_transition_key) + output["platform"] = target_triplet.platform + output["architecture"] = target_triplet.architecture + output["environment"] = target_triplet.environment + + outputs.append(struct(**output)) + + header_tokens = [] + for _, deps in split_deps.items(): + for dep in deps: + if CcInfo in dep: + header_tokens.append(dep[CcInfo].compilation_context.validation_artifacts) + + output_groups = {"_validation": depset(transitive = header_tokens)} + + return struct( + outputs = outputs, + output_groups = OutputGroupInfo(**output_groups), + ) + +def _link_multi_arch_binary( + *, + ctx, + avoid_deps = [], + extra_linkopts = [], + extra_link_inputs = [], + extra_requested_features = [], + extra_disabled_features = [], + stamp = -1, + variables_extension = {}): + """Links a (potentially multi-architecture) binary targeting Apple platforms. + + This method comprises a bulk of the logic of the Starlark `apple_binary` + rule in the rules_apple domain and exists to aid in the migration of its + linking logic to Starlark in rules_apple. + + This API is **highly experimental** and subject to change at any time. Do + not depend on the stability of this function at this time. + + Args: + ctx: The Starlark rule context. + avoid_deps: A list of `Target`s representing dependencies of the binary but + whose libraries should not be linked into the binary. This is the case for + dependencies that will be found at runtime in another image, such as the + bundle loader or any dynamic libraries/frameworks that will be loaded by + this binary. + extra_linkopts: A list of strings: Extra linkopts to add to the linking action. + extra_link_inputs: A list of strings: Extra files to pass to the linker action. + extra_requested_features: A list of strings: Extra requested features to be passed + to the linker action. + extra_disabled_features: A list of strings: Extra disabled features to be passed + to the linker action. + stamp: Whether to include build information in the linked binary. If 1, build + information is always included. If 0, build information is always excluded. + If -1 (the default), then the behavior is determined by the --[no]stamp + flag. This should be set to 0 when generating the executable output for + test rules. + variables_extension: A dictionary of user-defined variables to be added to the + toolchain configuration when create link command line. + + Returns: + A `struct` which contains the following fields: + * `cc_info`: The CcInfo 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. + * `output_groups`: A `dict` with the single key `_validation` and as valuea depset + containing the validation artifacts from the compilation contexts of the CcInfo + providers of the targets that were linked. + * `debug_outputs_provider`: An AppleDebugOutputs provider + """ + + split_target_triplets = get_split_target_triplet(ctx) + split_build_configs = apple_common.get_split_build_configs(ctx) + split_deps = ctx.split_attr.deps + child_configs_and_toolchains = ctx.split_attr._child_configuration_dummy + + if split_deps and split_deps.keys() != child_configs_and_toolchains.keys(): + fail(("Split transition keys are different between 'deps' [%s] and " + + "'_child_configuration_dummy' [%s]") % ( + split_deps.keys(), + child_configs_and_toolchains.keys(), + )) + + avoid_cc_infos = [ + dep[apple_common.AppleDynamicFramework].cc_info + for dep in avoid_deps + if apple_common.AppleDynamicFramework in dep + ] + avoid_cc_infos.extend([ + dep[apple_common.AppleExecutableBinary].cc_info + for dep in avoid_deps + if apple_common.AppleExecutableBinary 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] + + outputs = [] + cc_infos = [] + legacy_debug_outputs = {} + + cc_infos.extend(avoid_cc_infos) + + # $(location...) is only used in one test, and tokenize only affects linkopts in one target + additional_linker_inputs = getattr(ctx.attr, "additional_linker_inputs", []) + attr_linkopts = [ + ctx.expand_location(opt, targets = additional_linker_inputs) + for opt in getattr(ctx.attr, "linkopts", []) + ] + attr_linkopts = [token for opt in attr_linkopts for token in ctx.tokenize(opt)] + + for split_transition_key, child_toolchain in child_configs_and_toolchains.items(): + cc_toolchain = child_toolchain[cc_common.CcToolchainInfo] + deps = split_deps.get(split_transition_key, []) + target_triplet = split_target_triplets.get(split_transition_key) + + common_variables = apple_common.compilation_support.build_common_variables( + ctx = ctx, + toolchain = cc_toolchain, + deps = deps, + extra_disabled_features = extra_disabled_features, + extra_enabled_features = extra_requested_features, + attr_linkopts = attr_linkopts, + ) + + cc_infos.append(CcInfo( + compilation_context = cc_common.merge_compilation_contexts( + compilation_contexts = + common_variables.objc_compilation_context.cc_compilation_contexts, + ), + linking_context = cc_common.merge_linking_contexts( + linking_contexts = common_variables.objc_linking_context.cc_linking_contexts, + ), + )) + + cc_linking_context = subtract_linking_contexts( + owner = ctx.label, + linking_contexts = common_variables.objc_linking_context.cc_linking_contexts + + avoid_cc_linking_contexts, + avoid_dep_linking_contexts = avoid_cc_linking_contexts, + ) + + child_config = split_build_configs.get(split_transition_key) + + additional_outputs = [] + extensions = {} + + dsym_binary = None + if ctx.fragments.cpp.apple_generate_dsym: + if ctx.fragments.cpp.objc_should_strip_binary: + suffix = "_bin_unstripped.dwarf" + else: + suffix = "_bin.dwarf" + dsym_binary = ctx.actions.declare_shareable_artifact( + ctx.label.package + "/" + ctx.label.name + suffix, + child_config.bin_dir, + ) + extensions["dsym_path"] = dsym_binary.path # dsym symbol file + additional_outputs.append(dsym_binary) + legacy_debug_outputs.setdefault(target_triplet.architecture, {})["dsym_binary"] = dsym_binary + + linkmap = None + if ctx.fragments.cpp.objc_generate_linkmap: + linkmap = ctx.actions.declare_shareable_artifact( + ctx.label.package + "/" + ctx.label.name + ".linkmap", + child_config.bin_dir, + ) + extensions["linkmap_exec_path"] = linkmap.path # linkmap file + additional_outputs.append(linkmap) + legacy_debug_outputs.setdefault(target_triplet.architecture, {})["linkmap"] = linkmap + + name = ctx.label.name + "_bin" + executable = apple_common.compilation_support.register_configuration_specific_link_actions( + name = name, + common_variables = common_variables, + cc_linking_context = cc_linking_context, + build_config = child_config, + extra_link_args = extra_linkopts, + stamp = stamp, + user_variable_extensions = variables_extension | extensions, + additional_outputs = additional_outputs, + deps = deps, + extra_link_inputs = extra_link_inputs, + attr_linkopts = attr_linkopts, + ) + + output = { + "binary": executable, + "platform": target_triplet.platform, + "architecture": target_triplet.architecture, + "environment": target_triplet.environment, + "dsym_binary": dsym_binary, + "linkmap": linkmap, + } + + outputs.append(struct(**output)) + + header_tokens = [] + for _, deps in split_deps.items(): + for dep in deps: + if CcInfo in dep: + header_tokens.append(dep[CcInfo].compilation_context.validation_artifacts) + + output_groups = {"_validation": depset(transitive = header_tokens)} + + return struct( + 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), + ) def _debug_outputs_by_architecture(link_outputs): """Returns debug outputs indexed by architecture from `register_binary_linking_action` output. @@ -152,8 +437,7 @@ def _register_binary_linking_action( for test rules. Returns: - A `struct` which contains the following fields, which are a superset of the fields - returned by `apple_common.link_multi_arch_binary`: + A `struct` which contains the following fields: * `binary`: The final binary `File` that was linked. If only one architecture was requested, then it is a symlink to that single architecture binary. Otherwise, it @@ -167,6 +451,7 @@ def _register_binary_linking_action( and environment that each was built for. * `output_groups`: A `dict` containing output groups that should be returned in the `OutputGroupInfo` provider of the calling rule. + * `debug_outputs_provider`: An AppleDebugOutputs provider """ linkopts = [] link_inputs = [] @@ -224,7 +509,7 @@ def _register_binary_linking_action( linkopts.extend(["-bundle_loader", bundle_loader_file.path]) link_inputs.append(bundle_loader_file) - linking_outputs = apple_common.link_multi_arch_binary( + linking_outputs = _link_multi_arch_binary( ctx = ctx, avoid_deps = all_avoid_deps, extra_linkopts = linkopts, @@ -262,8 +547,7 @@ def _register_static_library_linking_action(ctx): ctx: The rule context. Returns: - A `struct` which contains the following fields, which are a superset of the fields - returned by `apple_common.link_multi_arch_static_library`: + A `struct` which contains the following fields: * `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 @@ -276,7 +560,7 @@ def _register_static_library_linking_action(ctx): * `output_groups`: A `dict` containing output groups that should be returned in the `OutputGroupInfo` provider of the calling rule. """ - linking_outputs = apple_common.link_multi_arch_static_library(ctx = ctx) + linking_outputs = _link_multi_arch_static_library(ctx = ctx) fat_library = ctx.actions.declare_file("{}_lipo.a".format(ctx.label.name)) diff --git a/apple/internal/multi_arch_binary_support.bzl b/apple/internal/multi_arch_binary_support.bzl new file mode 100644 index 0000000000..6bd62971a3 --- /dev/null +++ b/apple/internal/multi_arch_binary_support.bzl @@ -0,0 +1,104 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License(**kwargs): 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(**kwargs): software +# distributed under the License is distributed on an "AS IS" BASIS(**kwargs): +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND(**kwargs): either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Support utility for creating multi-arch Apple binaries.""" + +visibility([ + "//apple/...", +]) + +TargetTripletInfo = provider( + "Contains the target triplet (architecture, platform, environment) for a given configuration.", + fields = { + "architecture": "string, the CPU as returned by AppleConfiguration.getSingleArchitecture()", + "platform": "apple_platform.PLATFORM_TYPE string as returned by apple_platform.get_target_platform()", + "environment": "string ('device', 'simulator' or 'macabi) as returned by apple_platform.get_target_environment", + }, +) + +def _build_avoid_library_set(avoid_dep_linking_contexts): + avoid_library_set = dict() + for linking_context in avoid_dep_linking_contexts: + for linker_input in linking_context.linker_inputs.to_list(): + for library_to_link in linker_input.libraries: + library_artifact = apple_common.compilation_support.get_static_library_for_linking(library_to_link) + if library_artifact: + avoid_library_set[library_artifact.short_path] = True + return avoid_library_set + +def subtract_linking_contexts(owner, linking_contexts, avoid_dep_linking_contexts): + """Subtracts the libraries in avoid_dep_linking_contexts from linking_contexts. + + Args: + owner: The label of the target currently being analyzed. + linking_contexts: An iterable of CcLinkingContext objects. + avoid_dep_linking_contexts: An iterable of CcLinkingContext objects. + + Returns: + A CcLinkingContext object. + """ + libraries = [] + user_link_flags = [] + additional_inputs = [] + linkstamps = [] + avoid_library_set = _build_avoid_library_set(avoid_dep_linking_contexts) + for linking_context in linking_contexts: + for linker_input in linking_context.linker_inputs.to_list(): + for library_to_link in linker_input.libraries: + library_artifact = apple_common.compilation_support.get_library_for_linking(library_to_link) + if library_artifact.short_path not in avoid_library_set: + libraries.append(library_to_link) + user_link_flags.extend(linker_input.user_link_flags) + additional_inputs.extend(linker_input.additional_inputs) + linkstamps.extend(linker_input.linkstamps) + linker_input = cc_common.create_linker_input( + owner = owner, + libraries = depset(libraries, order = "topological"), + user_link_flags = user_link_flags, + additional_inputs = depset(additional_inputs), + linkstamps = depset(linkstamps), + ) + return cc_common.create_linking_context( + linker_inputs = depset([linker_input]), + owner = owner, + ) + +def _get_target_triplet(config): + """Returns the target triplet (architecture, platform, environment) for a given configuration.""" + cpu_platform = apple_common.apple_platform.for_target_cpu(apple_common.get_cpu(config)) + apple_config = apple_common.get_apple_config(config) + + return TargetTripletInfo( + architecture = apple_config.single_arch_cpu, + platform = apple_common.apple_platform.get_target_platform(cpu_platform), + environment = apple_common.apple_platform.get_target_environment(cpu_platform), + ) + +def get_split_target_triplet(ctx): + """Transforms a rule context's ctads to a Starlark Dict mapping transitions to target triplets. + + Args: + ctx: The Starlark rule context. + + Returns: + A Starlark Dict keyed by split transition keys with + their target triplet (architecture, platform, environment) as value. + """ + result = dict() + ctads = apple_common.get_split_prerequisites(ctx) + for split_transition_key, config in ctads.items(): + if split_transition_key == None: + fail("unexpected empty key in split transition") + result[split_transition_key] = _get_target_triplet(config) + return result From 94e2fd23b13f29cef0b02bc45d95f900cdbf116f Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:38:45 +0000 Subject: [PATCH 02/23] compat --- apple/internal/linking_support.bzl | 4 +++- apple/internal/partials/app_intents_metadata_bundle.bzl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 8732cb30c8..42bc8c9be8 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -603,7 +603,8 @@ def _lipo_or_symlink_inputs(*, actions, inputs, output, apple_fragment, xcode_co # Symlink if there was only a single architecture created; it's faster. actions.symlink(target_file = inputs[0], output = output) -def _link_multi_arch_binary( +# TODO: Delete when we take https://github.com/bazelbuild/rules_apple/commit/29eb94cbc9b1a898582e1e238cc2551ddbeaa58b +def _legacy_link_multi_arch_binary( *, actions, additional_inputs = [], @@ -734,6 +735,7 @@ def _link_multi_arch_binary( linking_support = struct( debug_outputs_by_architecture = _debug_outputs_by_architecture, + legacy_link_multi_arch_binary = _legacy_link_multi_arch_binary, link_multi_arch_binary = _link_multi_arch_binary, lipo_or_symlink_inputs = _lipo_or_symlink_inputs, new_executable_binary_provider = _new_executable_binary_provider, diff --git a/apple/internal/partials/app_intents_metadata_bundle.bzl b/apple/internal/partials/app_intents_metadata_bundle.bzl index 351ae0c70e..c665a68fd8 100644 --- a/apple/internal/partials/app_intents_metadata_bundle.bzl +++ b/apple/internal/partials/app_intents_metadata_bundle.bzl @@ -49,7 +49,7 @@ def _app_intents_metadata_bundle_partial_impl( # # TODO(b/295227222): Avoid this linker step for Xcode 15.0+ when rules_swift supports the new # swiftconstvalues-based manner of handling App Intents metadata. - link_result = linking_support.link_multi_arch_binary( + link_result = linking_support.legacy_link_multi_arch_binary( actions = actions, cc_toolchains = cc_toolchains, ctx = ctx, From 9242a8168f356c20a8f0f1a50101c975683d6d75 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:42:24 +0000 Subject: [PATCH 03/23] 6.x and 7.x compact --- apple/internal/linking_support.bzl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 42bc8c9be8..79bd215f60 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -49,6 +49,11 @@ def _link_multi_arch_static_library(ctx): - environment: Linked static library environment (e.g. 'device', 'simulator'). """ + # TODO: Delete when we drop bazel 7.x + legacy_linking_function = getattr(apple_common, "link_multi_arch_static_library", None) + if legacy_linking_function: + return legacy_linking_function(ctx = ctx) + split_target_triplets = get_split_target_triplet(ctx) split_deps = ctx.split_attr.deps From 6dd490a705ae2eb4a07cf93a12ad86f2190b0257 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:44:30 +0000 Subject: [PATCH 04/23] last green for real --- .bazelci/presubmit.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index b110abcc43..fb9be0e3bc 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -25,10 +25,7 @@ tasks: macos_last_green: name: "Last Green Bazel" - # FIXME: Use last_green once we cherry-pick in changes needed by - # https://github.com/bazelbuild/bazel/commit/b59004dd17366b09b0758b833f98294fd0e89345 - # bazel: last_green - bazel: 21a12c72d84e9108142421d9a8526edf8dceb78c + bazel: last_green <<: *common doc_tests: From 4c668eaf5366077cafa81a204a9b9543b2f8d3fd Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:47:27 +0000 Subject: [PATCH 05/23] another compat --- apple/internal/linking_support.bzl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 79bd215f60..114122b9cf 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -174,6 +174,17 @@ def _link_multi_arch_binary( * `debug_outputs_provider`: An AppleDebugOutputs provider """ + # TODO: Delete when we drop bazel 7.x + legacy_linking_function = getattr(apple_common, "link_multi_arch_binary", None) + if legacy_linking_function: + return legacy_linking_function( + ctx = ctx, + avoid_deps = all_avoid_deps, + extra_linkopts = linkopts, + extra_link_inputs = link_inputs, + stamp = stamp, + ) + split_target_triplets = get_split_target_triplet(ctx) split_build_configs = apple_common.get_split_build_configs(ctx) split_deps = ctx.split_attr.deps From 7652c8f5bf0ce27c4025734579fcd03b007fffca Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:48:14 +0000 Subject: [PATCH 06/23] closer --- .bazelci/presubmit.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index fb9be0e3bc..46a128a1a2 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -25,7 +25,8 @@ tasks: macos_last_green: name: "Last Green Bazel" - bazel: last_green + # FIXME: Use last_green once we cherry-pick https://github.com/bazelbuild/rules_apple/commit/46535afcec837dcdaf216a3e94dff72e1f14c7a7 + bazel: b59004dd17366b09b0758b833f98294fd0e89345 <<: *common doc_tests: From 30eeb3cc8a759a13dd83536f90cdd5eb2f7efe5d Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:49:06 +0000 Subject: [PATCH 07/23] copy pasta: --- apple/internal/linking_support.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 114122b9cf..15845117e8 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -179,9 +179,9 @@ def _link_multi_arch_binary( if legacy_linking_function: return legacy_linking_function( ctx = ctx, - avoid_deps = all_avoid_deps, - extra_linkopts = linkopts, - extra_link_inputs = link_inputs, + avoid_deps = avoid_deps, + extra_linkopts = extra_linkopts, + extra_link_inputs = extra_link_inputs, stamp = stamp, ) From 1884cca1b9b2461e809005c8071c6175a0331dc1 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:51:19 +0000 Subject: [PATCH 08/23] new provider --- apple/internal/linking_support.bzl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 15845117e8..7f8c171aa1 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -28,6 +28,10 @@ load( "get_split_target_triplet", "subtract_linking_contexts", ) +load( + "@build_bazel_rules_apple//apple/internal/providers:apple_dynamic_framework_info.bzl", + "AppleDynamicFrameworkInfo", +) ObjcInfo = apple_common.Objc @@ -198,9 +202,9 @@ 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 From 6979d17f394db9a9dc684a7364f3b0e994a0a7bd Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 20:30:27 +0000 Subject: [PATCH 09/23] Providers changes cherry picked from 46535afcec837dcdaf216a3e94dff72e1f14c7a7 --- apple/apple_binary.bzl | 6 ++++-- apple/internal/apple_framework_import.bzl | 2 +- apple/internal/apple_xcframework_import.bzl | 4 ++-- apple/internal/framework_import_support.bzl | 15 --------------- apple/internal/ios_rules.bzl | 7 ++++--- apple/internal/linking_support.bzl | 17 ++--------------- apple/internal/macos_rules.bzl | 8 ++++---- apple/internal/partials/framework_provider.bzl | 2 +- .../testing/apple_test_bundle_support.bzl | 2 +- apple/internal/tvos_rules.bzl | 4 ++-- apple/internal/visionos_rules.bzl | 4 ++-- 11 files changed, 23 insertions(+), 48 deletions(-) diff --git a/apple/apple_binary.bzl b/apple/apple_binary.bzl index 910fe3ebc2..656e558910 100644 --- a/apple/apple_binary.bzl +++ b/apple/apple_binary.bzl @@ -20,6 +20,8 @@ load( ) load( "//apple/internal:rule_attrs.bzl", + "AppleExecutableBinaryInfo", + "new_appleexecutablebinaryinfo", "rule_attrs", ) load( @@ -116,7 +118,7 @@ Resolved Xcode is version {xcode_version}. # so that bundles can use it as their loader. if binary_type == "executable": providers.append( - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -170,7 +172,7 @@ The target representing the executable that will be loading this bundle. Undefined symbols from the bundle are checked against this executable 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/apple_framework_import.bzl b/apple/internal/apple_framework_import.bzl index c893f6e2b0..35636e20ee 100644 --- a/apple/internal/apple_framework_import.bzl +++ b/apple/internal/apple_framework_import.bzl @@ -281,7 +281,7 @@ def _apple_dynamic_framework_import_impl(ctx): # Create AppleDynamicFramework provider. framework_groups = _grouped_framework_files(framework_imports) framework_dirs_set = depset(framework_groups.keys()) - providers.append(framework_import_support.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 150761c315..0acf12e02c 100644 --- a/apple/internal/apple_xcframework_import.bzl +++ b/apple/internal/apple_xcframework_import.bzl @@ -513,7 +513,7 @@ def _apple_dynamic_xcframework_import_impl(ctx): providers.append(cc_info) # Create AppleDynamicFrameworkInfo provider - apple_dynamic_framework_info = framework_import_support.new_dynamic_framework_provider( + apple_dynamic_framework_info = AppleDynamicFrameworkInfo( cc_info = cc_info, ) providers.append(apple_dynamic_framework_info) @@ -751,7 +751,7 @@ Unnecssary and ignored, will be removed in the future. provides = [ AppleFrameworkImportInfo, CcInfo, - apple_common.AppleDynamicFramework, + AppleDynamicFrameworkInfo, ], toolchains = use_cpp_toolchain(), ) diff --git a/apple/internal/framework_import_support.bzl b/apple/internal/framework_import_support.bzl index 5570ebebe5..593bfedd7c 100644 --- a/apple/internal/framework_import_support.bzl +++ b/apple/internal/framework_import_support.bzl @@ -411,20 +411,6 @@ def _has_versioned_framework_files(framework_files): return True return False -def _new_dynamic_framework_provider(**kwargs): - """A wrapper API for the Bazel API of the same name to better support multiple Bazel versions - - Args: - **kwargs: Arguments to pass if supported. - """ - - # TODO: Remove once we drop bazel 7.x - _OBJC_PROVIDER_LINKING = hasattr(apple_common.new_objc_provider(), "linkopt") - if not _OBJC_PROVIDER_LINKING: - kwargs.pop("objc", None) - - return apple_common.new_dynamic_framework_provider(**kwargs) - def _swift_info_from_module_interface( *, actions, @@ -497,7 +483,6 @@ framework_import_support = struct( framework_import_info_with_dependencies = _framework_import_info_with_dependencies, get_swift_module_files_with_target_triplet = _get_swift_module_files_with_target_triplet, has_versioned_framework_files = _has_versioned_framework_files, - new_dynamic_framework_provider = _new_dynamic_framework_provider, swift_info_from_module_interface = _swift_info_from_module_interface, swift_interop_info_with_dependencies = _swift_interop_info_with_dependencies, ) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index cc7553391d..ed75fae90a 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -84,6 +84,7 @@ load( ) load( "//apple/internal:providers.bzl", + "new_appleexecutablebinaryinfo", "new_appleframeworkbundleinfo", "new_iosappclipbundleinfo", "new_iosapplicationbundleinfo", @@ -523,7 +524,7 @@ def _ios_application_impl(ctx): processor_result.output_groups, ) ), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -837,7 +838,7 @@ def _ios_app_clip_impl(ctx): processor_result.output_groups, ) ), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -1398,7 +1399,7 @@ def _ios_extension_impl(ctx): DefaultInfo( files = processor_result.output_files, ), - linking_support.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 7f8c171aa1..26a0e06d5b 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -356,18 +356,6 @@ def _debug_outputs_by_architecture(link_outputs): linkmaps = linkmaps, ) -def _new_executable_binary_provider(*, binary, cc_info): - """Wrap the apple_common API of the same name to better support multiple Bazel versions. - - Args: - binary: The `File` representing the binary. - cc_info: The `CcInfo` provider for the binary. - """ - return apple_common.new_executable_binary_provider( - binary = binary, - cc_info = cc_info, - ) - def _sectcreate_objc_provider(label, segname, sectname, file): """Returns an objc provider that propagates a section in a linked binary. @@ -428,7 +416,7 @@ 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` @@ -524,7 +512,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) @@ -758,7 +746,6 @@ linking_support = struct( legacy_link_multi_arch_binary = _legacy_link_multi_arch_binary, link_multi_arch_binary = _link_multi_arch_binary, lipo_or_symlink_inputs = _lipo_or_symlink_inputs, - new_executable_binary_provider = _new_executable_binary_provider, register_binary_linking_action = _register_binary_linking_action, register_static_library_linking_action = _register_static_library_linking_action, sectcreate_objc_provider = _sectcreate_objc_provider, diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index ba1858e042..4035f066e6 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -453,7 +453,7 @@ def _macos_application_impl(ctx): processor_result.output_groups, ) ), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -967,7 +967,7 @@ def _macos_extension_impl(ctx): DefaultInfo( files = processor_result.output_files, ), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -2092,7 +2092,7 @@ def _macos_command_line_application_impl(ctx): processor_result.output_groups, ) ), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -2377,7 +2377,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/framework_provider.bzl b/apple/internal/partials/framework_provider.bzl index 32f6145de3..21f5b898bf 100644 --- a/apple/internal/partials/framework_provider.bzl +++ b/apple/internal/partials/framework_provider.bzl @@ -80,7 +80,7 @@ def _framework_provider_partial_impl( ], ) - framework_provider = framework_import_support.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/testing/apple_test_bundle_support.bzl b/apple/internal/testing/apple_test_bundle_support.bzl index 34aa473c5b..85bcb5de4d 100644 --- a/apple/internal/testing/apple_test_bundle_support.bzl +++ b/apple/internal/testing/apple_test_bundle_support.bzl @@ -343,7 +343,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 and + test_host and AppleExecutableBinaryInfo in test_host and ctx.attr.test_host_is_bundle_loader ): bundle_loader = test_host diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 41ef5fe47b..4b6f36f1f2 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -458,7 +458,7 @@ def _tvos_application_impl(ctx): ) ), new_tvosapplicationbundleinfo(), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -1297,7 +1297,7 @@ def _tvos_extension_impl(ctx): processor_result.output_groups, ) ), - linking_support.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 20d2c7f6e2..912987dd76 100644 --- a/apple/internal/visionos_rules.bzl +++ b/apple/internal/visionos_rules.bzl @@ -462,7 +462,7 @@ Resolved Xcode is version {xcode_version}. ) ), new_visionosapplicationbundleinfo(), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), @@ -1298,7 +1298,7 @@ def _visionos_extension_impl(ctx): processor_result.output_groups, ) ), - linking_support.new_executable_binary_provider( + new_appleexecutablebinaryinfo( binary = binary_artifact, cc_info = link_result.cc_info, ), From d26bf8818995e8811bfc9f303869b5b4e8bbdcb0 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 5 Nov 2024 05:15:25 -0800 Subject: [PATCH 10/23] No public description PiperOrigin-RevId: 693308877 (cherry picked from commit 46535afcec837dcdaf216a3e94dff72e1f14c7a7) --- apple/internal/BUILD | 3 ++ apple/internal/linking_support.bzl | 9 ++++- apple/internal/macos_rules.bzl | 4 +- apple/internal/partials/BUILD | 1 + .../internal/partials/framework_provider.bzl | 2 +- apple/internal/providers.bzl | 32 ++++++++++++++++ apple/internal/providers/BUILD | 10 +++++ .../apple_dynamic_framework_info.bzl | 38 +++++++++++++++++++ .../testing/apple_test_bundle_support.bzl | 1 + apple/internal/tvos_rules.bzl | 1 + apple/internal/visionos_rules.bzl | 1 + apple/providers.bzl | 4 ++ 12 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 apple/internal/providers/apple_dynamic_framework_info.bzl diff --git a/apple/internal/BUILD b/apple/internal/BUILD index 0b1787636f..d1367d1697 100644 --- a/apple/internal/BUILD +++ b/apple/internal/BUILD @@ -341,7 +341,9 @@ bzl_library( ":apple_toolchains", ":cc_toolchain_info_support", ":entitlements_support", + ":providers", ":rule_support", + "//apple/internal/providers:apple_dynamic_framework_info", "@bazel_skylib//lib:collections", "@build_bazel_apple_support//lib:lipo", ], @@ -449,6 +451,7 @@ bzl_library( "//apple/internal/partials:swift_dynamic_framework", "//apple/internal/partials:swift_framework", "//apple/internal/partials:watchos_stub", + "//apple/internal/providers:apple_dynamic_framework_info", ], ) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 26a0e06d5b..8a675b0752 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -28,6 +28,11 @@ 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", @@ -326,7 +331,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): @@ -420,7 +425,7 @@ def _register_binary_linking_action( 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 diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 4035f066e6..71afca3ab3 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -86,7 +86,9 @@ load( ) load( "//apple/internal:providers.bzl", + "AppleExecutableBinaryInfo", "new_applebinaryinfo", + "new_appleexecutablebinaryinfo", "new_appleframeworkbundleinfo", "new_macosapplicationbundleinfo", "new_macosbundlebundleinfo", @@ -2093,7 +2095,7 @@ def _macos_command_line_application_impl(ctx): ) ), new_appleexecutablebinaryinfo( - binary = binary_artifact, + binary = output_file, cc_info = link_result.cc_info, ), # TODO(b/228856372): Remove when downstream users are migrated off this provider. diff --git a/apple/internal/partials/BUILD b/apple/internal/partials/BUILD index 52a3b65664..bf4b26623c 100644 --- a/apple/internal/partials/BUILD +++ b/apple/internal/partials/BUILD @@ -235,6 +235,7 @@ bzl_library( ], deps = [ "//apple/internal:framework_import_support", + "//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 21f5b898bf..cd93ed2505 100644 --- a/apple/internal/partials/framework_provider.bzl +++ b/apple/internal/partials/framework_provider.bzl @@ -24,7 +24,7 @@ load( ) load( "//apple/internal:framework_import_support.bzl", - "framework_import_support", + "AppleDynamicFrameworkInfo", ) def _framework_provider_partial_impl( diff --git a/apple/internal/providers.bzl b/apple/internal/providers.bzl index abf65b083d..04fea15fad 100644 --- a/apple/internal/providers.bzl +++ b/apple/internal/providers.bzl @@ -199,6 +199,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 = { @@ -214,6 +229,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 04fcab9de9..2549a3a3c7 100644 --- a/apple/internal/providers/BUILD +++ b/apple/internal/providers/BUILD @@ -31,6 +31,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 = "embeddable_info", srcs = ["embeddable_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 85bcb5de4d..8fdde7943d 100644 --- a/apple/internal/testing/apple_test_bundle_support.bzl +++ b/apple/internal/testing/apple_test_bundle_support.bzl @@ -74,6 +74,7 @@ load( ) load( "//apple/internal:providers.bzl", + "AppleExecutableBinaryInfo", "new_appleextraoutputsinfo", "new_appletestinfo", ) diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 4b6f36f1f2..52e4cb2285 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -82,6 +82,7 @@ load( ) load( "//apple/internal:providers.bzl", + "new_appleexecutablebinaryinfo", "new_appleframeworkbundleinfo", "new_tvosapplicationbundleinfo", "new_tvosextensionbundleinfo", diff --git a/apple/internal/visionos_rules.bzl b/apple/internal/visionos_rules.bzl index 912987dd76..33de047b4a 100644 --- a/apple/internal/visionos_rules.bzl +++ b/apple/internal/visionos_rules.bzl @@ -79,6 +79,7 @@ load( "ApplePlatformInfo", "VisionosExtensionBundleInfo", "VisionosFrameworkBundleInfo", + "new_appleexecutablebinaryinfo", "new_appleframeworkbundleinfo", "new_visionosapplicationbundleinfo", "new_visionosextensionbundleinfo", diff --git a/apple/providers.bzl b/apple/providers.bzl index 84aee66309..3f715ece43 100644 --- a/apple/providers.bzl +++ b/apple/providers.bzl @@ -36,7 +36,9 @@ load( _AppleBundleInfo = "AppleBundleInfo", _AppleBundleVersionInfo = "AppleBundleVersionInfo", _AppleCodesigningDossierInfo = "AppleCodesigningDossierInfo", + _AppleDebugOutputsInfo = "AppleDebugOutputsInfo", _AppleDsymBundleInfo = "AppleDsymBundleInfo", + _AppleExecutableBinaryInfo = "AppleExecutableBinaryInfo", _AppleExtraOutputsInfo = "AppleExtraOutputsInfo", _AppleFrameworkBundleInfo = "AppleFrameworkBundleInfo", _AppleFrameworkImportInfo = "AppleFrameworkImportInfo", @@ -85,7 +87,9 @@ AppleBundleInfo = _AppleBundleInfo AppleBinaryInfo = _AppleBinaryInfo AppleBundleVersionInfo = _AppleBundleVersionInfo AppleCodesigningDossierInfo = _AppleCodesigningDossierInfo +AppleDebugOutputsInfo = _AppleDebugOutputsInfo AppleDsymBundleInfo = _AppleDsymBundleInfo +AppleExecutableBinaryInfo = _AppleExecutableBinaryInfo AppleExtraOutputsInfo = _AppleExtraOutputsInfo AppleFrameworkBundleInfo = _AppleFrameworkBundleInfo AppleFrameworkImportInfo = _AppleFrameworkImportInfo From d255bf7cc567a3dce29d439c590553cac2a315d2 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 21:10:35 +0000 Subject: [PATCH 11/23] real last_green again --- .bazelci/presubmit.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 46a128a1a2..fb9be0e3bc 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -25,8 +25,7 @@ tasks: macos_last_green: name: "Last Green Bazel" - # FIXME: Use last_green once we cherry-pick https://github.com/bazelbuild/rules_apple/commit/46535afcec837dcdaf216a3e94dff72e1f14c7a7 - bazel: b59004dd17366b09b0758b833f98294fd0e89345 + bazel: last_green <<: *common doc_tests: From 68b9618dbfe52c5a056c7fb83145315bcc59d033 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 21:15:04 +0000 Subject: [PATCH 12/23] more compat --- apple/internal/providers.bzl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apple/internal/providers.bzl b/apple/internal/providers.bzl index 04fea15fad..0612bc0a8f 100644 --- a/apple/internal/providers.bzl +++ b/apple/internal/providers.bzl @@ -229,12 +229,16 @@ dependencies of the given target if any were generated. init = _make_banned_init(provider_name = "AppleDsymBundleInfo"), ) -AppleExecutableBinaryInfo, new_appleexecutablebinaryinfo = provider( +_AppleExecutableBinaryInfo = provider( doc = """ Contains the executable binary output that was built using `link_multi_arch_binary` with the `executable` binary type. """, fields = { + # TODO: Remove when we drop 7.x + "objc": """\ +apple_common.Objc provider used for legacy linking behavior. +""", "binary": """\ The executable binary artifact output by `link_multi_arch_binary`. """, @@ -243,9 +247,14 @@ A `CcInfo` which contains information about the transitive dependencies linked into the binary. """, }, - init = _make_banned_init(provider_name = "AppleExecutableBinaryInfo"), ) +AppleExecutableBinaryInfo = getattr(apple_common, "AppleExecutableBinaryInfo", _AppleExecutableBinaryInfo) + +# TODO: Use common init pattern when we drop 7.x +def new_appleexecutablebinaryinfo(**kwargs): + return AppleExecutableBinaryInfo(**kwargs) + AppleExtraOutputsInfo, new_appleextraoutputsinfo = provider( doc = """ Provides information about extra outputs that should be produced from the build. From d0cd1d323fd95d903864d0f98ef72730396aefb0 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 22:26:11 +0000 Subject: [PATCH 13/23] Add last_rc for now Useful to know what is broken in 8.x vs 9.x during the 8.x release cycle --- .bazelci/presubmit.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index fb9be0e3bc..e6c90fd1bc 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -23,6 +23,11 @@ tasks: bazel: latest <<: *common + macos_last_rc: + name: "Last RC Bazel" + bazel: last_rc + <<: *common + macos_last_green: name: "Last Green Bazel" bazel: last_green From fc631ffca6c73b807b010e870465c03e4a58f71e Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 14:37:43 -0800 Subject: [PATCH 14/23] Provider fix --- apple/internal/linking_support.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 8a675b0752..4bb526b33f 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -212,9 +212,9 @@ def _link_multi_arch_binary( 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] From 6861c6e7c7bbff8d473b5c35241d8f65aff93e4c Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 16:09:30 -0800 Subject: [PATCH 15/23] new ones --- apple/internal/linking_support.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index 4bb526b33f..cf3b2ca357 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -24,17 +24,17 @@ load( "entitlements_support", ) load( - "@build_bazel_rules_apple//apple/internal:multi_arch_binary_support.bzl", + "//apple/internal:multi_arch_binary_support.bzl", "get_split_target_triplet", "subtract_linking_contexts", ) load( - "@build_bazel_rules_apple//apple/internal:providers.bzl", + "//apple/internal:providers.bzl", "AppleExecutableBinaryInfo", "new_appledebugoutputsinfo", ) load( - "@build_bazel_rules_apple//apple/internal/providers:apple_dynamic_framework_info.bzl", + "//apple/internal/providers:apple_dynamic_framework_info.bzl", "AppleDynamicFrameworkInfo", ) From 7f8e95bd9ee0849a453311b4348c001b4f77a7bf Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 16:10:04 -0800 Subject: [PATCH 16/23] fix load --- apple/internal/partials/framework_provider.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/internal/partials/framework_provider.bzl b/apple/internal/partials/framework_provider.bzl index cd93ed2505..7fad4315fc 100644 --- a/apple/internal/partials/framework_provider.bzl +++ b/apple/internal/partials/framework_provider.bzl @@ -23,7 +23,7 @@ load( "paths", ) load( - "//apple/internal:framework_import_support.bzl", + "//apple/internal/providers:apple_dynamic_framework_info.bzl", "AppleDynamicFrameworkInfo", ) From e4ea857e863f31b4fd18eed61a6b71c7f84b592d Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 16:11:16 -0800 Subject: [PATCH 17/23] missing imports --- apple/apple_binary.bzl | 5 ++++- apple/internal/apple_framework_import.bzl | 4 ++++ apple/internal/apple_xcframework_import.bzl | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apple/apple_binary.bzl b/apple/apple_binary.bzl index 656e558910..1cbf0be7b9 100644 --- a/apple/apple_binary.bzl +++ b/apple/apple_binary.bzl @@ -19,9 +19,12 @@ load( "linking_support", ) load( - "//apple/internal:rule_attrs.bzl", + "//apple/internal:providers.bzl", "AppleExecutableBinaryInfo", "new_appleexecutablebinaryinfo", +) +load( + "//apple/internal:rule_attrs.bzl", "rule_attrs", ) load( diff --git a/apple/internal/apple_framework_import.bzl b/apple/internal/apple_framework_import.bzl index 35636e20ee..1273658ea5 100644 --- a/apple/internal/apple_framework_import.bzl +++ b/apple/internal/apple_framework_import.bzl @@ -69,6 +69,10 @@ load( "//apple/internal/aspects:swift_usage_aspect.bzl", "SwiftUsageInfo", ) +load( + "//apple/internal/providers:apple_dynamic_framework_info.bzl", + "AppleDynamicFrameworkInfo", +) load( "//apple/internal/providers:framework_import_bundle_info.bzl", "AppleFrameworkImportBundleInfo", diff --git a/apple/internal/apple_xcframework_import.bzl b/apple/internal/apple_xcframework_import.bzl index 0acf12e02c..3881de1592 100644 --- a/apple/internal/apple_xcframework_import.bzl +++ b/apple/internal/apple_xcframework_import.bzl @@ -43,6 +43,10 @@ load( "//apple/internal/aspects:swift_usage_aspect.bzl", "SwiftUsageInfo", ) +load( + "//apple/internal/providers:apple_dynamic_framework_info.bzl", + "AppleDynamicFrameworkInfo", +) load( "//apple/internal/providers:framework_import_bundle_info.bzl", "AppleFrameworkImportBundleInfo", From 63445f1831c011b9f4a5d2b37b5c4ff3cbee0e54 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 17:01:37 -0800 Subject: [PATCH 18/23] sync docs --- doc/providers.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/doc/providers.md b/doc/providers.md index b398d6d791..6b8e61a568 100644 --- a/doc/providers.md +++ b/doc/providers.md @@ -149,6 +149,31 @@ Provides information around the use of a code signing dossier. | dossier | A `File` reference to the code signing dossier zip that acts as a direct dependency of the given target if one was generated. | + + +## AppleDebugOutputsInfo + +
+AppleDebugOutputsInfo(outputs_map)
+
+ +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** + + +| Name | Description | +| :------------- | :------------- | +| outputs_map | - | + + ## AppleDeviceTestRunnerInfo @@ -187,6 +212,27 @@ Provides information for an Apple dSYM bundle. | transitive_dsyms | `depset` containing `File` references to each of the dSYM bundles that act as transitive dependencies of the given target if any were generated. | + + +## AppleExecutableBinaryInfo + +
+AppleExecutableBinaryInfo(objc, binary, cc_info)
+
+ +Contains the executable binary output that was built using +`link_multi_arch_binary` with the `executable` binary type. + +**FIELDS** + + +| Name | Description | +| :------------- | :------------- | +| objc | apple_common.Objc provider used for legacy linking behavior. | +| 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. | + + ## AppleExtraOutputsInfo From fff97ca542b506d969c9c1e1a3e400eb161d4803 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 5 Dec 2024 17:16:55 -0800 Subject: [PATCH 19/23] fix legacy usage --- apple/internal/linking_support.bzl | 3 +++ apple/internal/providers.bzl | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apple/internal/linking_support.bzl b/apple/internal/linking_support.bzl index cf3b2ca357..f50d89e59b 100644 --- a/apple/internal/linking_support.bzl +++ b/apple/internal/linking_support.bzl @@ -191,6 +191,9 @@ def _link_multi_arch_binary( avoid_deps = avoid_deps, extra_linkopts = extra_linkopts, extra_link_inputs = extra_link_inputs, + extra_requested_features = extra_requested_features, + extra_disabled_features = extra_disabled_features, + variables_extension = variables_extension, stamp = stamp, ) diff --git a/apple/internal/providers.bzl b/apple/internal/providers.bzl index 0612bc0a8f..4b667acbc6 100644 --- a/apple/internal/providers.bzl +++ b/apple/internal/providers.bzl @@ -249,10 +249,14 @@ into the binary. }, ) -AppleExecutableBinaryInfo = getattr(apple_common, "AppleExecutableBinaryInfo", _AppleExecutableBinaryInfo) +AppleExecutableBinaryInfo = getattr(apple_common, "AppleExecutableBinary", _AppleExecutableBinaryInfo) # TODO: Use common init pattern when we drop 7.x def new_appleexecutablebinaryinfo(**kwargs): + legacy_initializer = getattr(apple_common, "new_executable_binary_provider", None) + if legacy_initializer: + return legacy_initializer(**kwargs) + return AppleExecutableBinaryInfo(**kwargs) AppleExtraOutputsInfo, new_appleextraoutputsinfo = provider( From 26947aa86bead450a30dbc3e66e96bcd7ab4b2c1 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 6 Dec 2024 09:06:07 -0800 Subject: [PATCH 20/23] sync docs, strange one, nbd for now, mostly internal only anyways --- doc/providers.md | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/doc/providers.md b/doc/providers.md index 6b8e61a568..4c25facbd2 100644 --- a/doc/providers.md +++ b/doc/providers.md @@ -212,27 +212,6 @@ Provides information for an Apple dSYM bundle. | transitive_dsyms | `depset` containing `File` references to each of the dSYM bundles that act as transitive dependencies of the given target if any were generated. | - - -## AppleExecutableBinaryInfo - -
-AppleExecutableBinaryInfo(objc, binary, cc_info)
-
- -Contains the executable binary output that was built using -`link_multi_arch_binary` with the `executable` binary type. - -**FIELDS** - - -| Name | Description | -| :------------- | :------------- | -| objc | apple_common.Objc provider used for legacy linking behavior. | -| 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. | - - ## AppleExtraOutputsInfo From 7ed23bb2a1e9107cd23e6a0b0f0f4abe9850ee7e Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 6 Dec 2024 09:08:08 -0800 Subject: [PATCH 21/23] merge conflict issue --- apple/internal/macos_rules.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 71afca3ab3..6f36246a6d 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -2095,7 +2095,7 @@ def _macos_command_line_application_impl(ctx): ) ), new_appleexecutablebinaryinfo( - binary = output_file, + binary = binary_artifact, cc_info = link_result.cc_info, ), # TODO(b/228856372): Remove when downstream users are migrated off this provider. From fe396d647935d06d94ea2141b11396fb6e65f955 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 6 Dec 2024 09:18:02 -0800 Subject: [PATCH 22/23] getattr for dynamic framework provider too since we use bazel's internal linking function on 7.x, it looks for this old provider, so we can't use the new one until we drop that. --- apple/internal/apple_framework_import.bzl | 4 ++-- apple/internal/apple_xcframework_import.bzl | 3 ++- apple/internal/partials/framework_provider.bzl | 4 ++-- .../providers/apple_dynamic_framework_info.bzl | 13 ++++++++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apple/internal/apple_framework_import.bzl b/apple/internal/apple_framework_import.bzl index 1273658ea5..90544fbce0 100644 --- a/apple/internal/apple_framework_import.bzl +++ b/apple/internal/apple_framework_import.bzl @@ -71,7 +71,7 @@ load( ) load( "//apple/internal/providers:apple_dynamic_framework_info.bzl", - "AppleDynamicFrameworkInfo", + "new_appledynamicframeworkinfo", ) load( "//apple/internal/providers:framework_import_bundle_info.bzl", @@ -285,7 +285,7 @@ def _apple_dynamic_framework_import_impl(ctx): # Create AppleDynamicFramework provider. framework_groups = _grouped_framework_files(framework_imports) framework_dirs_set = depset(framework_groups.keys()) - providers.append(AppleDynamicFrameworkInfo( + providers.append(new_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 3881de1592..c663101b78 100644 --- a/apple/internal/apple_xcframework_import.bzl +++ b/apple/internal/apple_xcframework_import.bzl @@ -46,6 +46,7 @@ load( load( "//apple/internal/providers:apple_dynamic_framework_info.bzl", "AppleDynamicFrameworkInfo", + "new_appledynamicframeworkinfo", ) load( "//apple/internal/providers:framework_import_bundle_info.bzl", @@ -517,7 +518,7 @@ def _apple_dynamic_xcframework_import_impl(ctx): providers.append(cc_info) # Create AppleDynamicFrameworkInfo provider - apple_dynamic_framework_info = AppleDynamicFrameworkInfo( + apple_dynamic_framework_info = new_appledynamicframeworkinfo( cc_info = cc_info, ) providers.append(apple_dynamic_framework_info) diff --git a/apple/internal/partials/framework_provider.bzl b/apple/internal/partials/framework_provider.bzl index 7fad4315fc..776396a046 100644 --- a/apple/internal/partials/framework_provider.bzl +++ b/apple/internal/partials/framework_provider.bzl @@ -24,7 +24,7 @@ load( ) load( "//apple/internal/providers:apple_dynamic_framework_info.bzl", - "AppleDynamicFrameworkInfo", + "new_appledynamicframeworkinfo", ) def _framework_provider_partial_impl( @@ -80,7 +80,7 @@ def _framework_provider_partial_impl( ], ) - framework_provider = AppleDynamicFrameworkInfo( + framework_provider = new_appledynamicframeworkinfo( binary = binary_artifact, cc_info = wrapper_cc_info, framework_dirs = depset([absolute_framework_dir]), diff --git a/apple/internal/providers/apple_dynamic_framework_info.bzl b/apple/internal/providers/apple_dynamic_framework_info.bzl index 47f76ebb6d..fa94aaff2a 100644 --- a/apple/internal/providers/apple_dynamic_framework_info.bzl +++ b/apple/internal/providers/apple_dynamic_framework_info.bzl @@ -18,7 +18,7 @@ visibility([ "//apple/internal/...", ]) -AppleDynamicFrameworkInfo = provider( +_AppleDynamicFrameworkInfo = provider( doc = "Contains information about an Apple dynamic framework.", fields = { "framework_dirs": """\ @@ -36,3 +36,14 @@ into the binary. """, }, ) + +# TODO: Remove when we drop 7.x +AppleDynamicFrameworkInfo = getattr(apple_common, "AppleDynamicFramework", _AppleDynamicFrameworkInfo) + +# TODO: Remove when we drop 7.x +def new_appledynamicframeworkinfo(**kwargs): + legacy_initializer = getattr(apple_common, "new_dynamic_framework_provider", None) + if legacy_initializer: + return legacy_initializer(**kwargs) + + return AppleDynamicFrameworkInfo(**kwargs) From 408636bdb73c132f3aede2dacff91670ca27b1d6 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 6 Dec 2024 09:22:14 -0800 Subject: [PATCH 23/23] update docs with same version as CIl --- doc/providers.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/providers.md b/doc/providers.md index 4c25facbd2..3b17be59ec 100644 --- a/doc/providers.md +++ b/doc/providers.md @@ -212,6 +212,26 @@ Provides information for an Apple dSYM bundle. | transitive_dsyms | `depset` containing `File` references to each of the dSYM bundles that act as transitive dependencies of the given target if any were generated. | + + +## AppleExecutableBinaryInfo + +
+AppleExecutableBinaryInfo(binary, cc_info)
+
+ +Contains the executable binary output that was built using +`link_multi_arch_binary` with the `executable` binary type. + +**FIELDS** + + +| Name | Description | +| :------------- | :------------- | +| 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. | + + ## AppleExtraOutputsInfo