diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 780414cba8..00bb73b964 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -311,6 +311,7 @@ def _ios_static_framework_impl(ctx): partials.binary_partial(binary_artifact = binary_artifact), partials.static_framework_header_modulemap_partial( hdrs = ctx.files.hdrs, + umbrella_header = ctx.file.umbrella_header, binary_objc_provider = binary_target[apple_common.Objc], ), ] diff --git a/apple/internal/partials/static_framework_header_modulemap.bzl b/apple/internal/partials/static_framework_header_modulemap.bzl index 40eab75e6b..e082b20935 100644 --- a/apple/internal/partials/static_framework_header_modulemap.bzl +++ b/apple/internal/partials/static_framework_header_modulemap.bzl @@ -115,14 +115,19 @@ def _create_umbrella_header(actions, output, headers): content = "\n".join(import_lines) + "\n" actions.write(output = output, content = content) -def _static_framework_header_modulemap_partial_impl(ctx, hdrs, binary_objc_provider): +def _static_framework_header_modulemap_partial_impl(ctx, hdrs, umbrella_header, binary_objc_provider): """Implementation for the static framework headers and modulemaps partial.""" bundle_name = bundling_support.bundle_name(ctx) bundle_files = [] umbrella_header_name = None - if hdrs: + if umbrella_header: + umbrella_header_name = umbrella_header.basename + bundle_files.append( + (processor.location.bundle, "Headers", depset(hdrs + [umbrella_header])), + ) + elif hdrs: umbrella_header_name = "{}.h".format(bundle_name) umbrella_header_file = intermediates.file(ctx.actions, ctx.label.name, umbrella_header_name) _create_umbrella_header( @@ -165,13 +170,14 @@ def _static_framework_header_modulemap_partial_impl(ctx, hdrs, binary_objc_provi bundle_files = bundle_files, ) -def static_framework_header_modulemap_partial(hdrs, binary_objc_provider): +def static_framework_header_modulemap_partial(hdrs, umbrella_header, binary_objc_provider): """Constructor for the static framework headers and modulemaps partial. This partial bundles the headers and modulemaps for static frameworks. Args: hdrs: The list of headers to bundle. + umbrella_header: An umbrella header to use instead of generating one binary_objc_provider: The ObjC provider for the binary target. Returns: @@ -181,5 +187,6 @@ def static_framework_header_modulemap_partial(hdrs, binary_objc_provider): return partial.make( _static_framework_header_modulemap_partial_impl, hdrs = hdrs, + umbrella_header = umbrella_header, binary_objc_provider = binary_objc_provider, ) diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl index 5a2587d249..0dad31ffe4 100644 --- a/apple/internal/rule_factory.bzl +++ b/apple/internal/rule_factory.bzl @@ -525,6 +525,15 @@ use only extension-safe APIs. A list of `.h` files that will be publicly exposed by this framework. These headers should have framework-relative imports, and if non-empty, an umbrella header named `%{bundle_name}.h` will also be generated that imports all of the headers listed here. +""", + ), + "umbrella_header": attr.label( + allow_single_file = [".h"], + doc = """ +A 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 +format. If this attribute is not specified, an umbrella header will be generated under the same name as this +target. """, ), "avoid_deps": attr.label_list(