@@ -36,190 +36,6 @@ On this page:
36
36
* [ deprecated_swift_grpc_library] ( #deprecated_swift_grpc_library )
37
37
* [ deprecated_swift_proto_library] ( #deprecated_swift_proto_library )
38
38
39
- <a id =" deprecated_swift_grpc_library " ></a >
40
-
41
- ## deprecated_swift_grpc_library
42
-
43
- <pre >
44
- 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 >)
45
- </pre >
46
-
47
- DEPRECATED -- Please use the swift_proto_library rule defined in //proto: proto .bzl instead.
48
- This rule will be removed in the next rules_swift major version update.
49
- If you're already using this rule, see [ the proto migration doc] ( proto_migration.md ) for infomation on how to migrate.
50
-
51
- Generates a Swift library from gRPC services defined in protocol buffer sources.
52
-
53
- There should be one ` swift_grpc_library ` for any ` proto_library ` that defines
54
- services. A target based on this rule can be used as a dependency anywhere that
55
- a ` swift_library ` can be used.
56
-
57
- We recommend that ` swift_grpc_library ` targets be located in the same package as
58
- the ` proto_library ` and ` swift_proto_library ` targets they depend on. For more
59
- best practices around the use of Swift protocol buffer build rules, see the
60
- documentation for ` swift_proto_library ` .
61
-
62
- #### Defining Build Targets for Services
63
-
64
- Note that ` swift_grpc_library ` only generates the gRPC service interfaces (the
65
- ` service ` definitions) from the ` .proto ` files. Any messages defined in the same
66
- ` .proto ` file must be generated using a ` swift_proto_library ` target. Thus, the
67
- typical structure of a Swift gRPC library is similar to the following:
68
-
69
- ``` python
70
- proto_library(
71
- name = " my_protos" ,
72
- srcs = [" my_protos.proto" ],
73
- )
74
-
75
- # Generate Swift types from the protos.
76
- swift_proto_library(
77
- name = " my_protos_swift" ,
78
- deps = [" :my_protos" ],
79
- )
80
-
81
- # Generate Swift types from the services.
82
- swift_grpc_library(
83
- name = " my_protos_client_services_swift" ,
84
-
85
- # The `srcs` attribute points to the `proto_library` containing the service
86
- # definitions...
87
- srcs = [" :my_protos" ],
88
-
89
- # ...the `flavor` attribute specifies the kind of definitions to generate...
90
- flavor = " client" ,
91
-
92
- # ...and the `deps` attribute points to the `swift_proto_library` that was
93
- # generated from the same `proto_library` and which contains the messages
94
- # used by those services.
95
- deps = [" :my_protos_swift" ],
96
- )
97
-
98
- # Generate test stubs from swift services.
99
- swift_grpc_library(
100
- name = " my_protos_client_stubs_swift" ,
101
-
102
- # The `srcs` attribute points to the `proto_library` containing the service
103
- # definitions...
104
- srcs = [" :my_protos" ],
105
-
106
- # ...the `flavor` attribute specifies the kind of definitions to generate...
107
- flavor = " client_stubs" ,
108
-
109
- # ...and the `deps` attribute points to the `swift_grpc_library` that was
110
- # generated from the same `proto_library` and which contains the service
111
- # implementation.
112
- deps = [" :my_protos_client_services_swift" ],
113
- )
114
- ```
115
-
116
- ** ATTRIBUTES**
117
-
118
-
119
- | Name | Description | Type | Mandatory | Default |
120
- | :------------- | :------------- | :------------- | :------------- | :------------- |
121
- | <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 | |
122
- | <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 | ` [] ` |
123
- | <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 | ` [] ` |
124
- | <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 | |
125
-
126
-
127
- <a id =" deprecated_swift_proto_library " ></a >
128
-
129
- ## deprecated_swift_proto_library
130
-
131
- <pre >
132
- deprecated_swift_proto_library(<a href =" #deprecated_swift_proto_library-name " >name</a >, <a href =" #deprecated_swift_proto_library-deps " >deps</a >)
133
- </pre >
134
-
135
- DEPRECATED -- Please use the swift_proto_library rule defined in //proto: proto .bzl instead.
136
- This rule will be removed in the next rules_swift major version update.
137
- If you're already using this rule, see [ the proto migration doc] ( proto_migration.md ) for infomation on how to migrate.
138
-
139
- Generates a Swift library from protocol buffer sources.
140
-
141
- There should be one ` swift_proto_library ` for any ` proto_library ` that you wish
142
- to depend on. A target based on this rule can be used as a dependency anywhere
143
- that a ` swift_library ` can be used.
144
-
145
- A ` swift_proto_library ` target only creates a Swift module if the
146
- ` proto_library ` on which it depends has a non-empty ` srcs ` attribute. If the
147
- ` proto_library ` does not contain ` srcs ` , then no module is produced, but the
148
- ` swift_proto_library ` still propagates the modules of its non-empty dependencies
149
- so that those generated protos can be used by depending on the
150
- ` swift_proto_library ` of the "collector" target.
151
-
152
- Note that the module name of the Swift library produced by this rule (if any) is
153
- based on the name of the ` proto_library ` target, * not* the name of the
154
- ` swift_proto_library ` target. In other words, if the following BUILD file were
155
- located in ` //my/pkg ` , the target would create a Swift module named
156
- ` my_pkg_foo ` :
157
-
158
- ``` python
159
- proto_library(
160
- name = " foo" ,
161
- srcs = [" foo.proto" ],
162
- )
163
-
164
- swift_proto_library(
165
- name = " foo_swift" ,
166
- deps = [" :foo" ],
167
- )
168
- ```
169
-
170
- Because the Swift modules are generated from an aspect that is applied to the
171
- ` proto_library ` targets, the module name and other compilation flags for the
172
- resulting Swift modules cannot be changed.
173
-
174
- #### Tip: Where to locate ` swift_proto_library ` targets
175
-
176
- Convention is to put the ` swift_proto_library ` in the same ` BUILD ` file as the
177
- ` proto_library ` it is generating for (just like all the other
178
- ` LANG_proto_library ` rules). This lets anyone needing the protos in Swift share
179
- the single rule as well as making it easier to realize what proto files are in
180
- use in what contexts.
181
-
182
- This is not a requirement, however, as it may not be possible for Bazel
183
- workspaces that create ` swift_proto_library ` targets that depend on
184
- ` proto_library ` targets from different repositories.
185
-
186
- #### Tip: Avoid ` import ` only ` .proto ` files
187
-
188
- Avoid creating a ` .proto ` file that just contains ` import ` directives of all the
189
- other ` .proto ` files you need. While this does _ group_ the protos into this new
190
- target, it comes with some high costs. This causes the proto compiler to parse
191
- all those files and invoke the generator for an otherwise empty source file.
192
- That empty source file then has to get compiled, but it will have dependencies
193
- on the full deps chain of the imports (recursively). The Swift compiler must
194
- load all of these module dependencies, which can be fairly slow if there are
195
- many of them, so this method of grouping via a ` .proto ` file actually ends up
196
- creating build steps that slow down the build.
197
-
198
- #### Tip: Resolving unused import warnings
199
-
200
- If you see warnings like the following during your build:
201
-
202
- ```
203
- path/file.proto: warning: Import other/path/file.proto but not used.
204
- ```
205
-
206
- The proto compiler is letting you know that you have an ` import ` statement
207
- loading a file from which nothing is used, so it is wasted work. The ` import `
208
- can be removed (in this case, ` import other/path/file.proto ` could be removed
209
- from ` path/file.proto ` ). These warnings can also mean that the ` proto_library `
210
- has ` deps ` that aren't needed. Removing those along with the ` import `
211
- statement(s) will speed up downstream Swift compilation actions, because it
212
- prevents unused modules from being loaded by ` swiftc ` .
213
-
214
- ** ATTRIBUTES**
215
-
216
-
217
- | Name | Description | Type | Mandatory | Default |
218
- | :------------- | :------------- | :------------- | :------------- | :------------- |
219
- | <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 | |
220
- | <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 | ` [] ` |
221
-
222
-
223
39
<a id =" swift_binary " ></a >
224
40
225
41
## swift_binary
0 commit comments