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

Add support for macos in apple_*_xcframework rules #2459

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion apple/internal/cc_info_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def _get_all_deps(*, deps, split_deps_keys = []):

all_deps = []
for split_deps_key in split_deps_keys:
all_deps += deps[split_deps_key]
if split_deps_key in deps:
all_deps += deps[split_deps_key]
Comment on lines +35 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keith @brentleyjones this fixes an issue introduced by adding the macos attr to apple_static_xcframework:

ERROR: /Users/lpadron/Development/rules_apple/test/starlark_tests/targets_under_test/apple/BUILD:942:25: in apple_static_xcframework rule //test/starlark_tests/targets_under_test/apple:ios_static_xcframework_with_resources: 
Traceback (most recent call last):
        File "/Users/lpadron/Development/rules_apple/apple/internal/xcframework_rules.bzl", line 943, column 83, in _apple_static_xcframework_impl
                link_outputs_by_library_identifier = _group_link_outputs_by_library_identifier(
        File "/Users/lpadron/Development/rules_apple/apple/internal/xcframework_rules.bzl", line 205, column 45, in _group_link_outputs_by_library_identifier
                if swift_support.uses_swift(deps[split_attr_key]):
Error: key "ios_arm64e_device" not found in dictionary

How should we properly fix this? Is the apple_rule_arm64_as_arm64e_transition being applied here for some reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still leaves us with:

ERROR: /Users/lpadron/Development/rules_apple/test/starlark_tests/targets_under_test/apple/BUILD:508:8: declared output 'test/starlark_tests/targets_under_test/apple/ios_xcframework_bundling_static_fmwks.xcframework/ios-arm64_x86_64-simulator/ios_xcframework_bundling_static_fmwks.framework/Headers/ios_xcframework_bundling_static_fmwks.h' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT adding macos changes the transitions to add arm64e, maybe this is related to #2419 as well since that's a split deps issue as well.

return all_deps

def _get_sdk_frameworks(*, deps, split_deps_keys = [], include_weak = False):
Expand Down
9 changes: 5 additions & 4 deletions apple/internal/resource_actions/plist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,20 @@ def merge_root_infoplists(
else:
plist_key = "MinimumOSVersion"

input_files.append(environment_plist)
platform = platform_prerequisites.platform
sdk_version = platform_prerequisites.sdk_version
platform_with_version = platform.name_in_plist.lower() + str(sdk_version)
forced_plists.extend([
environment_plist.path,
if environment_plist:
input_files.append(environment_plist)
forced_plists.append(environment_plist.path)
forced_plists.append(
struct(
CFBundleSupportedPlatforms = [platform.name_in_plist],
DTPlatformName = platform.name_in_plist.lower(),
DTSDKName = platform_with_version,
**{plist_key: platform_prerequisites.minimum_deployment_os}
),
])
)

output_files = [output_plist]
if output_pkginfo:
Expand Down
13 changes: 10 additions & 3 deletions apple/internal/transition_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ load(
"@build_bazel_rules_apple//apple/build_settings:build_settings.bzl",
"build_settings_labels",
)
load(
"@bazel_skylib//lib:types.bzl",
"types",
)

_supports_visionos = hasattr(apple_common.platform_type, "visionos")
_is_bazel_7 = not hasattr(apple_common, "apple_crosstool_transition")
Expand Down Expand Up @@ -346,9 +350,12 @@ def _command_line_options_for_xcframework_platform(
"""
output_dictionary = {}
for target_environment in target_environments:
if not platform_attr.get(target_environment):
continue
for arch in platform_attr[target_environment]:
if types.is_dict(platform_attr):
if not platform_attr.get(target_environment):
continue
platform_attr = platform_attr[target_environment]

for arch in platform_attr:
resolved_environment_arch = _resolved_environment_arch_for_arch(
arch = arch,
environment = target_environment,
Expand Down
12 changes: 11 additions & 1 deletion apple/internal/xcframework_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _group_link_outputs_by_library_identifier(

# If there's any Swift dependencies on this framework rule,
# look for providers to see if we need to generate Swift interfaces.
if swift_support.uses_swift(deps[split_attr_key]):
if split_attr_key in deps and swift_support.uses_swift(deps[split_attr_key]):
uses_swift = True
for dep in deps[split_attr_key]:
if SwiftInfo in dep:
Expand Down Expand Up @@ -864,6 +864,11 @@ built for those platform variants (for example, `x86_64`, `arm64`) as their valu
A dictionary of strings indicating which platform variants should be built for the tvOS 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.
""",
),
"macos": attr.string_list(
doc = """
A list of strings indicating which architecture should be built for the macOS platform (for example, `x86_64`, `arm64`).
Comment on lines +869 to +871
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this a string_list_dict keeps the logic simpler, and maybe we just fail if folks pass simulator?

""",
),
"minimum_deployment_os_versions": attr.string_dict(
Expand Down Expand Up @@ -1184,6 +1189,11 @@ Currently, this only affects processing of `ios` resources.
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.
""",
),
"macos": attr.string_list(
doc = """
A list of strings indicating which architecture should be built for the macOS platform (for example, `x86_64`, `arm64`).
""",
),
"minimum_deployment_os_versions": attr.string_dict(
Expand Down
8 changes: 5 additions & 3 deletions doc/rules-apple.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ implementation of `apple_static_library` in Bazel core so that it can be removed

<pre>
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>,
<a href="#apple_static_xcframework-ios">ios</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>,
<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>,
<a href="#apple_static_xcframework-umbrella_header">umbrella_header</a>)
</pre>

Expand All @@ -192,6 +192,7 @@ Generates an XCFramework with static libraries for third-party distribution.
| <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 | `{}` |
| <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 | `{}` |
| <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 | `[]` |
| <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 | `{}` |
| <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 | |
| <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 | `[]` |
Expand Down Expand Up @@ -279,7 +280,7 @@ The `lipo` tool is used to combine built binaries of multiple architectures.
<pre>
apple_xcframework(<a href="#apple_xcframework-name">name</a>, <a href="#apple_xcframework-deps">deps</a>, <a href="#apple_xcframework-data">data</a>, <a href="#apple_xcframework-additional_linker_inputs">additional_linker_inputs</a>, <a href="#apple_xcframework-bundle_id">bundle_id</a>, <a href="#apple_xcframework-bundle_name">bundle_name</a>,
<a href="#apple_xcframework-codesign_inputs">codesign_inputs</a>, <a href="#apple_xcframework-codesignopts">codesignopts</a>, <a href="#apple_xcframework-exported_symbols_lists">exported_symbols_lists</a>, <a href="#apple_xcframework-extension_safe">extension_safe</a>,
<a href="#apple_xcframework-families_required">families_required</a>, <a href="#apple_xcframework-infoplists">infoplists</a>, <a href="#apple_xcframework-ios">ios</a>, <a href="#apple_xcframework-linkopts">linkopts</a>, <a href="#apple_xcframework-minimum_deployment_os_versions">minimum_deployment_os_versions</a>,
<a href="#apple_xcframework-families_required">families_required</a>, <a href="#apple_xcframework-infoplists">infoplists</a>, <a href="#apple_xcframework-ios">ios</a>, <a href="#apple_xcframework-linkopts">linkopts</a>, <a href="#apple_xcframework-macos">macos</a>, <a href="#apple_xcframework-minimum_deployment_os_versions">minimum_deployment_os_versions</a>,
<a href="#apple_xcframework-minimum_os_versions">minimum_os_versions</a>, <a href="#apple_xcframework-public_hdrs">public_hdrs</a>, <a href="#apple_xcframework-stamp">stamp</a>, <a href="#apple_xcframework-tvos">tvos</a>, <a href="#apple_xcframework-umbrella_header">umbrella_header</a>, <a href="#apple_xcframework-version">version</a>)
</pre>

Expand All @@ -304,6 +305,7 @@ Builds and bundles an XCFramework for third-party distribution.
| <a id="apple_xcframework-infoplists"></a>infoplists | A list of .plist files that will be merged to form the Info.plist for each of the embedded frameworks. At least one file must be specified. Please see [Info.plist Handling](https://github.com/bazelbuild/rules_apple/blob/master/doc/common_info.md#infoplist-handling) for what is supported. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="apple_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 | `{}` |
| <a id="apple_xcframework-linkopts"></a>linkopts | A list of strings representing extra flags that should be passed to the linker. | List of strings | optional | `[]` |
| <a id="apple_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 | `[]` |
| <a id="apple_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 | `{}` |
| <a id="apple_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`, or `tvos` as keys:<br><br> minimum_os_versions = { "ios": "13.0", "tvos": "15.0", } | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
| <a id="apple_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 frameworks. These header files will be embedded within each bundle, typically in a subdirectory such as `Headers`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
Expand Down Expand Up @@ -488,7 +490,7 @@ This repository rule depends on the following environment variables:
## provisioning_profile_repository_extension

<pre>
provisioning_profile_repository_extension = use_extension("@rules_apple//apple:apple.bzl", "provisioning_profile_repository_extension")
provisioning_profile_repository_extension = use_extension("@build_bazel_rules_apple//apple:apple.bzl", "provisioning_profile_repository_extension")
provisioning_profile_repository_extension.setup(<a href="#provisioning_profile_repository_extension.setup-fallback_profiles">fallback_profiles</a>)
</pre>

Expand Down
53 changes: 53 additions & 0 deletions test/starlark_tests/targets_under_test/apple/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1530,3 +1530,56 @@ apple_metal_library(
hdrs = ["@build_bazel_rules_apple//test/testdata/resources:metal_hdrs"],
tags = common.fixture_tags,
)

# ---------------------------------------------------------------------------------------
# Targets for multiplatform xcframework tests.

apple_xcframework(
name = "ios_and_macos_dynamic_xcframework",
bundle_id = "com.google.example",
extension_safe = True,
infoplists = [
"//test/starlark_tests/resources:Info.plist",
],
ios = {
"simulator": ["x86_64"],
"device": ["arm64"],
},
macos = [
"arm64",
"x86_64",
],
minimum_os_versions = {
"ios": common.min_os_ios.baseline,
"macos": common.min_os_macos.baseline,
},
public_hdrs = [
"//test/starlark_tests/resources:shared.h",
],
tags = common.fixture_tags,
deps = [":fmwk_lib"],
)

apple_static_xcframework(
name = "ios_and_macos_static_xcframework",
ios = {
"simulator": [
"x86_64",
"arm64",
],
"device": ["arm64"],
},
macos = [
"arm64",
"x86_64",
],
minimum_os_versions = {
"ios": common.min_os_ios.baseline,
"macos": common.min_os_macos.baseline,
},
public_hdrs = [
"//test/starlark_tests/resources:shared.h",
],
tags = common.fixture_tags,
deps = [":fmwk_lib"],
)