Skip to content

Commit

Permalink
Add watchOS ExtensionKit Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
maustinstar committed Apr 18, 2023
1 parent 91657ff commit ccc2f24
Show file tree
Hide file tree
Showing 6 changed files with 565 additions and 6 deletions.
9 changes: 9 additions & 0 deletions apple/internal/rule_factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,15 @@ If `True`, this extension is an App Extension instead of a WatchKit Extension.
It links the extension with the application extension point (`_NSExtensionMain`)
instead of the WatchKit extension point (`_WKExtensionMain`), and has the
`app_extension` `product_type` instead of `watch2_extension`.
""",
),
"extensionkit_extension": attr.bool(
default = False,
doc = """
If `True`, this extension is an ExtensionKit Extension instead of a WatchKit Extension.
It links the extension with the application extension point (`_NSExtensionMain`)
instead of the WatchKit extension point (`_WKExtensionMain`), and has the
`extensionkit_extension` `product_type` instead of `watch2_extension`.
""",
),
})
Expand Down
22 changes: 19 additions & 3 deletions apple/internal/watchos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,11 @@ def _watchos_extension_impl(ctx):
],
)
product_type = rule_descriptor.product_type
if ctx.attr.extensionkit_extension:
bundle_location = processor.location.extension
product_type = apple_product_type.extensionkit_extension
else:
bundle_location = processor.location.plugin

# Xcode 11 requires this flag to be passed to the linker, but it is not accepted by earlier
# versions.
Expand All @@ -868,6 +873,9 @@ def _watchos_extension_impl(ctx):
if ctx.attr.application_extension:
extra_linkopts = ["-e", "_NSExtensionMain"]
product_type = apple_product_type.app_extension
elif ctx.attr.extensionkit_extension:
extra_linkopts = ["-e", "_NSExtensionMain"]
product_type = apple_product_type.extensionkit_extension
else:
extra_linkopts = ["-e", "_WKExtensionMain"]

Expand Down Expand Up @@ -913,14 +921,21 @@ def _watchos_extension_impl(ctx):
binary_artifact = link_result.binary
debug_outputs = linking_support.debug_outputs_by_architecture(link_result.outputs)

archive = outputs.archive(
archive_for_embedding = outputs.archive(
actions = actions,
bundle_extension = bundle_extension,
bundle_name = bundle_name,
platform_prerequisites = platform_prerequisites,
predeclared_outputs = predeclared_outputs,
)

if ctx.attr.extensionkit_extension:
plugins = []
extensions = [archive_for_embedding]
else:
plugins = [archive_for_embedding]
extensions = []

bundle_verification_targets = [struct(target = ext) for ext in ctx.attr.extensions]

processor_partials = [
Expand Down Expand Up @@ -965,7 +980,7 @@ def _watchos_extension_impl(ctx):
actions = actions,
apple_mac_toolchain_info = apple_mac_toolchain_info,
bundle_extension = bundle_extension,
bundle_location = processor.location.plugin,
bundle_location = bundle_location,
bundle_name = bundle_name,
embed_target_dossiers = True,
embedded_targets = embeddable_targets,
Expand All @@ -990,7 +1005,8 @@ def _watchos_extension_impl(ctx):
bundle_embedded_bundles = True,
platform_prerequisites = platform_prerequisites,
embeddable_targets = embeddable_targets,
plugins = [archive],
plugins = plugins,
extensions = extensions,
),
partials.extension_safe_validation_partial(
is_extension_safe = True,
Expand Down
8 changes: 5 additions & 3 deletions doc/rules-watchos.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ Builds and bundles a watchOS dynamic framework that is consumable by Xcode.
<pre>
watchos_extension(<a href="#watchos_extension-name">name</a>, <a href="#watchos_extension-additional_linker_inputs">additional_linker_inputs</a>, <a href="#watchos_extension-application_extension">application_extension</a>, <a href="#watchos_extension-bundle_id">bundle_id</a>, <a href="#watchos_extension-bundle_name">bundle_name</a>,
<a href="#watchos_extension-codesign_inputs">codesign_inputs</a>, <a href="#watchos_extension-codesignopts">codesignopts</a>, <a href="#watchos_extension-deps">deps</a>, <a href="#watchos_extension-entitlements">entitlements</a>, <a href="#watchos_extension-entitlements_validation">entitlements_validation</a>,
<a href="#watchos_extension-executable_name">executable_name</a>, <a href="#watchos_extension-exported_symbols_lists">exported_symbols_lists</a>, <a href="#watchos_extension-extensions">extensions</a>, <a href="#watchos_extension-frameworks">frameworks</a>, <a href="#watchos_extension-infoplists">infoplists</a>,
<a href="#watchos_extension-ipa_post_processor">ipa_post_processor</a>, <a href="#watchos_extension-linkopts">linkopts</a>, <a href="#watchos_extension-minimum_deployment_os_version">minimum_deployment_os_version</a>, <a href="#watchos_extension-minimum_os_version">minimum_os_version</a>,
<a href="#watchos_extension-platform_type">platform_type</a>, <a href="#watchos_extension-provisioning_profile">provisioning_profile</a>, <a href="#watchos_extension-resources">resources</a>, <a href="#watchos_extension-stamp">stamp</a>, <a href="#watchos_extension-strings">strings</a>, <a href="#watchos_extension-version">version</a>)
<a href="#watchos_extension-executable_name">executable_name</a>, <a href="#watchos_extension-exported_symbols_lists">exported_symbols_lists</a>, <a href="#watchos_extension-extensionkit_extension">extensionkit_extension</a>, <a href="#watchos_extension-extensions">extensions</a>,
<a href="#watchos_extension-frameworks">frameworks</a>, <a href="#watchos_extension-infoplists">infoplists</a>, <a href="#watchos_extension-ipa_post_processor">ipa_post_processor</a>, <a href="#watchos_extension-linkopts">linkopts</a>, <a href="#watchos_extension-minimum_deployment_os_version">minimum_deployment_os_version</a>,
<a href="#watchos_extension-minimum_os_version">minimum_os_version</a>, <a href="#watchos_extension-platform_type">platform_type</a>, <a href="#watchos_extension-provisioning_profile">provisioning_profile</a>, <a href="#watchos_extension-resources">resources</a>, <a href="#watchos_extension-stamp">stamp</a>, <a href="#watchos_extension-strings">strings</a>,
<a href="#watchos_extension-version">version</a>)
</pre>

Builds and bundles an watchOS Extension.
Expand All @@ -156,6 +157,7 @@ so these bundling rules do not support that version of the platform.
| <a id="watchos_extension-entitlements_validation"></a>entitlements_validation | An [<code>entitlements_validation_mode</code>](/doc/types.md#entitlements-validation-mode) to control the validation of the requested entitlements against the provisioning profile to ensure they are supported. | String | optional | <code>"loose"</code> |
| <a id="watchos_extension-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 <code>bundle_name</code> attribute will be used if it is set; if not, then the name of the target will be used instead. | String | optional | <code>""</code> |
| <a id="watchos_extension-exported_symbols_lists"></a>exported_symbols_lists | A list of targets containing exported symbols lists files for the linker to control symbol resolution.<br><br>Each file is expected to have a list of global symbol names that will remain as global symbols in the compiled binary owned by this framework. All other global symbols will be treated as if they were marked as <code>__private_extern__</code> (aka <code>visibility=hidden</code>) and will not be global in the output file.<br><br>See the man page documentation for <code>ld(1)</code> on macOS for more details. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="watchos_extension-extensionkit_extension"></a>extensionkit_extension | If <code>True</code>, this extension is an ExtensionKit Extension instead of a WatchKit Extension. It links the extension with the application extension point (<code>_NSExtensionMain</code>) instead of the WatchKit extension point (<code>_WKExtensionMain</code>), and has the <code>extensionkit_extension</code> <code>product_type</code> instead of <code>watch2_extension</code>. | Boolean | optional | <code>False</code> |
| <a id="watchos_extension-extensions"></a>extensions | A list of watchOS application extensions to include in the final watch extension bundle. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="watchos_extension-frameworks"></a>frameworks | A list of framework targets (see [<code>watchos_framework</code>](https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-watchos.md#watchos_framework)) that this target depends on. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="watchos_extension-infoplists"></a>infoplists | A list of .plist files that will be merged to form the Info.plist for this target. 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 | |
Expand Down
3 changes: 3 additions & 0 deletions test/starlark_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ load(":watchos_application_swift_tests.bzl", "watchos_application_swift_test_sui
load(":watchos_application_tests.bzl", "watchos_application_test_suite")
load(":watchos_dynamic_framework_tests.bzl", "watchos_dynamic_framework_test_suite")
load(":watchos_extension_tests.bzl", "watchos_extension_test_suite")
load(":watchos_extensionkit_extension_tests.bzl", "watchos_extensionkit_extension_test_suite")
load(":watchos_framework_tests.bzl", "watchos_framework_test_suite")
load(":watchos_static_framework_tests.bzl", "watchos_static_framework_test_suite")
load(":watchos_ui_test_tests.bzl", "watchos_ui_test_test_suite")
Expand Down Expand Up @@ -141,6 +142,8 @@ watchos_dynamic_framework_test_suite(name = "watchos_dynamic_framework")

watchos_extension_test_suite(name = "watchos_extension")

watchos_extensionkit_extension_test_suite(name = "watchos_extensionkit_extension")

watchos_framework_test_suite(name = "watchos_framework")

watchos_static_framework_test_suite(name = "watchos_static_framework")
Expand Down
Loading

0 comments on commit ccc2f24

Please sign in to comment.