Skip to content

Commit

Permalink
Bless SwiftBinaryInfo as a public provider for IDEs and language to…
Browse files Browse the repository at this point in the history
…oling that need to get at the Swift module of a `swift_binary` or `swift_test` target.

PiperOrigin-RevId: 596931309
  • Loading branch information
allevato authored and swiple-rules-gardener committed Jan 9, 2024
1 parent 0206011 commit 33df9a7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
30 changes: 0 additions & 30 deletions swift/internal/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,6 @@ visibility([
"@build_bazel_rules_swift//swift/...",
])

SwiftBinaryInfo = provider(
doc = """
Information about a binary target's module.
`swift_binary` and `swift_compiler_plugin` propagate this provider that wraps
`CcInfo` and `SwiftInfo` providers, instead of propagating them directly, so
that `swift_test` targets can depend on those binaries and test their modules
(similar to what Swift Package Manager allows) without allowing any
`swift_library` to depend on an arbitrary binary.
""",
fields = {
"cc_info": """\
A `CcInfo` provider containing the binary's code compiled as a static library,
which is suitable for linking into a `swift_test` so that unit tests can be
written against it.
Notably, this `CcInfo`'s linking context does *not* contain the linker flags
used to alias the `main` entry point function, because the purpose of this
provider is to allow it to be linked into another binary that would provide its
own entry point instead.
""",
"swift_info": """\
A `SwiftInfo` provider representing the Swift module created by compiling the
target. This is used specifically by `swift_test` to allow test code to depend
on the binary's module without making it possible for arbitrary libraries or
binaries to depend on other binaries.
""",
},
)

SwiftCompilerPluginInfo = provider(
doc = """
Information about compiler plugins (like macros) that is needed by the compiler
Expand Down
34 changes: 34 additions & 0 deletions swift/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,40 @@ users who just load these providers to inspect and/or repropagate them.

visibility("public")

SwiftBinaryInfo = provider(
doc = """
Information about a binary target's module.
`swift_binary` and `swift_compiler_plugin` propagate this provider that wraps
`CcInfo` and `SwiftInfo` providers, instead of propagating them directly, so
that `swift_test` targets can depend on those binaries and test their modules
(similar to what Swift Package Manager allows) without allowing any
`swift_library` to depend on an arbitrary binary.
Aside from these use cases, this provider should only be consumed by clients
like IDEs, debuggers, and other language tooling that need access to the Swift
module produced by compiling a binary target. Other uses are unsupported.
""",
fields = {
"cc_info": """\
A `CcInfo` provider containing the binary's code compiled as a static library,
which is suitable for linking into a `swift_test` so that unit tests can be
written against it.
Notably, this `CcInfo`'s linking context does *not* contain the linker flags
used to alias the `main` entry point function, because the purpose of this
provider is to allow it to be linked into another binary that would provide its
own entry point instead.
""",
"swift_info": """\
A `SwiftInfo` provider representing the Swift module created by compiling the
target. This is used specifically by `swift_test` to allow test code to depend
on the binary's module without making it possible for arbitrary libraries or
binaries to depend on other binaries.
""",
},
)

SwiftFeatureAllowlistInfo = provider(
doc = """\
Describes a set of features and the packages and aspects that are allowed to
Expand Down
3 changes: 1 addition & 2 deletions swift/swift_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ load(
)
load(
"@build_bazel_rules_swift//swift/internal:providers.bzl",
"SwiftBinaryInfo",
"SwiftCompilerPluginInfo",
)
load(
Expand All @@ -48,7 +47,7 @@ load(
"get_providers",
)
load(":module_name.bzl", "derive_swift_module_name")
load(":providers.bzl", "SwiftInfo")
load(":providers.bzl", "SwiftBinaryInfo", "SwiftInfo")

visibility("public")

Expand Down
3 changes: 1 addition & 2 deletions swift/swift_compiler_plugin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ load(
)
load(
"@build_bazel_rules_swift//swift/internal:providers.bzl",
"SwiftBinaryInfo",
"SwiftCompilerPluginInfo",
)
load(
Expand All @@ -48,7 +47,7 @@ load(
"get_providers",
)
load(":module_name.bzl", "derive_swift_module_name")
load(":providers.bzl", "SwiftInfo")
load(":providers.bzl", "SwiftBinaryInfo", "SwiftInfo")

visibility("public")

Expand Down
3 changes: 1 addition & 2 deletions swift/swift_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ load(
)
load(
"@build_bazel_rules_swift//swift/internal:providers.bzl",
"SwiftBinaryInfo",
"SwiftCompilerPluginInfo",
)
load(
Expand All @@ -55,7 +54,7 @@ load(
"get_providers",
)
load(":module_name.bzl", "derive_swift_module_name")
load(":providers.bzl", "SwiftInfo", "SwiftSymbolGraphInfo")
load(":providers.bzl", "SwiftBinaryInfo", "SwiftInfo", "SwiftSymbolGraphInfo")

visibility("public")

Expand Down

1 comment on commit 33df9a7

@brentleyjones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.