Skip to content

Commit ab29ef8

Browse files
Fix apple_static_xcframework rule to exclude bundles of dependencies marked as avoid_deps (#2541)
Fixes #2540. ~Alternatively, I thought about not including resources from the dependencies passed in `avoid_deps`, but I'm not sure that this would not be a breaking change.~
1 parent e12f3a5 commit ab29ef8

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

apple/internal/xcframework_rules.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,11 @@ def _apple_static_xcframework_impl(ctx):
10461046
split_attr = ctx.split_attr,
10471047
split_attr_keys = link_output.split_attr_keys,
10481048
)
1049+
targets_to_avoid = _unioned_attrs(
1050+
attr_names = ["avoid_deps"],
1051+
split_attr = ctx.split_attr,
1052+
split_attr_keys = link_output.split_attr_keys,
1053+
)
10491054
partial_output = partial.call(partials.resources_partial(
10501055
actions = actions,
10511056
apple_mac_toolchain_info = apple_mac_toolchain_info,
@@ -1060,6 +1065,7 @@ def _apple_static_xcframework_impl(ctx):
10601065
resource_deps = resource_deps,
10611066
rule_descriptor = rule_descriptor,
10621067
rule_label = label,
1068+
targets_to_avoid = targets_to_avoid,
10631069
version = None,
10641070
))
10651071

@@ -1147,12 +1153,13 @@ the target will be used instead.
11471153
default = "@build_bazel_rules_apple//apple/internal:environment_plist_ios",
11481154
),
11491155
"avoid_deps": attr.label_list(
1156+
aspects = [apple_resource_aspect],
11501157
allow_files = True,
11511158
cfg = transition_support.xcframework_transition,
11521159
mandatory = False,
11531160
doc = """
11541161
A list of library targets on which this framework depends in order to compile, but the transitive
1155-
closure of which will not be linked into the framework's binary.
1162+
closure of which will not be linked into the framework's binary, nor bundled into final XCFramework.
11561163
""",
11571164
),
11581165
"bundle_name": attr.string(

doc/rules-apple.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Generates an XCFramework with static libraries for third-party distribution.
187187
| :------------- | :------------- | :------------- | :------------- | :------------- |
188188
| <a id="apple_static_xcframework-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
189189
| <a id="apple_static_xcframework-deps"></a>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. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
190-
| <a id="apple_static_xcframework-avoid_deps"></a>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. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
190+
| <a id="apple_static_xcframework-avoid_deps"></a>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. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
191191
| <a id="apple_static_xcframework-bundle_name"></a>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 | `""` |
192192
| <a id="apple_static_xcframework-executable_name"></a>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 | `""` |
193193
| <a id="apple_static_xcframework-families_required"></a>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. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a> | optional | `{}` |

test/starlark_tests/apple_static_xcframework_tests.bzl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ def apple_static_xcframework_test_suite(name):
8989
tags = [name],
9090
)
9191

92+
archive_contents_test(
93+
name = "{}_ios_avoid_deps_bundles_test".format(name),
94+
build_type = "device",
95+
compilation_mode = "opt",
96+
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_xcframework_bundling_static_fmwks_with_avoid_deps",
97+
contains = [
98+
"$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/ios_xcframework_bundling_static_fmwks_with_avoid_deps",
99+
"$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/ios_xcframework_bundling_static_fmwks_with_avoid_deps",
100+
"$BUNDLE_ROOT/Info.plist",
101+
],
102+
not_contains = [
103+
"$BUNDLE_ROOT/ios-arm64/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/resource_bundle.bundle",
104+
"$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks_with_avoid_deps.framework/resource_bundle.bundle",
105+
],
106+
tags = [name],
107+
)
108+
92109
archive_contents_test(
93110
name = "{}_objc_generated_modulemap_file_content_test".format(name),
94111
build_type = "device",

test/starlark_tests/targets_under_test/apple/BUILD

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,16 @@ objc_library(
939939
tags = common.fixture_tags,
940940
)
941941

942+
objc_library(
943+
name = "fmwk_lib_with_resources_upper_lib",
944+
srcs = [
945+
"//test/starlark_tests/resources:shared.h",
946+
"//test/starlark_tests/resources:shared.m",
947+
],
948+
tags = common.fixture_tags,
949+
deps = [":fmwk_lib_with_resources"],
950+
)
951+
942952
apple_static_xcframework(
943953
name = "ios_static_xcframework_with_resources",
944954
ios = {
@@ -1007,6 +1017,23 @@ apple_static_xcframework_import(
10071017
xcframework_imports = [":generated_ios_static_xcframework_with_resources"],
10081018
)
10091019

1020+
apple_static_xcframework(
1021+
name = "ios_xcframework_bundling_static_fmwks_with_avoid_deps",
1022+
avoid_deps = [":fmwk_lib_with_resources"],
1023+
ios = {
1024+
"simulator": [
1025+
"x86_64",
1026+
"arm64",
1027+
],
1028+
"device": ["arm64"],
1029+
},
1030+
minimum_os_versions = {
1031+
"ios": common.min_os_ios.baseline,
1032+
},
1033+
tags = common.fixture_tags,
1034+
deps = [":fmwk_lib_with_resources_upper_lib"],
1035+
)
1036+
10101037
apple_static_xcframework(
10111038
name = "ios_xcframework_bundling_static_fmwks",
10121039
ios = {

0 commit comments

Comments
 (0)