Skip to content

Commit bdd83d9

Browse files
authored
Support creating Info.plist for inner framework apple_static_xcframework (#2791)
Will generate an `Info.plist` for inner `.framework` directories inside a static XCFramework when `infoplists` and `bundle_id` is provided (kept optional for backward compatibility). Closes #2456
1 parent aa0cef2 commit bdd83d9

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed

apple/internal/xcframework_rules.bzl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,21 @@ def _apple_static_xcframework_impl(ctx):
11631163
split_attr = ctx.split_attr,
11641164
split_attr_keys = link_output.split_attr_keys,
11651165
)
1166+
1167+
# Collect top_level_infoplists only if bundle_id is set
1168+
top_level_infoplists = []
1169+
if ctx.attr.bundle_id:
1170+
top_level_infoplists = resources.collect(
1171+
attr = ctx.split_attr,
1172+
res_attrs = ["infoplists"],
1173+
split_attr_keys = link_output.split_attr_keys,
1174+
)
1175+
11661176
partial_output = partial.call(partials.resources_partial(
11671177
actions = actions,
11681178
apple_mac_toolchain_info = apple_mac_toolchain_info,
11691179
bundle_extension = ".framework",
1180+
bundle_id = ctx.attr.bundle_id,
11701181
bundle_name = bundle_name,
11711182
# TODO(b/174858377): Select which environment_plist to use based on Apple platform.
11721183
environment_plist = ctx.file._environment_plist_ios,
@@ -1178,7 +1189,8 @@ def _apple_static_xcframework_impl(ctx):
11781189
rule_descriptor = rule_descriptor,
11791190
rule_label = label,
11801191
targets_to_avoid = targets_to_avoid,
1181-
version = None,
1192+
top_level_infoplists = top_level_infoplists,
1193+
version = ctx.attr.version,
11821194
))
11831195

11841196
if getattr(partial_output, "bundle_files", None):
@@ -1256,6 +1268,14 @@ apple_static_xcframework = rule_factory.create_apple_rule(
12561268
deps_cfg = transition_support.xcframework_transition,
12571269
),
12581270
{
1271+
"bundle_id": attr.string(
1272+
mandatory = False,
1273+
doc = """
1274+
Optional bundle ID (reverse-DNS path followed by framework name) for each of the embedded frameworks.
1275+
If present, this value will be embedded in an Info.plist within each framework bundle, similar to
1276+
apple_xcframework (dynamic frameworks).
1277+
""",
1278+
),
12591279
"executable_name": attr.string(
12601280
mandatory = False,
12611281
doc = """
@@ -1302,6 +1322,16 @@ values are `iphone` and `ipad` for `ios`; at least one must be specified if a pl
13021322
Currently, this only affects processing of `ios` resources.
13031323
""",
13041324
),
1325+
"infoplists": attr.label_list(
1326+
allow_empty = True,
1327+
allow_files = [".plist"],
1328+
cfg = transition_support.xcframework_transition,
1329+
doc = """
1330+
A list of .plist files that will be merged to form the Info.plist for each of the embedded
1331+
frameworks. Only used if bundle_id is provided.
1332+
""",
1333+
mandatory = False,
1334+
),
13051335
"ios": attr.string_list_dict(
13061336
doc = """
13071337
A dictionary of strings indicating which platform variants should be built for the `ios` platform (
@@ -1347,6 +1377,13 @@ An optional single .h file to use as the umbrella header for this framework. Usu
13471377
will have the same name as this target, so that clients can load the header using the #import
13481378
<MyFramework/MyFramework.h> format. If this attribute is not specified (the common use case), an
13491379
umbrella header will be generated under the same name as this target.
1380+
""",
1381+
),
1382+
"version": attr.label(
1383+
providers = [[AppleBundleVersionInfo]],
1384+
doc = """
1385+
An `apple_bundle_version` target that represents the version for this target. See
1386+
[`apple_bundle_version`](https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-versioning.md#apple_bundle_version).
13501387
""",
13511388
),
13521389
},

doc/rules-apple.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ implementation of `apple_static_library` in Bazel core so that it can be removed
183183
<pre>
184184
load("@rules_apple//apple:apple.bzl", "apple_static_xcframework")
185185

186-
apple_static_xcframework(<a href="#apple_static_xcframework-name">name</a>, <a href="#apple_static_xcframework-deps">deps</a>, <a href="#apple_static_xcframework-avoid_deps">avoid_deps</a>, <a href="#apple_static_xcframework-bundle_name">bundle_name</a>, <a href="#apple_static_xcframework-executable_name">executable_name</a>, <a href="#apple_static_xcframework-families_required">families_required</a>,
187-
<a href="#apple_static_xcframework-ios">ios</a>, <a href="#apple_static_xcframework-macos">macos</a>, <a href="#apple_static_xcframework-minimum_deployment_os_versions">minimum_deployment_os_versions</a>, <a href="#apple_static_xcframework-minimum_os_versions">minimum_os_versions</a>, <a href="#apple_static_xcframework-public_hdrs">public_hdrs</a>,
188-
<a href="#apple_static_xcframework-umbrella_header">umbrella_header</a>)
186+
apple_static_xcframework(<a href="#apple_static_xcframework-name">name</a>, <a href="#apple_static_xcframework-deps">deps</a>, <a href="#apple_static_xcframework-avoid_deps">avoid_deps</a>, <a href="#apple_static_xcframework-bundle_id">bundle_id</a>, <a href="#apple_static_xcframework-bundle_name">bundle_name</a>, <a href="#apple_static_xcframework-executable_name">executable_name</a>,
187+
<a href="#apple_static_xcframework-families_required">families_required</a>, <a href="#apple_static_xcframework-infoplists">infoplists</a>, <a href="#apple_static_xcframework-ios">ios</a>, <a href="#apple_static_xcframework-macos">macos</a>, <a href="#apple_static_xcframework-minimum_deployment_os_versions">minimum_deployment_os_versions</a>,
188+
<a href="#apple_static_xcframework-minimum_os_versions">minimum_os_versions</a>, <a href="#apple_static_xcframework-public_hdrs">public_hdrs</a>, <a href="#apple_static_xcframework-umbrella_header">umbrella_header</a>, <a href="#apple_static_xcframework-version">version</a>)
189189
</pre>
190190

191191
Generates an XCFramework with static libraries for third-party distribution.
@@ -198,15 +198,18 @@ Generates an XCFramework with static libraries for third-party distribution.
198198
| <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 | |
199199
| <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 | |
200200
| <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 | `[]` |
201+
| <a id="apple_static_xcframework-bundle_id"></a>bundle_id | Optional bundle ID (reverse-DNS path followed by framework name) for each of the embedded frameworks. If present, this value will be embedded in an Info.plist within each framework bundle, similar to apple_xcframework (dynamic frameworks). | String | optional | `""` |
201202
| <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 | `""` |
202203
| <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 | `""` |
203204
| <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 | `{}` |
205+
| <a id="apple_static_xcframework-infoplists"></a>infoplists | A list of .plist files that will be merged to form the Info.plist for each of the embedded frameworks. Only used if bundle_id is provided. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
204206
| <a id="apple_static_xcframework-ios"></a>ios | A dictionary of strings indicating which platform variants should be built for the `ios` platform ( `device` or `simulator`) as keys, and arrays of strings listing which architectures should be built for those platform variants (for example, `x86_64`, `arm64`) as their values. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a> | optional | `{}` |
205207
| <a id="apple_static_xcframework-macos"></a>macos | A list of strings indicating which architecture should be built for the macOS platform (for example, `x86_64`, `arm64`). | List of strings | optional | `[]` |
206208
| <a id="apple_static_xcframework-minimum_deployment_os_versions"></a>minimum_deployment_os_versions | A dictionary of strings indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0") as values, with their respective platforms such as `ios` as keys. This is different from `minimum_os_versions`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
207209
| <a id="apple_static_xcframework-minimum_os_versions"></a>minimum_os_versions | A dictionary of strings indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "8.0") as values, with their respective platforms such as `ios` as keys. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
208210
| <a id="apple_static_xcframework-public_hdrs"></a>public_hdrs | A list of files directly referencing header files to be used as the publicly visible interface for each of these embedded libraries. These header files will be embedded within each platform split, typically in a subdirectory such as `Headers`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
209211
| <a id="apple_static_xcframework-umbrella_header"></a>umbrella_header | An optional single .h file to use as the umbrella header for this framework. Usually, this header will have the same name as this target, so that clients can load the header using the #import <MyFramework/MyFramework.h> format. If this attribute is not specified (the common use case), an umbrella header will be generated under the same name as this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
212+
| <a id="apple_static_xcframework-version"></a>version | An `apple_bundle_version` target that represents the version for this target. See [`apple_bundle_version`](https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-versioning.md#apple_bundle_version). | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
210213

211214

212215
<a id="apple_static_xcframework_import"></a>

test/starlark_tests/apple_static_xcframework_tests.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ def apple_static_xcframework_test_suite(name):
291291
tags = [name],
292292
)
293293

294+
archive_contents_test(
295+
name = "{}_ios_inner_framework_infoplist_test".format(name),
296+
build_type = "device",
297+
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_static_xcframework_with_bundle_id",
298+
plist_test_file = "$BUNDLE_ROOT/ios-arm64/ios_static_xcframework_with_bundle_id.framework/Info.plist",
299+
plist_test_values = {
300+
"CFBundleIdentifier": "com.example.static.framework",
301+
"CFBundleExecutable": "ios_static_xcframework_with_bundle_id",
302+
"CFBundleShortVersionString": "2.1",
303+
"CFBundleVersion": "2.1.0",
304+
"MinimumOSVersion": common.min_os_ios.baseline,
305+
},
306+
tags = [name],
307+
)
308+
294309
directory_test(
295310
name = "{}_ios_static_library_xcframework_tree_artifact_test".format(name),
296311
build_settings = {

test/starlark_tests/targets_under_test/apple/BUILD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,3 +1654,27 @@ apple_static_xcframework(
16541654
tags = common.fixture_tags,
16551655
deps = [":fmwk_lib"],
16561656
)
1657+
1658+
apple_bundle_version(
1659+
name = "static_xcframework_version",
1660+
build_version = "2.1.0",
1661+
short_version_string = "2.1",
1662+
tags = common.fixture_tags,
1663+
)
1664+
1665+
apple_static_xcframework(
1666+
name = "ios_static_xcframework_with_bundle_id",
1667+
bundle_id = "com.example.static.framework",
1668+
infoplists = ["//test/starlark_tests/resources:Info.plist"],
1669+
ios = {
1670+
"simulator": ["x86_64"],
1671+
"device": ["arm64"],
1672+
},
1673+
minimum_os_versions = {
1674+
"ios": common.min_os_ios.baseline,
1675+
},
1676+
public_hdrs = ["//test/starlark_tests/resources:shared.h"],
1677+
tags = common.fixture_tags,
1678+
version = ":static_xcframework_version",
1679+
deps = [":fmwk_lib"],
1680+
)

0 commit comments

Comments
 (0)