Skip to content

Commit

Permalink
Add SwiftGRPCInfo provider (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaTheFun committed Oct 19, 2023
1 parent 2c7390d commit 4217d3f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _DOC_SRCS = {
"swift_usage_aspect",
],
"providers": [
"SwiftGRPCInfo",
"SwiftInfo",
"SwiftToolchainInfo",
"SwiftProtoInfo",
Expand Down
23 changes: 22 additions & 1 deletion doc/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,31 @@ with the Swift build rules as needed.

On this page:

* [SwiftGRPCInfo](#SwiftGRPCInfo)
* [SwiftInfo](#SwiftInfo)
* [SwiftToolchainInfo](#SwiftToolchainInfo)
* [SwiftProtoInfo](#SwiftProtoInfo)
* [SwiftUsageInfo](#SwiftUsageInfo)

<a id="SwiftGRPCInfo"></a>

## SwiftGRPCInfo

<pre>
SwiftGRPCInfo(<a href="#SwiftGRPCInfo-flavor">flavor</a>, <a href="#SwiftGRPCInfo-direct_pbgrpc_files">direct_pbgrpc_files</a>)
</pre>

Propagates Swift-specific information about a `swift_grpc_library`.

**FIELDS**


| Name | Description |
| :------------- | :------------- |
| <a id="SwiftGRPCInfo-flavor"></a>flavor | The flavor of GRPC that was generated. E.g. server, client, or client_stubs. |
| <a id="SwiftGRPCInfo-direct_pbgrpc_files"></a>direct_pbgrpc_files | `Depset` of `File`s. The Swift source files (`.grpc.swift`) generated from the `.proto` files in direct dependencies. |


<a id="SwiftInfo"></a>

## SwiftInfo
Expand Down Expand Up @@ -41,7 +61,7 @@ has reasonable defaults for any fields not explicitly set.
## SwiftProtoInfo

<pre>
SwiftProtoInfo(<a href="#SwiftProtoInfo-module_mappings">module_mappings</a>, <a href="#SwiftProtoInfo-pbswift_files">pbswift_files</a>)
SwiftProtoInfo(<a href="#SwiftProtoInfo-module_mappings">module_mappings</a>, <a href="#SwiftProtoInfo-pbswift_files">pbswift_files</a>, <a href="#SwiftProtoInfo-direct_pbswift_files">direct_pbswift_files</a>)
</pre>

Propagates Swift-specific information about a `proto_library`.
Expand All @@ -53,6 +73,7 @@ Propagates Swift-specific information about a `proto_library`.
| :------------- | :------------- |
| <a id="SwiftProtoInfo-module_mappings"></a>module_mappings | `Sequence` of `struct`s. Each struct contains `module_name` and `proto_file_paths` fields that denote the transitive mappings from `.proto` files to Swift modules. This allows messages that reference messages in other libraries to import those modules in generated code. |
| <a id="SwiftProtoInfo-pbswift_files"></a>pbswift_files | `Depset` of `File`s. The transitive Swift source files (`.pb.swift`) generated from the `.proto` files. |
| <a id="SwiftProtoInfo-direct_pbswift_files"></a>direct_pbswift_files | `list` of `File`s. The Swift source files (`.pb.swift`) generated from the `.proto` files in direct dependencies. |


<a id="SwiftToolchainInfo"></a>
Expand Down
17 changes: 17 additions & 0 deletions swift/internal/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ the allowlist.
},
)

SwiftGRPCInfo = provider(
doc = "Propagates Swift-specific information about a `swift_grpc_library`.",
fields = {
"flavor": """\
The flavor of GRPC that was generated. E.g. server, client, or client_stubs.
""",
"direct_pbgrpc_files": """\
`Depset` of `File`s. The Swift source files (`.grpc.swift`) generated
from the `.proto` files in direct dependencies.
""",
},
)

SwiftInfo = provider(
doc = """\
Contains information about the compiled artifacts of a Swift module.
Expand Down Expand Up @@ -120,6 +133,10 @@ libraries to import those modules in generated code.
"pbswift_files": """\
`Depset` of `File`s. The transitive Swift source files (`.pb.swift`) generated
from the `.proto` files.
""",
"direct_pbswift_files": """\
`list` of `File`s. The Swift source files (`.pb.swift`) generated
from the `.proto` files in direct dependencies.
""",
},
)
Expand Down
12 changes: 11 additions & 1 deletion swift/internal/swift_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ load(
"proto_import_path",
"register_module_mapping_write_action",
)
load(":providers.bzl", "SwiftInfo", "SwiftProtoInfo", "SwiftToolchainInfo")
load(
":providers.bzl",
"SwiftGRPCInfo",
"SwiftInfo",
"SwiftProtoInfo",
"SwiftToolchainInfo",
)
load(":swift_common.bzl", "swift_common")
load(":transitions.bzl", "proto_compiler_transition")
load(":utils.bzl", "compact", "get_providers")
Expand Down Expand Up @@ -334,6 +340,10 @@ def _swift_grpc_library_impl(ctx):
linking_context = linking_context,
),
deps[0][SwiftProtoInfo],
SwiftGRPCInfo(
flavor = ctx.attr.flavor,
direct_pbgrpc_files = generated_files,
),
swift_common.create_swift_info(
modules = [module_context],
swift_infos = get_providers(compile_deps, SwiftInfo),
Expand Down
1 change: 1 addition & 0 deletions swift/internal/swift_protoc_gen_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def _build_swift_proto_info_provider(
An instance of `SwiftProtoInfo`.
"""
return SwiftProtoInfo(
direct_pbswift_files = pbswift_files,
module_mappings = transitive_module_mappings,
pbswift_files = depset(
direct = pbswift_files,
Expand Down
2 changes: 2 additions & 0 deletions swift/swift.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")

load(
"@build_bazel_rules_swift//swift/internal:providers.bzl",
_SwiftGRPCInfo = "SwiftGRPCInfo",
_SwiftInfo = "SwiftInfo",
_SwiftProtoInfo = "SwiftProtoInfo",
_SwiftToolchainInfo = "SwiftToolchainInfo",
Expand Down Expand Up @@ -90,6 +91,7 @@ load(
)

# Re-export providers.
SwiftGRPCInfo = _SwiftGRPCInfo
SwiftInfo = _SwiftInfo
SwiftProtoInfo = _SwiftProtoInfo
SwiftToolchainInfo = _SwiftToolchainInfo
Expand Down

0 comments on commit 4217d3f

Please sign in to comment.