Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it an error to specify both swiftinterface and swiftmodule in swift_import #1253

Merged
merged 1 commit into from
Jun 21, 2024
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
4 changes: 2 additions & 2 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ the `.private.swiftinterface` files are required in order to build any code that
| <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 | `[]` |
| <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 `.swiftdoc` file provided to Swift targets that depend on this target. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
| <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` |
| <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` |
| <a id="swift_import-swiftinterface"></a>swiftinterface | The `.swiftinterface` file that defines the module interface for this target. May not be specified if `swiftmodule` is specified. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
| <a id="swift_import-swiftmodule"></a>swiftmodule | The `.swiftmodule` file provided to Swift targets that depend on this target. May not be specified if `swiftinterface` is specified. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |


<a id="swift_interop_hint"></a>
Expand Down
14 changes: 8 additions & 6 deletions swift/swift_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def _swift_import_impl(ctx):
)

if not (swiftinterface or swiftmodule):
fail("One or both of 'swiftinterface' and 'swiftmodule' must be " +
fail("One of 'swiftinterface' or 'swiftmodule' must be " +
"specified.")

if swiftinterface and swiftmodule:
fail("'swiftinterface' may not be specified when " +
"'swiftmodule' is specified.")

swift_toolchain = swift_common.get_toolchain(ctx)
feature_configuration = swift_common.configure_features(
ctx = ctx,
Expand Down Expand Up @@ -82,7 +86,7 @@ def _swift_import_impl(ctx):

swift_infos = get_providers(deps, SwiftInfo)

if swiftinterface and not swiftmodule:
if swiftinterface:
module_context = swift_common.compile_module_interface(
actions = ctx.actions,
compilation_contexts = get_compilation_contexts(ctx.attr.deps),
Expand All @@ -97,9 +101,6 @@ def _swift_import_impl(ctx):
module_context.swift.swiftmodule,
] + compact([module_context.swift.swiftdoc])
else:
# TODO: make this a failure in version 2.x
if swiftinterface:
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
brentleyjones marked this conversation as resolved.
Show resolved Hide resolved
module_context = swift_common.create_module(
name = ctx.attr.module_name,
clang = swift_common.create_clang_module(
Expand Down Expand Up @@ -174,14 +175,15 @@ The `.swiftdoc` file provided to Swift targets that depend on this target.
allow_single_file = ["swiftinterface"],
doc = """\
The `.swiftinterface` file that defines the module interface for this target.
The interface files are ignored if `swiftmodule` is specified.
May not be specified if `swiftmodule` is specified.
""",
mandatory = False,
),
"swiftmodule": attr.label(
allow_single_file = ["swiftmodule"],
doc = """\
The `.swiftmodule` file provided to Swift targets that depend on this target.
May not be specified if `swiftinterface` is specified.
""",
mandatory = False,
),
Expand Down