Skip to content
Closed
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
10 changes: 10 additions & 0 deletions swift/internal/api.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def _compile(
copts = [],
defines = [],
deps = [],
generated_header_name = None,
genfiles_dir = None):
"""Compiles a Swift module.

Expand Down Expand Up @@ -530,6 +531,8 @@ def _compile(
deps: Dependencies of the target being compiled. These targets must
propagate one of the following providers: `CcInfo`, `SwiftInfo`, or
`apple_common.Objc`.
generated_header_name: The name of the generated Objective-C interface header.
If not provided, it defaults to `${target_name}-Swift.h`.
genfiles_dir: The Bazel `*-genfiles` directory root. If provided, its
path is added to ClangImporter's header search paths for
compatibility with Bazel's C++ and Objective-C rules which support
Expand Down Expand Up @@ -705,6 +708,7 @@ def _compile(
generated_header = derived_files.objc_header(
actions = actions,
target_name = target_name,
header_name = generated_header_name,
)
args.add("-emit-objc-header-path")
args.add(generated_header)
Expand Down Expand Up @@ -1035,6 +1039,12 @@ explicitly called by code in the binary; for example, if you rely on runtime
checks for protocol conformances added in extensions in the library but do not
directly reference any other symbols in the object file that adds that
conformance.
""",
),
"generated_header_name": attr.string(
doc = """\
The name of the generated Objective-C interface header.
If not provided, it defaults to `${target_name}-Swift.h`.
""",
),
},
Expand Down
15 changes: 13 additions & 2 deletions swift/internal/derived_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,28 @@ def _modulewrap_object(actions, target_name):
"""
return actions.declare_file("{}.modulewrap.o".format(target_name))

def _objc_header(actions, target_name):
def _objc_header(actions, target_name, header_name = None):
"""Declares the generated header file exposing Swift APIs to Objective-C.

Args:
actions: The context's actions object.
target_name: The name of the target being built.
header_name: The name of the header being declared.

Returns:
The declared `File`.
"""
return actions.declare_file("{}-Swift.h".format(target_name))
if header_name:
if not header_name.endswith(".h"):
fail(("The generated objc header name for {} must end in" +

This comment was marked as resolved.

" '.h', given '{}'") % (target_name, header_name))
if "/" in header_name:
fail(("The generated objc header name for {} cannot contain a " +

This comment was marked as resolved.

"'/', given '{}'") % (target_name, header_name))
else:
header_name = "{}-Swift.h".format(target_name)

return actions.declare_file(header_name)

def _partial_swiftmodule(actions, target_name, src):
"""Declares a file for a partial Swift module created during compilation.
Expand Down
1 change: 1 addition & 0 deletions swift/internal/swift_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def _swift_library_impl(ctx):
defines = ctx.attr.defines,
deps = deps + private_deps,
feature_configuration = feature_configuration,
generated_header_name = ctx.attr.generated_header_name,
genfiles_dir = ctx.genfiles_dir,
module_name = module_name,
srcs = srcs,
Expand Down