From 157feeafc6f3f2380185f4f474995d7a5c2aa8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seweryn=20Plaz=CC=87uk?= Date: Fri, 20 Sep 2024 14:20:44 +0200 Subject: [PATCH 1/4] Introduce avoid_bundles into apple_static_xcframework rule --- apple/internal/xcframework_rules.bzl | 16 +++++++++++ doc/rules-apple.md | 3 ++- .../apple_static_xcframework_tests.bzl | 17 ++++++++++++ .../targets_under_test/apple/BUILD | 27 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/apple/internal/xcframework_rules.bzl b/apple/internal/xcframework_rules.bzl index 6c965f73da..264bb68462 100644 --- a/apple/internal/xcframework_rules.bzl +++ b/apple/internal/xcframework_rules.bzl @@ -1046,6 +1046,11 @@ def _apple_static_xcframework_impl(ctx): split_attr = ctx.split_attr, split_attr_keys = link_output.split_attr_keys, ) + targets_to_avoid = _unioned_attrs( + attr_names = ["avoid_bundles"], + split_attr = ctx.split_attr, + split_attr_keys = link_output.split_attr_keys, + ) partial_output = partial.call(partials.resources_partial( actions = actions, apple_mac_toolchain_info = apple_mac_toolchain_info, @@ -1060,6 +1065,7 @@ def _apple_static_xcframework_impl(ctx): resource_deps = resource_deps, rule_descriptor = rule_descriptor, rule_label = label, + targets_to_avoid = targets_to_avoid, version = None, )) @@ -1153,6 +1159,16 @@ the target will be used instead. doc = """ A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. +""", + ), + "avoid_bundles": attr.label_list( + aspects = [apple_resource_aspect], + allow_files = True, + cfg = transition_support.xcframework_transition, + mandatory = False, + doc = """ +A list of library targets containing resources on which this framework depends to compile, but the transitive +closure will not be bundled into final XCFramework. """, ), "bundle_name": attr.string( diff --git a/doc/rules-apple.md b/doc/rules-apple.md index 17c3b625ab..768f8540e4 100755 --- a/doc/rules-apple.md +++ b/doc/rules-apple.md @@ -173,7 +173,7 @@ implementation of `apple_static_library` in Bazel core so that it can be removed ## apple_static_xcframework
-apple_static_xcframework(name, deps, avoid_deps, bundle_name, executable_name, families_required,
+apple_static_xcframework(name, deps, avoid_deps, avoid_bundles, bundle_name, executable_name, families_required,
                          ios, minimum_deployment_os_versions, minimum_os_versions, public_hdrs,
                          umbrella_header)
 
@@ -188,6 +188,7 @@ Generates an XCFramework with static libraries for third-party distribution. | name | A unique name for this target. | Name | required | | | deps | A list of files directly referencing libraries to be represented for each given platform split in the XCFramework. These libraries will be embedded within each platform split. | List of labels | required | | | avoid_deps | A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. | List of labels | optional | `[]` | +| avoid_bundles | A list of library targets containing resources on which this framework depends to compile, but the transitive closure will not be bundled into final XCFramework. | List of labels | optional | `[]` | | bundle_name | The desired name of the XCFramework bundle (without the extension) and the binaries for all embedded static libraries. If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` | | executable_name | The desired name of the executable, if the bundle has an executable. If this attribute is not set, then the name of the `bundle_name` attribute will be used if it is set; if not, then the name of the target will be used instead. | String | optional | `""` | | families_required | A list of device families supported by this extension, with platforms such as `ios` as keys. Valid values are `iphone` and `ipad` for `ios`; at least one must be specified if a platform is defined. Currently, this only affects processing of `ios` resources. | Dictionary: String -> List of strings | optional | `{}` | diff --git a/test/starlark_tests/apple_static_xcframework_tests.bzl b/test/starlark_tests/apple_static_xcframework_tests.bzl index b631bd9c93..2d0829cde3 100644 --- a/test/starlark_tests/apple_static_xcframework_tests.bzl +++ b/test/starlark_tests/apple_static_xcframework_tests.bzl @@ -89,6 +89,23 @@ def apple_static_xcframework_test_suite(name): tags = [name], ) + archive_contents_test( + name = "{}_ios_avoid_bundles_test".format(name), + build_type = "device", + compilation_mode = "opt", + target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_xcframework_bundling_static_fmwks_with_avoid_bundles", + contains = [ + "$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/ios_xcframework_bundling_static_fmwks_with_avoid_bundles", + "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/ios_xcframework_bundling_static_fmwks_with_avoid_bundles", + "$BUNDLE_ROOT/Info.plist", + ], + not_contains = [ + "$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/resource_bundle.bundle", + "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/resource_bundle.bundle", + ], + tags = [name], + ) + archive_contents_test( name = "{}_objc_generated_modulemap_file_content_test".format(name), build_type = "device", diff --git a/test/starlark_tests/targets_under_test/apple/BUILD b/test/starlark_tests/targets_under_test/apple/BUILD index b472041f97..c67944e3ac 100644 --- a/test/starlark_tests/targets_under_test/apple/BUILD +++ b/test/starlark_tests/targets_under_test/apple/BUILD @@ -939,6 +939,16 @@ objc_library( tags = common.fixture_tags, ) +objc_library( + name = "fmwk_lib_with_resources_upper_lib", + srcs = [ + "//test/starlark_tests/resources:shared.h", + "//test/starlark_tests/resources:shared.m", + ], + tags = common.fixture_tags, + deps = [":fmwk_lib_with_resources"] +) + apple_static_xcframework( name = "ios_static_xcframework_with_resources", ios = { @@ -1007,6 +1017,23 @@ apple_static_xcframework_import( xcframework_imports = [":generated_ios_static_xcframework_with_resources"], ) +apple_static_xcframework( + name = 'ios_xcframework_bundling_static_fmwks_with_avoid_bundles', + avoid_bundles = [":fmwk_lib_with_resources"], + ios = { + "simulator": [ + "x86_64", + "arm64", + ], + "device": ["arm64"], + }, + minimum_os_versions = { + "ios": common.min_os_ios.baseline, + }, + tags = common.fixture_tags, + deps = [":fmwk_lib_with_resources_upper_lib"], +) + apple_static_xcframework( name = "ios_xcframework_bundling_static_fmwks", ios = { From 7ea4ee1cb2c0fde8d636adfc4a244878d7ec3870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seweryn=20Plaz=CC=87uk?= Date: Mon, 23 Sep 2024 09:36:43 +0200 Subject: [PATCH 2/4] Run buildifier --- test/starlark_tests/targets_under_test/apple/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/starlark_tests/targets_under_test/apple/BUILD b/test/starlark_tests/targets_under_test/apple/BUILD index c67944e3ac..cba9a1f290 100644 --- a/test/starlark_tests/targets_under_test/apple/BUILD +++ b/test/starlark_tests/targets_under_test/apple/BUILD @@ -946,7 +946,7 @@ objc_library( "//test/starlark_tests/resources:shared.m", ], tags = common.fixture_tags, - deps = [":fmwk_lib_with_resources"] + deps = [":fmwk_lib_with_resources"], ) apple_static_xcframework( @@ -1018,7 +1018,7 @@ apple_static_xcframework_import( ) apple_static_xcframework( - name = 'ios_xcframework_bundling_static_fmwks_with_avoid_bundles', + name = "ios_xcframework_bundling_static_fmwks_with_avoid_bundles", avoid_bundles = [":fmwk_lib_with_resources"], ios = { "simulator": [ From f0b1995c5365f86b8783941282802583f7482835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seweryn=20Plaz=CC=87uk?= Date: Mon, 23 Sep 2024 09:40:12 +0200 Subject: [PATCH 3/4] Update docs --- doc/rules-apple.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/rules-apple.md b/doc/rules-apple.md index 768f8540e4..a56627cb1b 100755 --- a/doc/rules-apple.md +++ b/doc/rules-apple.md @@ -173,9 +173,9 @@ implementation of `apple_static_library` in Bazel core so that it can be removed ## apple_static_xcframework
-apple_static_xcframework(name, deps, avoid_deps, avoid_bundles, bundle_name, executable_name, families_required,
-                         ios, minimum_deployment_os_versions, minimum_os_versions, public_hdrs,
-                         umbrella_header)
+apple_static_xcframework(name, deps, avoid_bundles, avoid_deps, bundle_name, executable_name,
+                         families_required, ios, minimum_deployment_os_versions, minimum_os_versions,
+                         public_hdrs, umbrella_header)
 
Generates an XCFramework with static libraries for third-party distribution. @@ -187,8 +187,8 @@ Generates an XCFramework with static libraries for third-party distribution. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | deps | A list of files directly referencing libraries to be represented for each given platform split in the XCFramework. These libraries will be embedded within each platform split. | List of labels | required | | -| avoid_deps | A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. | List of labels | optional | `[]` | | avoid_bundles | A list of library targets containing resources on which this framework depends to compile, but the transitive closure will not be bundled into final XCFramework. | List of labels | optional | `[]` | +| avoid_deps | A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. | List of labels | optional | `[]` | | bundle_name | The desired name of the XCFramework bundle (without the extension) and the binaries for all embedded static libraries. If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` | | executable_name | The desired name of the executable, if the bundle has an executable. If this attribute is not set, then the name of the `bundle_name` attribute will be used if it is set; if not, then the name of the target will be used instead. | String | optional | `""` | | families_required | A list of device families supported by this extension, with platforms such as `ios` as keys. Valid values are `iphone` and `ipad` for `ios`; at least one must be specified if a platform is defined. Currently, this only affects processing of `ios` resources. | Dictionary: String -> List of strings | optional | `{}` | From d18ca8b013142afb2334a5ebc0e48d22c65a226e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seweryn=20Plaz=CC=87uk?= Date: Tue, 24 Sep 2024 08:15:33 +0200 Subject: [PATCH 4/4] Filter out avoid_deps bundles from final XCFramework --- apple/internal/xcframework_rules.bzl | 15 +++------------ doc/rules-apple.md | 9 ++++----- .../apple_static_xcframework_tests.bzl | 12 ++++++------ .../starlark_tests/targets_under_test/apple/BUILD | 4 ++-- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/apple/internal/xcframework_rules.bzl b/apple/internal/xcframework_rules.bzl index 264bb68462..e862c1e220 100644 --- a/apple/internal/xcframework_rules.bzl +++ b/apple/internal/xcframework_rules.bzl @@ -1047,7 +1047,7 @@ def _apple_static_xcframework_impl(ctx): split_attr_keys = link_output.split_attr_keys, ) targets_to_avoid = _unioned_attrs( - attr_names = ["avoid_bundles"], + attr_names = ["avoid_deps"], split_attr = ctx.split_attr, split_attr_keys = link_output.split_attr_keys, ) @@ -1153,22 +1153,13 @@ the target will be used instead. default = "@build_bazel_rules_apple//apple/internal:environment_plist_ios", ), "avoid_deps": attr.label_list( - allow_files = True, - cfg = transition_support.xcframework_transition, - mandatory = False, - doc = """ -A list of library targets on which this framework depends in order to compile, but the transitive -closure of which will not be linked into the framework's binary. -""", - ), - "avoid_bundles": attr.label_list( aspects = [apple_resource_aspect], allow_files = True, cfg = transition_support.xcframework_transition, mandatory = False, doc = """ -A list of library targets containing resources on which this framework depends to compile, but the transitive -closure will not be bundled into final XCFramework. +A list of library targets on which this framework depends in order to compile, but the transitive +closure of which will not be linked into the framework's binary, nor bundled into final XCFramework. """, ), "bundle_name": attr.string( diff --git a/doc/rules-apple.md b/doc/rules-apple.md index a56627cb1b..81a87e7222 100755 --- a/doc/rules-apple.md +++ b/doc/rules-apple.md @@ -173,9 +173,9 @@ implementation of `apple_static_library` in Bazel core so that it can be removed ## apple_static_xcframework
-apple_static_xcframework(name, deps, avoid_bundles, avoid_deps, bundle_name, executable_name,
-                         families_required, ios, minimum_deployment_os_versions, minimum_os_versions,
-                         public_hdrs, umbrella_header)
+apple_static_xcframework(name, deps, avoid_deps, bundle_name, executable_name, families_required,
+                         ios, minimum_deployment_os_versions, minimum_os_versions, public_hdrs,
+                         umbrella_header)
 
Generates an XCFramework with static libraries for third-party distribution. @@ -187,8 +187,7 @@ Generates an XCFramework with static libraries for third-party distribution. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | deps | A list of files directly referencing libraries to be represented for each given platform split in the XCFramework. These libraries will be embedded within each platform split. | List of labels | required | | -| avoid_bundles | A list of library targets containing resources on which this framework depends to compile, but the transitive closure will not be bundled into final XCFramework. | List of labels | optional | `[]` | -| avoid_deps | A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. | List of labels | optional | `[]` | +| avoid_deps | A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary, nor bundled into final XCFramework. | List of labels | optional | `[]` | | bundle_name | The desired name of the XCFramework bundle (without the extension) and the binaries for all embedded static libraries. If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` | | executable_name | The desired name of the executable, if the bundle has an executable. If this attribute is not set, then the name of the `bundle_name` attribute will be used if it is set; if not, then the name of the target will be used instead. | String | optional | `""` | | families_required | A list of device families supported by this extension, with platforms such as `ios` as keys. Valid values are `iphone` and `ipad` for `ios`; at least one must be specified if a platform is defined. Currently, this only affects processing of `ios` resources. | Dictionary: String -> List of strings | optional | `{}` | diff --git a/test/starlark_tests/apple_static_xcframework_tests.bzl b/test/starlark_tests/apple_static_xcframework_tests.bzl index 2d0829cde3..50b86eb514 100644 --- a/test/starlark_tests/apple_static_xcframework_tests.bzl +++ b/test/starlark_tests/apple_static_xcframework_tests.bzl @@ -90,18 +90,18 @@ def apple_static_xcframework_test_suite(name): ) archive_contents_test( - name = "{}_ios_avoid_bundles_test".format(name), + name = "{}_ios_avoid_deps_bundles_test".format(name), build_type = "device", compilation_mode = "opt", - target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_xcframework_bundling_static_fmwks_with_avoid_bundles", + target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_xcframework_bundling_static_fmwks_with_avoid_deps", contains = [ - "$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/ios_xcframework_bundling_static_fmwks_with_avoid_bundles", - "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/ios_xcframework_bundling_static_fmwks_with_avoid_bundles", + "$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/ios_xcframework_bundling_static_fmwks_with_avoid_deps", + "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/ios_xcframework_bundling_static_fmwks_with_avoid_deps", "$BUNDLE_ROOT/Info.plist", ], not_contains = [ - "$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/resource_bundle.bundle", - "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_bundles.framework/resource_bundle.bundle", + "$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/resource_bundle.bundle", + "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/resource_bundle.bundle", ], tags = [name], ) diff --git a/test/starlark_tests/targets_under_test/apple/BUILD b/test/starlark_tests/targets_under_test/apple/BUILD index cba9a1f290..a4b5ad477e 100644 --- a/test/starlark_tests/targets_under_test/apple/BUILD +++ b/test/starlark_tests/targets_under_test/apple/BUILD @@ -1018,8 +1018,8 @@ apple_static_xcframework_import( ) apple_static_xcframework( - name = "ios_xcframework_bundling_static_fmwks_with_avoid_bundles", - avoid_bundles = [":fmwk_lib_with_resources"], + name = "ios_xcframework_bundling_static_fmwks_with_avoid_deps", + avoid_deps = [":fmwk_lib_with_resources"], ios = { "simulator": [ "x86_64",