From 821c85cf280093bf7593c3af74a6294903897220 Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Mon, 4 Mar 2024 23:05:00 -0500 Subject: [PATCH] DROP: add changes from #811 --- rules/BUILD.bazel | 1 + rules/force_load_direct_deps.bzl | 89 ++++++++++++++++++++------ rules/framework.bzl | 22 +++++-- rules/internal/framework_middleman.bzl | 66 +++++++++++++++++-- rules/internal/objc_provider_utils.bzl | 7 +- 5 files changed, 154 insertions(+), 31 deletions(-) diff --git a/rules/BUILD.bazel b/rules/BUILD.bazel index 3d3e1d7b8..4e6906e35 100644 --- a/rules/BUILD.bazel +++ b/rules/BUILD.bazel @@ -53,6 +53,7 @@ bzl_library( ":providers", ":transition_support", "@bazel_skylib//lib:dicts", + "@bazel_skylib//rules:common_settings", ], ) diff --git a/rules/force_load_direct_deps.bzl b/rules/force_load_direct_deps.bzl index b9e864869..c7ac5ee08 100644 --- a/rules/force_load_direct_deps.bzl +++ b/rules/force_load_direct_deps.bzl @@ -1,10 +1,9 @@ load("//rules:providers.bzl", "AvoidDepsInfo") -load("//rules:transition_support.bzl", "split_transition_rule_attrs", "transition_support") -load("@bazel_skylib//lib:dicts.bzl", "dicts") +load("//rules:transition_support.bzl", "transition_support") -def _impl(ctx): +def _force_load_direct_deps_impl(ctx): if not ctx.attr.should_force_load: - return apple_common.new_objc_provider() + return [apple_common.new_objc_provider(), CcInfo()] force_load = [] @@ -14,25 +13,69 @@ def _impl(ctx): avoid_deps.extend(dep[AvoidDepsInfo].libraries) avoid_libraries = {} - for dep in avoid_deps: - if apple_common.Objc in dep: - for lib in dep[apple_common.Objc].library.to_list(): - avoid_libraries[lib] = True - force_load = [] - for dep in ctx.attr.deps: - if apple_common.Objc in dep: - for lib in dep[apple_common.Objc].library.to_list(): - if not lib in avoid_libraries: - force_load.append(lib) - return apple_common.new_objc_provider( - force_load_library = depset(force_load), - link_inputs = depset(force_load), - ) + _is_bazel_7 = not hasattr(apple_common, "apple_crosstool_transition") + if _is_bazel_7: + for dep in avoid_deps: + if CcInfo in dep: + for linker_input in dep[CcInfo].linking_context.linker_inputs.to_list(): + for lib in linker_input.libraries: + avoid_libraries[lib] = True + + force_load = [] + for dep in ctx.attr.deps: + if CcInfo in dep: + for linker_input in dep[CcInfo].linking_context.linker_inputs.to_list(): + for lib in linker_input.libraries: + if not lib in avoid_libraries: + force_load.append(lib) + + static_libraries = [lib.static_library for lib in force_load if lib.static_library != None] + return [ + apple_common.new_objc_provider( + force_load_library = depset(static_libraries), + link_inputs = depset(static_libraries), + ), + CcInfo( + linking_context = cc_common.create_linking_context( + linker_inputs = depset([ + cc_common.create_linker_input( + owner = ctx.label, + libraries = depset([ + cc_common.create_library_to_link( + actions = ctx.actions, + static_library = lib, + alwayslink = True, + ) + for lib in static_libraries + ]), + additional_inputs = depset(static_libraries), + ), + ]), + ), + ), + ] + else: + for dep in avoid_deps: + if apple_common.Objc in dep: + for lib in dep[apple_common.Objc].library.to_list(): + avoid_libraries[lib] = True + force_load = [] + + for dep in ctx.attr.deps: + if apple_common.Objc in dep: + for lib in dep[apple_common.Objc].library.to_list(): + if not lib in avoid_libraries: + force_load.append(lib) + + return apple_common.new_objc_provider( + force_load_library = depset(force_load), + link_inputs = depset(force_load), + ) force_load_direct_deps = rule( - implementation = _impl, - attrs = dicts.add(split_transition_rule_attrs, { + implementation = _force_load_direct_deps_impl, + attrs = { "deps": attr.label_list( cfg = transition_support.split_transition, mandatory = True, @@ -55,7 +98,11 @@ force_load_direct_deps = rule( """Internal - currently rules_ios the dict `platforms` """, ), - }), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + doc = "Needed to allow this rule to have an incoming edge configuration transition.", + ), + }, doc = """ A rule to link with `-force_load` for direct`deps` diff --git a/rules/framework.bzl b/rules/framework.bzl index 90f40d613..7f827cfc0 100644 --- a/rules/framework.bzl +++ b/rules/framework.bzl @@ -1029,11 +1029,23 @@ def _apple_framework_packaging_impl(ctx): # If not virtualizing the framework - then it runs a "clean" _get_symlinked_framework_clean_action(ctx, framework_files, compilation_context_fields) - cc_info_provider = CcInfo( - compilation_context = cc_common.create_compilation_context( - **compilation_context_fields - ), - ) + _is_bazel_7 = not hasattr(apple_common, "apple_crosstool_transition") + if _is_bazel_7: + cc_info_provider = CcInfo( + compilation_context = cc_common.create_compilation_context( + **compilation_context_fields + ), + linking_context = cc_common.merge_cc_infos( + direct_cc_infos = [], + cc_infos = [dep[CcInfo] for dep in deps], + ).linking_context, + ) + else: + cc_info_provider = CcInfo( + compilation_context = cc_common.create_compilation_context( + **compilation_context_fields + ), + ) if virtualize_frameworks: cc_info = cc_common.merge_cc_infos(direct_cc_infos = [cc_info_provider]) diff --git a/rules/internal/framework_middleman.bzl b/rules/internal/framework_middleman.bzl index 7b75125b7..52825a660 100644 --- a/rules/internal/framework_middleman.bzl +++ b/rules/internal/framework_middleman.bzl @@ -6,7 +6,9 @@ load( "new_applebundleinfo", "new_iosframeworkbundleinfo", ) +load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("@bazel_skylib//lib:dicts.bzl", "dicts") +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load( "@build_bazel_rules_apple//apple/internal:partials.bzl", "partials", @@ -32,7 +34,11 @@ load( "//rules/internal:objc_provider_utils.bzl", "objc_provider_utils", ) -load("//rules:transition_support.bzl", "split_transition_rule_attrs", "transition_support") +load( + "//rules:transition_support.bzl", + "split_transition_rule_attrs", + "transition_support", +) def _framework_middleman(ctx): resource_providers = [] @@ -74,12 +80,48 @@ def _framework_middleman(ctx): ]) # Add the frameworks to the linker command - dynamic_framework_provider = objc_provider_utils.merge_dynamic_framework_providers(dynamic_framework_providers) + _is_bazel_7 = not hasattr(apple_common, "apple_crosstool_transition") + dynamic_framework_provider = objc_provider_utils.merge_dynamic_framework_providers( + dynamic_framework_providers, + supports_cc_info_in_dynamic_framework_provider = _is_bazel_7, + ) objc_provider_fields["dynamic_framework_file"] = depset( transitive = [dynamic_framework_provider.framework_files, objc_provider_fields.get("dynamic_framework_file", depset([]))], ) objc_provider = apple_common.new_objc_provider(**objc_provider_fields) + cc_info_provider = cc_common.merge_cc_infos(direct_cc_infos = [], cc_infos = cc_providers) + if _is_bazel_7: + cc_toolchain = find_cpp_toolchain(ctx) + cc_features = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + language = "objc", + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + dynamic_framework_libraries_to_link = [ + cc_common.create_library_to_link( + actions = ctx.actions, + feature_configuration = cc_features, + cc_toolchain = cc_toolchain, + dynamic_library = dynamic_library, + ) + for dynamic_library in objc_provider_fields["dynamic_framework_file"].to_list() + ] + cc_info_provider = cc_common.merge_cc_infos( + direct_cc_infos = [ + CcInfo( + linking_context = cc_common.create_linking_context( + linker_inputs = depset([cc_common.create_linker_input( + owner = ctx.label, + libraries = depset(dynamic_framework_libraries_to_link), + )]), + ), + ), + ] + cc_providers, + ) + providers = [ dynamic_framework_provider, cc_info_provider, @@ -121,7 +163,9 @@ def _framework_middleman(ctx): framework_middleman = rule( implementation = _framework_middleman, - attrs = dicts.add(split_transition_rule_attrs, { + fragments = ["cpp"], + toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], + attrs = { "framework_deps": attr.label_list( cfg = transition_support.split_transition, mandatory = True, @@ -153,7 +197,12 @@ framework_middleman = rule( """Internal - The product type of the framework """, ), - }), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + doc = """Needed to allow this rule to have an incoming edge configuration transition. +""", + ), + }, doc = """ This is a volatile internal rule to make frameworks work with rules_apples bundling logic @@ -188,9 +237,13 @@ def _dep_middleman(ctx): cc_providers = [] avoid_libraries = {} + _is_bazel_7 = not hasattr(apple_common, "apple_crosstool_transition") + def _collect_providers(lib_dep): if apple_common.Objc in lib_dep: objc_providers.append(lib_dep[apple_common.Objc]) + if _is_bazel_7 and CcInfo in lib_dep: + cc_providers.append(lib_dep[CcInfo]) def _process_avoid_deps(avoid_dep_libs): for dep in avoid_dep_libs: @@ -273,6 +326,11 @@ dep_middleman = rule( mandatory = False, doc = """Internal - currently rules_ios the dict `platforms` +""", + ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + doc = """Needed to allow this rule to have an incoming edge configuration transition. """, ), }), diff --git a/rules/internal/objc_provider_utils.bzl b/rules/internal/objc_provider_utils.bzl index cba49ae47..de9a6793e 100644 --- a/rules/internal/objc_provider_utils.bzl +++ b/rules/internal/objc_provider_utils.bzl @@ -37,7 +37,7 @@ def _merge_objc_providers(providers, transitive = []): ) return apple_common.new_objc_provider(**objc_provider_fields) -def _merge_dynamic_framework_providers(dynamic_framework_providers): +def _merge_dynamic_framework_providers(dynamic_framework_providers, supports_cc_info_in_dynamic_framework_provider): fields = {} merge_keys = [ "framework_dirs", @@ -53,6 +53,11 @@ def _merge_dynamic_framework_providers(dynamic_framework_providers): fields["objc"] = apple_common.new_objc_provider() + if not supports_cc_info_in_dynamic_framework_provider: + fields.pop("cc_info", None) + elif "cc_info" not in fields: + fields["cc_info"] = CcInfo() + return apple_common.new_dynamic_framework_provider(**fields) objc_provider_utils = struct(