Skip to content

Commit

Permalink
Add an API to compile a .swiftinterface file into a .swiftmodule. (
Browse files Browse the repository at this point in the history
…#1085)

(cherry picked from commit 47b4648)
  • Loading branch information
keith authored Aug 11, 2023
1 parent f2d552e commit 9abae7d
Show file tree
Hide file tree
Showing 18 changed files with 703 additions and 23 deletions.
34 changes: 34 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,40 @@ A tuple containing three elements:
will be `None`.


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

## swift_common.compile_module_interface

<pre>
swift_common.compile_module_interface(<a href="#swift_common.compile_module_interface-actions">actions</a>, <a href="#swift_common.compile_module_interface-compilation_contexts">compilation_contexts</a>, <a href="#swift_common.compile_module_interface-feature_configuration">feature_configuration</a>,
<a href="#swift_common.compile_module_interface-module_name">module_name</a>, <a href="#swift_common.compile_module_interface-swiftinterface_file">swiftinterface_file</a>, <a href="#swift_common.compile_module_interface-swift_infos">swift_infos</a>, <a href="#swift_common.compile_module_interface-swift_toolchain">swift_toolchain</a>)
</pre>

Compiles a Swift module interface.

**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="swift_common.compile_module_interface-actions"></a>actions | The context's <code>actions</code> object. | none |
| <a id="swift_common.compile_module_interface-compilation_contexts"></a>compilation_contexts | A list of <code>CcCompilationContext</code>s that represent C/Objective-C requirements of the target being compiled, such as Swift-compatible preprocessor defines, header search paths, and so forth. These are typically retrieved from the <code>CcInfo</code> providers of a target's dependencies. | none |
| <a id="swift_common.compile_module_interface-feature_configuration"></a>feature_configuration | A feature configuration obtained from <code>swift_common.configure_features</code>. | none |
| <a id="swift_common.compile_module_interface-module_name"></a>module_name | The name of the Swift module being compiled. This must be present and valid; use <code>swift_common.derive_module_name</code> to generate a default from the target's label if needed. | none |
| <a id="swift_common.compile_module_interface-swiftinterface_file"></a>swiftinterface_file | The Swift module interface file to compile. | none |
| <a id="swift_common.compile_module_interface-swift_infos"></a>swift_infos | A list of <code>SwiftInfo</code> providers from dependencies of the target being compiled. | none |
| <a id="swift_common.compile_module_interface-swift_toolchain"></a>swift_toolchain | The <code>SwiftToolchainInfo</code> provider of the toolchain. | none |

**RETURNS**

A Swift module context (as returned by `swift_common.create_module`)
that contains the Swift (and potentially C/Objective-C) compilation
prerequisites of the compiled module. This should typically be
propagated by a `SwiftInfo` provider of the calling rule, and the
`CcCompilationContext` inside the Clang module substructure should be
propagated by the `CcInfo` provider of the calling rule.


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

## swift_common.configure_features
Expand Down
9 changes: 5 additions & 4 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ swift_grpc_library(
## swift_import

<pre>
swift_import(<a href="#swift_import-name">name</a>, <a href="#swift_import-archives">archives</a>, <a href="#swift_import-data">data</a>, <a href="#swift_import-deps">deps</a>, <a href="#swift_import-module_name">module_name</a>, <a href="#swift_import-swiftdoc">swiftdoc</a>, <a href="#swift_import-swiftmodule">swiftmodule</a>)
swift_import(<a href="#swift_import-name">name</a>, <a href="#swift_import-archives">archives</a>, <a href="#swift_import-data">data</a>, <a href="#swift_import-deps">deps</a>, <a href="#swift_import-module_name">module_name</a>, <a href="#swift_import-swiftdoc">swiftdoc</a>, <a href="#swift_import-swiftinterface">swiftinterface</a>, <a href="#swift_import-swiftmodule">swiftmodule</a>)
</pre>

Allows for the use of precompiled Swift modules as dependencies in other
Allows for the use of Swift textual module interfaces and/or precompiled Swift modules as dependencies in other
`swift_library` and `swift_binary` targets.


Expand All @@ -255,12 +255,13 @@ Allows for the use of precompiled Swift modules as dependencies in other
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="swift_import-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="swift_import-archives"></a>archives | The list of <code>.a</code> files provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="swift_import-archives"></a>archives | The list of <code>.a</code> files provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="swift_import-data"></a>data | The list of files needed by this target at runtime.<br><br>Files and targets named in the <code>data</code> attribute will appear in the <code>*.runfiles</code> area of this target, if it has one. This may include data files needed by a binary or library, or other programs needed by it. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="swift_import-deps"></a>deps | A list of targets that are dependencies of the target being built, which will be linked into that target.<br><br>If the Swift toolchain supports implementation-only imports (<code>private_deps</code> on <code>swift_library</code>), then targets in <code>deps</code> are treated as regular (non-implementation-only) imports that are propagated both to their direct and indirect (transitive) dependents.<br><br>Allowed kinds of dependencies are:<br><br>* <code>swift_c_module</code>, <code>swift_import</code> and <code>swift_library</code> (or anything propagating <code>SwiftInfo</code>)<br><br>* <code>cc_library</code> (or anything propagating <code>CcInfo</code>)<br><br>Additionally, on platforms that support Objective-C interop, <code>objc_library</code> targets (or anything propagating the <code>apple_common.Objc</code> provider) are allowed as dependencies. On platforms that do not support Objective-C interop (such as Linux), those dependencies will be **ignored.** | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="swift_import-module_name"></a>module_name | The name of the module represented by this target. | String | required | |
| <a id="swift_import-swiftdoc"></a>swiftdoc | The <code>.swiftdoc</code> file provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="swift_import-swiftmodule"></a>swiftmodule | The <code>.swiftmodule</code> file provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="swift_import-swiftinterface"></a>swiftinterface | The <code>.swiftinterface</code> file that defines the module interface for this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="swift_import-swiftmodule"></a>swiftmodule | The <code>.swiftmodule</code> file provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |


<a id="swift_library"></a>
Expand Down
1 change: 1 addition & 0 deletions swift/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bzl_library(
":toolchain_config",
":utils",
":vfsoverlay",
"//swift/toolchains/config:compile_module_interface_config",
"@bazel_skylib//lib:collections",
"@bazel_skylib//lib:partial",
"@bazel_skylib//lib:paths",
Expand Down
3 changes: 3 additions & 0 deletions swift/internal/actions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ swift_action_names = struct(
# object files.
COMPILE = "SwiftCompile",

# Compiles a `.swiftinterface` file into a `.swiftmodule` file.
COMPILE_MODULE_INTERFACE = "SwiftCompileModuleInterface",

# Wraps a `.swiftmodule` in a `.o` file on ELF platforms so that it can be
# linked into a binary for debugging.
MODULEWRAP = "SwiftModuleWrap",
Expand Down
Loading

0 comments on commit 9abae7d

Please sign in to comment.