Skip to content

Commit

Permalink
Delete deprecated swift proto library rules (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaTheFun authored Apr 18, 2024
1 parent eaa3551 commit 1aec64c
Show file tree
Hide file tree
Showing 25 changed files with 1 addition and 2,421 deletions.
1 change: 0 additions & 1 deletion doc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ _DOC_SRCS = {
"SwiftProtoCompilerInfo",
"SwiftProtoInfo",
"SwiftUsageInfo",
"DeprecatedSwiftGRPCInfo",
],
"rules": [
"swift_binary",
Expand Down
6 changes: 0 additions & 6 deletions doc/doc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ load(
load(
"//swift:swift.bzl",
# providers
_DeprecatedSwiftGRPCInfo = "SwiftGRPCInfo",
_SwiftInfo = "SwiftInfo",
_SwiftToolchainInfo = "SwiftToolchainInfo",
_SwiftUsageInfo = "SwiftUsageInfo",
# rules
_deprecated_swift_grpc_library = "deprecated_swift_grpc_library",
_deprecated_swift_proto_library = "deprecated_swift_proto_library",
_swift_binary = "swift_binary",
# api
_swift_common = "swift_common",
Expand Down Expand Up @@ -83,12 +80,9 @@ swift_proto_library_group = _swift_proto_library_group
# swift symbols
swift_common = _swift_common
swift_usage_aspect = _swift_usage_aspect
DeprecatedSwiftGRPCInfo = _DeprecatedSwiftGRPCInfo
SwiftInfo = _SwiftInfo
SwiftToolchainInfo = _SwiftToolchainInfo
SwiftUsageInfo = _SwiftUsageInfo
deprecated_swift_grpc_library = _deprecated_swift_grpc_library
deprecated_swift_proto_library = _deprecated_swift_proto_library
swift_binary = _swift_binary
swift_compiler_plugin = _swift_compiler_plugin
universal_swift_compiler_plugin = _universal_swift_compiler_plugin
Expand Down
20 changes: 0 additions & 20 deletions doc/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ On this page:
* [SwiftProtoCompilerInfo](#SwiftProtoCompilerInfo)
* [SwiftProtoInfo](#SwiftProtoInfo)
* [SwiftUsageInfo](#SwiftUsageInfo)
* [DeprecatedSwiftGRPCInfo](#DeprecatedSwiftGRPCInfo)

<a id="DeprecatedSwiftGRPCInfo"></a>

## DeprecatedSwiftGRPCInfo

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

DEPRECATED -- Propagates Swift-specific information about a `swift_grpc_library`.

**FIELDS**


| Name | Description |
| :------------- | :------------- |
| <a id="DeprecatedSwiftGRPCInfo-flavor"></a>flavor | The flavor of GRPC that was generated. E.g. server, client, or client_stubs. |
| <a id="DeprecatedSwiftGRPCInfo-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>

Expand Down
184 changes: 0 additions & 184 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,190 +36,6 @@ On this page:
* [deprecated_swift_grpc_library](#deprecated_swift_grpc_library)
* [deprecated_swift_proto_library](#deprecated_swift_proto_library)

<a id="deprecated_swift_grpc_library"></a>

## deprecated_swift_grpc_library

<pre>
deprecated_swift_grpc_library(<a href="#deprecated_swift_grpc_library-name">name</a>, <a href="#deprecated_swift_grpc_library-deps">deps</a>, <a href="#deprecated_swift_grpc_library-srcs">srcs</a>, <a href="#deprecated_swift_grpc_library-flavor">flavor</a>)
</pre>

DEPRECATED -- Please use the swift_proto_library rule defined in //proto:proto.bzl instead.
This rule will be removed in the next rules_swift major version update.
If you're already using this rule, see [the proto migration doc](proto_migration.md) for infomation on how to migrate.

Generates a Swift library from gRPC services defined in protocol buffer sources.

There should be one `swift_grpc_library` for any `proto_library` that defines
services. A target based on this rule can be used as a dependency anywhere that
a `swift_library` can be used.

We recommend that `swift_grpc_library` targets be located in the same package as
the `proto_library` and `swift_proto_library` targets they depend on. For more
best practices around the use of Swift protocol buffer build rules, see the
documentation for `swift_proto_library`.

#### Defining Build Targets for Services

Note that `swift_grpc_library` only generates the gRPC service interfaces (the
`service` definitions) from the `.proto` files. Any messages defined in the same
`.proto` file must be generated using a `swift_proto_library` target. Thus, the
typical structure of a Swift gRPC library is similar to the following:

```python
proto_library(
name = "my_protos",
srcs = ["my_protos.proto"],
)

# Generate Swift types from the protos.
swift_proto_library(
name = "my_protos_swift",
deps = [":my_protos"],
)

# Generate Swift types from the services.
swift_grpc_library(
name = "my_protos_client_services_swift",

# The `srcs` attribute points to the `proto_library` containing the service
# definitions...
srcs = [":my_protos"],

# ...the `flavor` attribute specifies the kind of definitions to generate...
flavor = "client",

# ...and the `deps` attribute points to the `swift_proto_library` that was
# generated from the same `proto_library` and which contains the messages
# used by those services.
deps = [":my_protos_swift"],
)

# Generate test stubs from swift services.
swift_grpc_library(
name = "my_protos_client_stubs_swift",

# The `srcs` attribute points to the `proto_library` containing the service
# definitions...
srcs = [":my_protos"],

# ...the `flavor` attribute specifies the kind of definitions to generate...
flavor = "client_stubs",

# ...and the `deps` attribute points to the `swift_grpc_library` that was
# generated from the same `proto_library` and which contains the service
# implementation.
deps = [":my_protos_client_services_swift"],
)
```

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="deprecated_swift_grpc_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="deprecated_swift_grpc_library-deps"></a>deps | Exactly one `swift_proto_library` or `swift_grpc_library` target that contains the Swift protos used by the services being generated. Test stubs should depend on the `swift_grpc_library` implementing the service. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="deprecated_swift_grpc_library-srcs"></a>srcs | Exactly one `proto_library` target that defines the services being generated. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="deprecated_swift_grpc_library-flavor"></a>flavor | The kind of definitions that should be generated:<br><br>* `"client"` to generate client definitions.<br><br>* `"client_stubs"` to generate client test stubs.<br><br>* `"server"` to generate server definitions. | String | required | |


<a id="deprecated_swift_proto_library"></a>

## deprecated_swift_proto_library

<pre>
deprecated_swift_proto_library(<a href="#deprecated_swift_proto_library-name">name</a>, <a href="#deprecated_swift_proto_library-deps">deps</a>)
</pre>

DEPRECATED -- Please use the swift_proto_library rule defined in //proto:proto.bzl instead.
This rule will be removed in the next rules_swift major version update.
If you're already using this rule, see [the proto migration doc](proto_migration.md) for infomation on how to migrate.

Generates a Swift library from protocol buffer sources.

There should be one `swift_proto_library` for any `proto_library` that you wish
to depend on. A target based on this rule can be used as a dependency anywhere
that a `swift_library` can be used.

A `swift_proto_library` target only creates a Swift module if the
`proto_library` on which it depends has a non-empty `srcs` attribute. If the
`proto_library` does not contain `srcs`, then no module is produced, but the
`swift_proto_library` still propagates the modules of its non-empty dependencies
so that those generated protos can be used by depending on the
`swift_proto_library` of the "collector" target.

Note that the module name of the Swift library produced by this rule (if any) is
based on the name of the `proto_library` target, *not* the name of the
`swift_proto_library` target. In other words, if the following BUILD file were
located in `//my/pkg`, the target would create a Swift module named
`my_pkg_foo`:

```python
proto_library(
name = "foo",
srcs = ["foo.proto"],
)

swift_proto_library(
name = "foo_swift",
deps = [":foo"],
)
```

Because the Swift modules are generated from an aspect that is applied to the
`proto_library` targets, the module name and other compilation flags for the
resulting Swift modules cannot be changed.

#### Tip: Where to locate `swift_proto_library` targets

Convention is to put the `swift_proto_library` in the same `BUILD` file as the
`proto_library` it is generating for (just like all the other
`LANG_proto_library` rules). This lets anyone needing the protos in Swift share
the single rule as well as making it easier to realize what proto files are in
use in what contexts.

This is not a requirement, however, as it may not be possible for Bazel
workspaces that create `swift_proto_library` targets that depend on
`proto_library` targets from different repositories.

#### Tip: Avoid `import` only `.proto` files

Avoid creating a `.proto` file that just contains `import` directives of all the
other `.proto` files you need. While this does _group_ the protos into this new
target, it comes with some high costs. This causes the proto compiler to parse
all those files and invoke the generator for an otherwise empty source file.
That empty source file then has to get compiled, but it will have dependencies
on the full deps chain of the imports (recursively). The Swift compiler must
load all of these module dependencies, which can be fairly slow if there are
many of them, so this method of grouping via a `.proto` file actually ends up
creating build steps that slow down the build.

#### Tip: Resolving unused import warnings

If you see warnings like the following during your build:

```
path/file.proto: warning: Import other/path/file.proto but not used.
```

The proto compiler is letting you know that you have an `import` statement
loading a file from which nothing is used, so it is wasted work. The `import`
can be removed (in this case, `import other/path/file.proto` could be removed
from `path/file.proto`). These warnings can also mean that the `proto_library`
has `deps` that aren't needed. Removing those along with the `import`
statement(s) will speed up downstream Swift compilation actions, because it
prevents unused modules from being loaded by `swiftc`.

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="deprecated_swift_proto_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="deprecated_swift_proto_library-deps"></a>deps | Exactly one `proto_library` target (or any target that propagates a `proto` provider) from which the Swift library should be generated. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |


<a id="swift_binary"></a>

## swift_binary
Expand Down
84 changes: 0 additions & 84 deletions examples/xplatform/deprecated_grpc/BUILD

This file was deleted.

Loading

0 comments on commit 1aec64c

Please sign in to comment.