Skip to content

Commit 72347ab

Browse files
luispadronjszumski
andauthored
Update swift_import docs and add warning (#1186)
Updates the `swift_import` documentation to provide more information on the `swiftinterface` attribute. This attribute is required when importing pre-built Swift targets across Xcode and/or OS versions. Additionally, adds a warning when `swiftinterface` is used alongside `swiftmodule` as this used to just drop `swiftinterface` silently. We'll make this a failure in a new major version to not break users. Co-authored-by: John Szumski <[email protected]>
1 parent 31d9ee6 commit 72347ab

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

doc/rules.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,21 @@ package.
438438
swift_import(<a href="#swift_import-name">name</a>, <a href="#swift_import-deps">deps</a>, <a href="#swift_import-data">data</a>, <a href="#swift_import-archives">archives</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>)
439439
</pre>
440440

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

444+
To use `swift_import` targets across Xcode versions and/or OS versions, it is required to use `.swiftinterface` files.
445+
These can be produced by the pre-built target if built with:
446+
447+
- `--features=swift.enable_library_evolution`
448+
- `--features=swift.emit_swiftinterface`
449+
450+
If the pre-built target supports `.private.swiftinterface` files, these can be used instead of `.swiftinterface` files
451+
in the `swiftinterface` attribute.
452+
453+
To import pre-built Swift modules that use `@_spi` when using `swiftinterface`,
454+
the `.private.swiftinterface` files are required in order to build any code that uses the API marked with `@_spi`.
455+
444456
**ATTRIBUTES**
445457

446458

@@ -452,7 +464,7 @@ Allows for the use of Swift textual module interfaces and/or precompiled Swift m
452464
| <a id="swift_import-archives"></a>archives | The list of `.a` files provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
453465
| <a id="swift_import-module_name"></a>module_name | The name of the module represented by this target. | String | required | |
454466
| <a id="swift_import-swiftdoc"></a>swiftdoc | The `.swiftdoc` file provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
455-
| <a id="swift_import-swiftinterface"></a>swiftinterface | The `.swiftinterface` file that defines the module interface for this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
467+
| <a id="swift_import-swiftinterface"></a>swiftinterface | The `.swiftinterface` file that defines the module interface for this target. The interface files are ignored if `swiftmodule` is specified. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
456468
| <a id="swift_import-swiftmodule"></a>swiftmodule | The `.swiftmodule` file provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
457469

458470

swift/internal/swift_import.bzl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def _swift_import_impl(ctx):
8888
module_context.swift.swiftmodule,
8989
] + compact([module_context.swift.swiftdoc])
9090
else:
91+
# TODO: make this a failure in version 2.x
92+
if swiftinterface:
93+
print("WARNING: Provided `swiftinterface` attribute will be ignored because `swiftmodule` was provided. This will be an error in a future version of rules_swift.") # buildifier: disable=print
9194
module_context = swift_common.create_module(
9295
name = ctx.attr.module_name,
9396
clang = swift_common.create_clang_module(
@@ -161,6 +164,7 @@ The `.swiftdoc` file provided to Swift targets that depend on this target.
161164
allow_single_file = ["swiftinterface"],
162165
doc = """\
163166
The `.swiftinterface` file that defines the module interface for this target.
167+
The interface files are ignored if `swiftmodule` is specified.
164168
""",
165169
mandatory = False,
166170
),
@@ -181,8 +185,20 @@ toolchain (such as `clang`) will be retrieved.
181185
},
182186
),
183187
doc = """\
184-
Allows for the use of Swift textual module interfaces and/or precompiled Swift modules as dependencies in other
188+
Allows for the use of Swift textual module interfaces or precompiled Swift modules as dependencies in other
185189
`swift_library` and `swift_binary` targets.
190+
191+
To use `swift_import` targets across Xcode versions and/or OS versions, it is required to use `.swiftinterface` files.
192+
These can be produced by the pre-built target if built with:
193+
194+
- `--features=swift.enable_library_evolution`
195+
- `--features=swift.emit_swiftinterface`
196+
197+
If the pre-built target supports `.private.swiftinterface` files, these can be used instead of `.swiftinterface` files
198+
in the `swiftinterface` attribute.
199+
200+
To import pre-built Swift modules that use `@_spi` when using `swiftinterface`,
201+
the `.private.swiftinterface` files are required in order to build any code that uses the API marked with `@_spi`.
186202
""",
187203
fragments = ["cpp"],
188204
implementation = _swift_import_impl,

0 commit comments

Comments
 (0)