Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix apple_static_xcframework rule to exclude bundles of dependencies marked as avoid_deps #2541

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apple/internal/xcframework_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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_deps"],
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,
Expand All @@ -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,
))

Expand Down Expand Up @@ -1147,12 +1153,13 @@ the target will be used instead.
default = "@build_bazel_rules_apple//apple/internal:environment_plist_ios",
),
"avoid_deps": attr.label_list(
aspects = [apple_resource_aspect],
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.
closure of which will not be linked into the framework's binary, nor bundled into final XCFramework.
""",
),
"bundle_name": attr.string(
Expand Down
2 changes: 1 addition & 1 deletion doc/rules-apple.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Generates an XCFramework with static libraries for third-party distribution.
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <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 | |
| <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 | |
| <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 | `[]` |
| <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 | `[]` |
| <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 | `""` |
| <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 | `""` |
| <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 | `{}` |
Expand Down
17 changes: 17 additions & 0 deletions test/starlark_tests/apple_static_xcframework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ def apple_static_xcframework_test_suite(name):
tags = [name],
)

archive_contents_test(
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_deps",
contains = [
"$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_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],
)

archive_contents_test(
name = "{}_objc_generated_modulemap_file_content_test".format(name),
build_type = "device",
Expand Down
27 changes: 27 additions & 0 deletions test/starlark_tests/targets_under_test/apple/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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_deps",
avoid_deps = [":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 = {
Expand Down