diff --git a/apple/internal/resource_actions/plist.bzl b/apple/internal/resource_actions/plist.bzl index 6eb6f436a..cee6b8e71 100644 --- a/apple/internal/resource_actions/plist.bzl +++ b/apple/internal/resource_actions/plist.bzl @@ -341,19 +341,21 @@ def merge_root_infoplists( else: plist_key = "MinimumOSVersion" - input_files.append(environment_plist) + if environment_plist: + input_files.append(environment_plist) + forced_plists.append(environment_plist.path) + 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, + 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: diff --git a/apple/internal/transition_support.bzl b/apple/internal/transition_support.bzl index 113f23255..7f0324133 100644 --- a/apple/internal/transition_support.bzl +++ b/apple/internal/transition_support.bzl @@ -658,15 +658,22 @@ def _xcframework_transition_impl(settings, attr): # TODO(b/288582842): Update for visionOS when we're ready to support it in XCFramework rules. for platform_type in ["ios", "tvos", "visionos", "watchos", "macos"]: - if not hasattr(attr, platform_type): + platform_attr = getattr(attr, platform_type, None) + if not platform_attr: continue + + # On the macOS platform the platform attr is a list and not a dict as device is the only option. + # To make the transition logic consistent with the other platforms, + # we convert the attr to a dict here so that the rest of the logic can be the same. + platform_attr = {"device": platform_attr} if platform_type == "macos" else platform_attr + target_environments = ["device"] if platform_type != "macos": target_environments.append("simulator") command_line_options = _command_line_options_for_xcframework_platform( minimum_os_version = attr.minimum_os_versions.get(platform_type), - platform_attr = getattr(attr, platform_type), + platform_attr = platform_attr, platform_type = platform_type, settings = settings, target_environments = target_environments, diff --git a/apple/internal/xcframework_rules.bzl b/apple/internal/xcframework_rules.bzl index 6c965f73d..17b1e6684 100644 --- a/apple/internal/xcframework_rules.bzl +++ b/apple/internal/xcframework_rules.bzl @@ -857,6 +857,11 @@ for what is supported. 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`). """, ), "tvos": attr.string_list_dict( @@ -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( diff --git a/doc/rules-apple.md b/doc/rules-apple.md index 8d5846936..917533a54 100755 --- a/doc/rules-apple.md +++ b/doc/rules-apple.md @@ -174,7 +174,7 @@ implementation of `apple_static_library` in Bazel core so that it can be removed
 apple_static_xcframework(name, deps, avoid_deps, bundle_name, executable_name, families_required,
-                         ios, minimum_deployment_os_versions, minimum_os_versions, public_hdrs,
+                         ios, macos, minimum_deployment_os_versions, minimum_os_versions, public_hdrs,
                          umbrella_header)
 
@@ -192,6 +192,7 @@ Generates an XCFramework with static libraries for third-party distribution. | 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 | `{}` | | 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. | Dictionary: String -> List of strings | optional | `{}` | +| macos | A list of strings indicating which architecture should be built for the macOS platform (for example, `x86_64`, `arm64`). | List of strings | optional | `[]` | | 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. | Dictionary: String -> String | optional | `{}` | | 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. | Dictionary: String -> String | required | | | 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`. | List of labels | optional | `[]` | @@ -279,7 +280,7 @@ The `lipo` tool is used to combine built binaries of multiple architectures.
 apple_xcframework(name, deps, data, additional_linker_inputs, bundle_id, bundle_name,
                   codesign_inputs, codesignopts, exported_symbols_lists, extension_safe,
-                  families_required, infoplists, ios, linkopts, minimum_deployment_os_versions,
+                  families_required, infoplists, ios, linkopts, macos, minimum_deployment_os_versions,
                   minimum_os_versions, public_hdrs, stamp, tvos, umbrella_header, version)
 
@@ -304,6 +305,7 @@ Builds and bundles an XCFramework for third-party distribution. | 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. | List of labels | required | | | 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. | Dictionary: String -> List of strings | optional | `{}` | | linkopts | A list of strings representing extra flags that should be passed to the linker. | List of strings | optional | `[]` | +| macos | A list of strings indicating which architecture should be built for the macOS platform (for example, `x86_64`, `arm64`). | List of strings | optional | `[]` | | 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. | Dictionary: String -> String | optional | `{}` | | 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:

minimum_os_versions = { "ios": "13.0", "tvos": "15.0", } | Dictionary: String -> String | required | | | 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`. | List of labels | optional | `[]` | diff --git a/test/starlark_tests/targets_under_test/apple/BUILD b/test/starlark_tests/targets_under_test/apple/BUILD index b472041f9..53b02fc9d 100644 --- a/test/starlark_tests/targets_under_test/apple/BUILD +++ b/test/starlark_tests/targets_under_test/apple/BUILD @@ -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"], +) diff --git a/test/starlark_tests/targets_under_test/macos/BUILD b/test/starlark_tests/targets_under_test/macos/BUILD index d37c91c26..7981f625b 100644 --- a/test/starlark_tests/targets_under_test/macos/BUILD +++ b/test/starlark_tests/targets_under_test/macos/BUILD @@ -7,6 +7,8 @@ load( "apple_dynamic_framework_import", "apple_dynamic_xcframework_import", "apple_static_framework_import", + "apple_static_xcframework", + "apple_xcframework", ) load( "//apple:macos.bzl", @@ -2963,3 +2965,43 @@ macos_application( tags = common.fixture_tags, deps = ["//test/starlark_tests/resources:ccinfo_dylibs_libapp"], ) + +# --------------------------------------------------------------------------------------- +# Targets for macOS xcframework tests. + +apple_xcframework( + name = "macos_dynamic_xcframework", + bundle_id = "com.google.example", + extension_safe = True, + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + macos = [ + "arm64", + "x86_64", + ], + minimum_os_versions = { + "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 = "macos_static_xcframework", + macos = [ + "arm64", + "x86_64", + ], + minimum_os_versions = { + "macos": common.min_os_macos.baseline, + }, + public_hdrs = [ + "//test/starlark_tests/resources:shared.h", + ], + tags = common.fixture_tags, + deps = [":fmwk_lib"], +)