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 ExtensionKit App Extensions with extensionkit_extension = True #1944

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions apple/internal/apple_product_type.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ apple_product_type = struct(
app_extension = "com.apple.product-type.app-extension",
bundle = "com.apple.product-type.bundle",
dylib = "com.apple.product-type.library.dynamic",
extensionkit_extension = "com.apple.product-type.extensionkit-extension",
framework = "com.apple.product-type.framework",
kernel_extension = "com.apple.product-type.kernel-extension",
messages_application = "com.apple.product-type.application.messages",
Expand Down
25 changes: 20 additions & 5 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,20 @@ def _ios_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

entitlements = entitlements_support.process_entitlements(
actions = actions,
apple_mac_toolchain_info = apple_mac_toolchain_info,
bundle_id = bundle_id,
entitlements_file = ctx.file.entitlements,
platform_prerequisites = platform_prerequisites,
product_type = rule_descriptor.product_type,
product_type = product_type,
provisioning_profile = provisioning_profile,
rule_label = label,
validation_mode = ctx.attr.entitlements_validation,
Expand Down Expand Up @@ -990,11 +997,18 @@ def _ios_extension_impl(ctx):
predeclared_outputs = predeclared_outputs,
)

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

processor_partials = [
partials.app_assets_validation_partial(
app_icons = ctx.files.app_icons,
platform_prerequisites = platform_prerequisites,
product_type = rule_descriptor.product_type,
product_type = product_type,
),
partials.apple_bundle_info_partial(
actions = actions,
Expand All @@ -1007,7 +1021,7 @@ def _ios_extension_impl(ctx):
label_name = label.name,
platform_prerequisites = platform_prerequisites,
predeclared_outputs = predeclared_outputs,
product_type = rule_descriptor.product_type,
product_type = product_type,
),
partials.binary_partial(
actions = actions,
Expand All @@ -1028,7 +1042,7 @@ def _ios_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 = False,
embedded_targets = ctx.attr.frameworks,
Expand Down Expand Up @@ -1061,7 +1075,8 @@ def _ios_extension_impl(ctx):
partials.embedded_bundles_partial(
embeddable_targets = ctx.attr.frameworks,
platform_prerequisites = platform_prerequisites,
plugins = [archive_for_embedding],
plugins = plugins,
extensions = extensions,
),
partials.extension_safe_validation_partial(
is_extension_safe = True,
Expand Down
25 changes: 20 additions & 5 deletions apple/internal/macos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,20 @@ def _macos_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

entitlements = entitlements_support.process_entitlements(
actions = actions,
apple_mac_toolchain_info = apple_mac_toolchain_info,
bundle_id = bundle_id,
entitlements_file = ctx.file.entitlements,
platform_prerequisites = platform_prerequisites,
product_type = rule_descriptor.product_type,
product_type = product_type,
provisioning_profile = provisioning_profile,
rule_label = label,
validation_mode = ctx.attr.entitlements_validation,
Expand All @@ -583,14 +590,21 @@ def _macos_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_name = bundle_name,
bundle_extension = bundle_extension,
platform_prerequisites = platform_prerequisites,
predeclared_outputs = predeclared_outputs,
)

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

processor_partials = [
partials.apple_bundle_info_partial(
actions = actions,
Expand All @@ -603,7 +617,7 @@ def _macos_extension_impl(ctx):
label_name = label.name,
platform_prerequisites = platform_prerequisites,
predeclared_outputs = predeclared_outputs,
product_type = rule_descriptor.product_type,
product_type = product_type,
),
partials.binary_partial(
actions = actions,
Expand All @@ -625,7 +639,7 @@ def _macos_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 = False,
entitlements = entitlements.codesigning,
Expand All @@ -647,7 +661,8 @@ def _macos_extension_impl(ctx):
),
partials.embedded_bundles_partial(
platform_prerequisites = platform_prerequisites,
plugins = [archive],
plugins = plugins,
extensions = extensions,
),
partials.macos_additional_contents_partial(
additional_contents = ctx.attr.additional_contents,
Expand Down
2 changes: 2 additions & 0 deletions apple/internal/partials/codesigning_dossier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Depset of structs with codesigning dossier information to be embedded in another

_VALID_LOCATIONS = sets.make([
processor.location.app_clip,
processor.location.extension,
processor.location.framework,
processor.location.plugin,
processor.location.watch,
Expand Down Expand Up @@ -77,6 +78,7 @@ def _location_map(rule_descriptor):
resolved = rule_descriptor.bundle_locations
return {
processor.location.app_clip: resolved.contents_relative_app_clips,
processor.location.extension: resolved.contents_relative_extensions,
processor.location.framework: resolved.contents_relative_frameworks,
processor.location.plugin: resolved.contents_relative_plugins,
processor.location.watch: resolved.contents_relative_watch,
Expand Down
5 changes: 5 additions & 0 deletions apple/internal/partials/embedded_bundles.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _embedded_bundles_partial_impl(
# Map of embedded bundle type to their final location in the top-level bundle.
bundle_type_to_location = {
"app_clips": processor.location.app_clip,
"extensions": processor.location.extension,
"frameworks": processor.location.framework,
"plugins": processor.location.plugin,
"watch_bundles": processor.location.watch,
Expand Down Expand Up @@ -145,6 +146,7 @@ def embedded_bundles_partial(
app_clips = [],
bundle_embedded_bundles = False,
embeddable_targets = [],
extensions = [],
frameworks = [],
platform_prerequisites,
plugins = [],
Expand All @@ -166,6 +168,8 @@ def embedded_bundles_partial(
embeddable bundles will be propagated downstream for a top level target to bundle them.
embeddable_targets: The list of targets that propagate embeddable bundles to bundle or
propagate.
extensions: List of extension bundles that should be propagated downstream for a top level
target to bundle inside `Extensions`.
frameworks: List of framework bundles that should be propagated downstream for a top level
target to bundle inside `Frameworks`.
platform_prerequisites: Struct containing information on the platform being targeted.
Expand All @@ -186,6 +190,7 @@ def embedded_bundles_partial(
app_clips = app_clips,
bundle_embedded_bundles = bundle_embedded_bundles,
embeddable_targets = embeddable_targets,
extensions = extensions,
frameworks = frameworks,
platform_prerequisites = platform_prerequisites,
plugins = plugins,
Expand Down
6 changes: 6 additions & 0 deletions apple/internal/processor.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Location types can be:
- binary: Files are to be placed in the binary section of the bundle.
- bundle: Files are to be placed at the root of the bundle.
- content: Files are to be placed in the contents section of the bundle.
- extension: Files are to be placed in the Extensions section of the bundle.
- framework: Files are to be placed in the Frameworks section of the bundle.
- plugin: Files are to be placed in the PlugIns section of the bundle.
- resources: Files are to be placed in the resources section of the bundle.
Expand Down Expand Up @@ -107,6 +108,7 @@ _LOCATION_ENUM = struct(
binary = "binary",
bundle = "bundle",
content = "content",
extension = "extension",
framework = "framework",
plugin = "plugin",
resource = "resource",
Expand Down Expand Up @@ -195,6 +197,10 @@ def _archive_paths(
),
_LOCATION_ENUM.bundle: bundle_path,
_LOCATION_ENUM.content: contents_path,
_LOCATION_ENUM.extension: paths.join(
contents_path,
rule_descriptor.bundle_locations.contents_relative_extensions,
),
_LOCATION_ENUM.framework: paths.join(
contents_path,
rule_descriptor.bundle_locations.contents_relative_frameworks,
Expand Down
3 changes: 3 additions & 0 deletions apple/internal/providers/embeddable_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ _APPLE_EMBEDDABLE_INFO_FIELDS = {
"app_clips": """
A depset with the zipped archives of bundles that need to be expanded into the
AppClips section of the packaging bundle.""",
"extensions": """
A depset with the zipped archives of bundles that need to be expanded into the
Extensions section of the packaging bundle.""",
"frameworks": """
A depset with the zipped archives of bundles that need to be expanded into the
Frameworks section of the packaging bundle.""",
Expand Down
40 changes: 40 additions & 0 deletions apple/internal/rule_factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,16 @@ Info.plist under the key `UILaunchStoryboardName`.
default = Label("@build_bazel_rules_apple//apple/internal/templates:ios_sim_template"),
),
})
elif rule_descriptor.product_type == apple_product_type.app_extension:
attrs.append({
"extensionkit_extension": attr.bool(
default = False,
doc = """
If `True`, this extension is an ExtensionKit Extension instead of an App Extension.
The bundle is installed into the Extensions directory instead of PlugIns.
""",
),
})
elif _is_test_product_type(rule_descriptor.product_type):
required_providers = [
[AppleBundleInfo, IosApplicationBundleInfo],
Expand Down Expand Up @@ -833,6 +843,17 @@ set, then the default extension is determined by the application's product_type.
),
})

elif rule_descriptor.product_type == apple_product_type.app_extension:
attrs.append({
"extensionkit_extension": attr.bool(
default = False,
doc = """
If `True`, this extension is an ExtensionKit Extension instead of an App Extension.
The bundle is installed into the Extensions directory instead of PlugIns.
""",
),
})

elif _is_test_product_type(rule_descriptor.product_type):
test_host_mandatory = rule_descriptor.product_type == apple_product_type.ui_test_bundle
attrs.append({
Expand Down Expand Up @@ -873,6 +894,16 @@ def _get_tvos_attrs(rule_descriptor):
default = Label("@build_bazel_rules_apple//apple/internal/templates:ios_sim_template"),
),
})
elif rule_descriptor.product_type == apple_product_type.app_extension:
attrs.append({
"extensionkit_extension": attr.bool(
default = False,
doc = """
If `True`, this extension is an ExtensionKit Extension instead of an App Extension.
The bundle is installed into the Extensions directory instead of PlugIns.
""",
),
})
elif rule_descriptor.product_type == apple_product_type.framework:
attrs.append({
# TODO(kaipi): This attribute is not publicly documented, but it is tested in
Expand Down Expand Up @@ -993,6 +1024,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
2 changes: 2 additions & 0 deletions apple/internal/rule_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _describe_bundle_locations(
bundle_relative_contents = "",
contents_relative_app_clips = "AppClips",
contents_relative_binary = "",
contents_relative_extensions = "Extensions",
contents_relative_frameworks = "Frameworks",
contents_relative_plugins = "PlugIns",
contents_relative_resources = "",
Expand All @@ -59,6 +60,7 @@ def _describe_bundle_locations(
bundle_relative_contents = bundle_relative_contents,
contents_relative_app_clips = contents_relative_app_clips,
contents_relative_binary = contents_relative_binary,
contents_relative_extensions = contents_relative_extensions,
contents_relative_frameworks = contents_relative_frameworks,
contents_relative_plugins = contents_relative_plugins,
contents_relative_resources = contents_relative_resources,
Expand Down
25 changes: 20 additions & 5 deletions apple/internal/tvos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,20 @@ def _tvos_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

entitlements = entitlements_support.process_entitlements(
actions = actions,
apple_mac_toolchain_info = apple_mac_toolchain_info,
bundle_id = bundle_id,
entitlements_file = ctx.file.entitlements,
platform_prerequisites = platform_prerequisites,
product_type = rule_descriptor.product_type,
product_type = product_type,
provisioning_profile = provisioning_profile,
rule_label = label,
validation_mode = ctx.attr.entitlements_validation,
Expand All @@ -922,14 +929,21 @@ def _tvos_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 = []

processor_partials = [
partials.apple_bundle_info_partial(
actions = actions,
Expand All @@ -942,7 +956,7 @@ def _tvos_extension_impl(ctx):
label_name = label.name,
platform_prerequisites = platform_prerequisites,
predeclared_outputs = predeclared_outputs,
product_type = rule_descriptor.product_type,
product_type = product_type,
),
partials.binary_partial(
actions = actions,
Expand Down Expand Up @@ -972,7 +986,7 @@ def _tvos_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 = False,
embedded_targets = ctx.attr.frameworks,
Expand All @@ -996,7 +1010,8 @@ def _tvos_extension_impl(ctx):
partials.embedded_bundles_partial(
embeddable_targets = ctx.attr.frameworks,
platform_prerequisites = platform_prerequisites,
plugins = [archive],
plugins = plugins,
extensions = extensions,
),
partials.extension_safe_validation_partial(
is_extension_safe = True,
Expand Down
Loading