Skip to content
Merged
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
30 changes: 30 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,36 @@ A `SwiftToolchainInfo` provider, or `None` if the toolchain was not
found and not required.


<a id="swift_common.is_action_enabled"></a>

## swift_common.is_action_enabled

<pre>
swift_common.is_action_enabled(<a href="#swift_common.is_action_enabled-action_name">action_name</a>, <a href="#swift_common.is_action_enabled-swift_toolchain">swift_toolchain</a>)
</pre>

Returns True if the given action is enabled in the Swift toolchain.

This function should be used before invoking APIs that invoke actions that
might not be available depending on the version of the Swift toolchain. For
example, `SwiftSynthesizeInterface` actions (created by calling
`swift_common.synthesize_interface`) are only available starting from Swift
6.1.


**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="swift_common.is_action_enabled-action_name"></a>action_name | The name of the action, which corresponds to the action's mnemonic (for example, `SwiftSynthesizeInterface`). | none |
| <a id="swift_common.is_action_enabled-swift_toolchain"></a>swift_toolchain | The Swift toolchain being used to build. | none |

**RETURNS**

True if the action is enabled, or False if it is not.


<a id="swift_common.is_enabled"></a>

## swift_common.is_enabled
Expand Down
1 change: 1 addition & 0 deletions swift/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bzl_library(
name = "swift_common",
srcs = ["swift_common.bzl"],
deps = [
"//swift/internal:actions",
"//swift/internal:compiling",
"//swift/internal:features",
"//swift/internal:interface_synthesizing",
Expand Down
9 changes: 8 additions & 1 deletion swift/internal/actions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ def _apply_action_configs(
def is_action_enabled(action_name, swift_toolchain):
"""Returns True if the given action is enabled in the Swift toolchain.

This function should be used before invoking APIs that invoke actions that
might not be available depending on the version of the Swift toolchain. For
example, `SwiftSynthesizeInterface` actions (created by calling
`swift_common.synthesize_interface`) are only available starting from Swift
6.1.

Args:
action_name: The name of the action.
action_name: The name of the action, which corresponds to the action's
mnemonic (for example, `SwiftSynthesizeInterface`).
swift_toolchain: The Swift toolchain being used to build.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion swift/internal/toolchain_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_swift_toolchain(
if group and toolchain_type in group.toolchains:
return group.toolchains[toolchain_type].swift_toolchain

if toolchain_type in ctx.toolchains:
if toolchain_type in ctx.toolchains and ctx.toolchains[toolchain_type]:
return ctx.toolchains[toolchain_type].swift_toolchain

# TODO(b/205018581): Delete this code path when migration to the new
Expand Down
12 changes: 12 additions & 0 deletions swift/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ def _swift_info_init(
direct_swift_infos = [],
modules = [],
swift_infos = []):
"""Creates a `SwiftInfo` provider from the given arguments.

Args:
direct_swift_infos: A list of `SwiftInfo` providers from dependencies
whose direct modules should be treated as direct modules in the resulting
provider, in addition to their transitive modules being merged.
modules: A list of values (as returned by `create_swift_module_context()`)
that represent Clang and/or Swift module artifacts that are direct outputs
of the target being built.
swift_infos: A list of `SwiftInfo` providers from dependencies whose
transitive modules should be merged into the resulting provider.
"""
direct_modules = modules + [
module
for provider in direct_swift_infos
Expand Down
5 changes: 5 additions & 0 deletions swift/swift_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ example, `swift_proto_library` generates Swift source code from `.proto` files
and then needs to compile them. This module provides that lower-level interface.
"""

load(
"//swift/internal:actions.bzl",
"is_action_enabled",
)
load(
"//swift/internal:compiling.bzl",
"compile",
Expand Down Expand Up @@ -62,6 +66,7 @@ swift_common = struct(
create_linking_context_from_compilation_outputs = create_linking_context_from_compilation_outputs,
extract_symbol_graph = extract_symbol_graph,
get_toolchain = get_swift_toolchain,
is_action_enabled = is_action_enabled,
is_enabled = is_feature_enabled,
precompile_clang_module = precompile_clang_module,
synthesize_interface = synthesize_interface,
Expand Down