From ac4c7429711128050eae92ea2f31c21cec4fb242 Mon Sep 17 00:00:00 2001 From: "i@jerrymarino.com" Date: Thu, 20 Jul 2023 11:13:30 -0700 Subject: [PATCH 1/2] Remove invalid product type It was previously hardcoded as as static library and led to confusion even though it was mainly unused at the time. Fixes #742 --- rules/framework.bzl | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/rules/framework.bzl b/rules/framework.bzl index a9bb27f7d..2b5fbde67 100644 --- a/rules/framework.bzl +++ b/rules/framework.bzl @@ -582,7 +582,7 @@ def _merge_root_infoplists(ctx): current_apple_platform = transition_support.current_apple_platform(apple_fragment = ctx.fragments.apple, xcode_config = ctx.attr._xcode_config) platform_type = str(current_apple_platform.platform.platform_type) apple_mac_toolchain_info = ctx.attr._toolchain[AppleMacToolsToolchainInfo] - rule_descriptor = rule_support.rule_descriptor(ctx) + rule_descriptor = rule_support.rule_descriptor_no_ctx(platform_type, apple_product_type.static_framework) resource_actions.merge_root_infoplists( actions = ctx.actions, @@ -648,8 +648,8 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): rules_apple_api_version = getattr(bundling_support, "rule_api_version", None) use_lts_5_rules_apple_api = rules_apple_api_version == 1.0 - bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) - executable_name = bundling_support.executable_name(ctx) + bundle_name = ctx.attr.framework_name + bundle_extension = ".framework" features = features_support.compute_enabled_features( requested_features = ctx.features, unsupported_features = ctx.disabled_features, @@ -663,11 +663,13 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): provisioning_profile = None resource_deps = ctx.attr.deps + ctx.attr.transitive_deps + ctx.attr.data - rule_descriptor = rule_support.rule_descriptor(ctx) + current_apple_platform = transition_support.current_apple_platform(apple_fragment = ctx.fragments.apple, xcode_config = ctx.attr._xcode_config) + platform_type = str(current_apple_platform.platform.platform_type) + rule_descriptor = rule_support.rule_descriptor_no_ctx(platform_type, apple_product_type.framework) signed_frameworks = [] if provisioning_profile: signed_frameworks = [ - bundle_name + rule_descriptor.bundle_extension, + bundle_name + bundle_extension, ] top_level_resources = resources.collect( attr = ctx.attr, @@ -703,7 +705,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): actions = actions, bundle_name = bundle_name, bundle_extension = bundle_extension, - executable_name = executable_name, + executable_name = bundle_name, label_name = label.name, rule_descriptor = rule_descriptor, platform_prerequisites = platform_prerequisites, @@ -721,7 +723,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): bundle_extension = bundle_extension, bundle_id = bundle_id, bundle_name = bundle_name, - executable_name = executable_name, + executable_name = bundle_name, label_name = label.name, platform_prerequisites = platform_prerequisites, predeclared_outputs = predeclared_outputs, @@ -733,7 +735,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): actions = actions, binary_artifact = binary_artifact, bundle_name = bundle_name, - executable_name = executable_name, + executable_name = bundle_name, label_name = label.name, ), ) @@ -775,7 +777,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): dsym_binaries = debug_outputs.dsym_binaries, linkmaps = debug_outputs.linkmaps, dsym_info_plist_template = apple_mac_toolchain_info.dsym_info_plist_template, - executable_name = executable_name, + executable_name = bundle_name, platform_prerequisites = platform_prerequisites, bin_root_path = bin_root_path, ), @@ -790,7 +792,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): dsym_binaries = debug_outputs.dsym_binaries, linkmaps = debug_outputs.linkmaps, dsym_info_plist_template = apple_mac_toolchain_info.dsym_info_plist_template, - executable_name = executable_name, + executable_name = bundle_name, platform_prerequisites = platform_prerequisites, ), ) @@ -855,7 +857,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): bundle_id = bundle_id, bundle_name = bundle_name, environment_plist = ctx.file.environment_plist, - executable_name = executable_name, + executable_name = bundle_name, launch_storyboard = None, platform_prerequisites = platform_prerequisites, resource_deps = resource_deps, @@ -897,7 +899,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): bundle_name = bundle_name, codesign_inputs = [], codesignopts = [], - executable_name = executable_name, + executable_name = bundle_name, features = features, ipa_post_processor = None, partials = processor_partials, @@ -1210,7 +1212,6 @@ that this target depends on. If not given, the framework will be built for the platform it inherits from the target that uses the framework as a dependency.""", ), - "_product_type": attr.string(default = apple_product_type.static_framework), "_xcode_config": attr.label( default = configuration_field( name = "xcode_config_label", @@ -1240,6 +1241,13 @@ the framework as a dependency.""", mandatory = False, doc = """Internal - currently rules_ios the dict `platforms` +""", + ), + "families": attr.string_list( + mandatory = False, + default = ["iphone", "ipad"], + doc = + """Internal - currently rules_ios the dict `platforms` """, ), "minimum_deployment_os_version": attr.string( From 9523862242bc54c6c933e40a936abcbc28c115ca Mon Sep 17 00:00:00 2001 From: "i@jerrymarino.com" Date: Thu, 20 Jul 2023 12:00:30 -0700 Subject: [PATCH 2/2] Simplify prerequisites / nix families addition --- rules/framework.bzl | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/rules/framework.bzl b/rules/framework.bzl index 2b5fbde67..812a60a37 100644 --- a/rules/framework.bzl +++ b/rules/framework.bzl @@ -22,6 +22,7 @@ load("@build_bazel_rules_apple//apple/internal:resource_actions.bzl", "resource_ load("@build_bazel_rules_apple//apple/internal:resources.bzl", "resources") load("@build_bazel_rules_apple//apple/internal:rule_support.bzl", "rule_support") load("@build_bazel_rules_apple//apple/internal:apple_toolchains.bzl", "AppleMacToolsToolchainInfo", "AppleXPlatToolsToolchainInfo") +load("@build_bazel_rules_apple//apple/internal:swift_support.bzl", "swift_support") load("@build_bazel_rules_apple//apple/internal/utils:clang_rt_dylibs.bzl", "clang_rt_dylibs") load("@build_bazel_rules_apple//apple:providers.bzl", "AppleBundleInfo", "IosFrameworkBundleInfo") load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo", "swift_clang_module_aspect", "swift_common") @@ -596,19 +597,7 @@ def _merge_root_infoplists(ctx): output_plist = output_plist, output_pkginfo = None, output_discriminator = "framework", - platform_prerequisites = platform_support.platform_prerequisites( - apple_fragment = ctx.fragments.apple, - config_vars = ctx.var, - device_families = rule_descriptor.allowed_device_families, - explicit_minimum_os = None, - explicit_minimum_deployment_os = None, - objc_fragment = None, - platform_type_string = platform_type, - uses_swift = False, - xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig], - disabled_features = [], - features = [], - ), + platform_prerequisites = _platform_prerequisites(ctx, rule_descriptor, platform_type), resolved_plisttool = apple_mac_toolchain_info.resolved_plisttool, rule_descriptor = rule_descriptor, rule_label = ctx.label, @@ -625,6 +614,26 @@ def _attrs_for_split_slice(attrs_by_split_slices, split_slice_key): else: return attrs_by_split_slices[split_slice_key] +def _platform_prerequisites(ctx, rule_descriptor, platform_type): + # Consider plumbing this in + deps = getattr(ctx.attr, "deps", None) + uses_swift = swift_support.uses_swift(deps) if deps else False + + return platform_support.platform_prerequisites( + apple_fragment = ctx.fragments.apple, + config_vars = ctx.var, + cpp_fragment = ctx.fragments.cpp, + device_families = rule_descriptor.allowed_device_families, + disabled_features = ctx.disabled_features, + explicit_minimum_deployment_os = ctx.attr.minimum_deployment_os_version, + explicit_minimum_os = ctx.attr.minimum_os_version, + features = ctx.features, + objc_fragment = ctx.fragments.objc, + platform_type_string = platform_type, + uses_swift = uses_swift, + xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig], + ) + def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): """Packages this as dynamic framework @@ -655,7 +664,6 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): unsupported_features = ctx.disabled_features, ) label = ctx.label - platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) # This file is used as part of the rules_apple bundling logic archive = actions.declare_file(ctx.attr.name + ".framework.zip") @@ -666,6 +674,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): current_apple_platform = transition_support.current_apple_platform(apple_fragment = ctx.fragments.apple, xcode_config = ctx.attr._xcode_config) platform_type = str(current_apple_platform.platform.platform_type) rule_descriptor = rule_support.rule_descriptor_no_ctx(platform_type, apple_product_type.framework) + platform_prerequisites = _platform_prerequisites(ctx, rule_descriptor, platform_type) signed_frameworks = [] if provisioning_profile: signed_frameworks = [ @@ -1241,13 +1250,6 @@ the framework as a dependency.""", mandatory = False, doc = """Internal - currently rules_ios the dict `platforms` -""", - ), - "families": attr.string_list( - mandatory = False, - default = ["iphone", "ipad"], - doc = - """Internal - currently rules_ios the dict `platforms` """, ), "minimum_deployment_os_version": attr.string(