|
68 | 68 | </chapter> |
69 | 69 | <chapter id="working-with-proto-files"> |
70 | 70 | <title> |
71 | | - Working with <code>.proto</code> files |
| 71 | + Working with proto-files |
72 | 72 | </title> |
73 | 73 | <p> |
74 | 74 | The minimum required configuration looks like this: |
|
79 | 79 | } |
80 | 80 | </code-block> |
81 | 81 | <p> |
82 | | - This will enable the code generation for your <code>.proto</code> files. |
83 | | - We create special source sets for <code>.proto</code> files: |
| 82 | + This enables code generation for your <path>.proto</path> files. |
| 83 | + Special source sets are created for them: |
84 | 84 | </p> |
85 | 85 | <list> |
86 | 86 | <li> |
87 | 87 | <code>main</code> and <code>test</code> - source sets for Kotlin/JVM projects. |
88 | | - Default source directories are <code>src/main/proto</code> and <code>src/test/proto</code>. |
| 88 | + Default source directories are <path>src/main/proto</path> and <path>src/test/proto</path>. |
89 | 89 | </li> |
90 | 90 | <li> |
91 | 91 | <code>jvmMain</code> and <code>jvmTest</code> - source sets for Kotlin/Multiplatform projects. |
92 | | - Default source directories are <code>src/jsmMain/proto</code> and <code>src/jvmTest/proto</code>. |
| 92 | + Default source directories are <path>src/jsmMain/proto</path> and <path>src/jvmTest/proto</path>. |
93 | 93 | <warning> |
94 | | - This will change to <code>src/commonMain/proto</code> and <code>src/commonTest/proto</code> in the |
| 94 | + These will change to <path>src/commonMain/proto</path> and <path>src/commonTest/proto</path> in the |
95 | 95 | future. |
96 | 96 | </warning> |
97 | | - <note> |
98 | | - Source set hierarchy is not supported, and we have no plans to support it. |
99 | | - That means, for example, |
100 | | - that you can't have <code>jsMain</code> and <code>jsTest</code> source sets for proto files. |
101 | | - Same for native and WASM. |
102 | | - Proto files can only be in the <code>jvmMain</code> and <code>jvmTest</code> source sets. |
103 | | - (Later to be replaced with <code>commonMain</code> and <code>commonTest</code>) |
104 | | - <br/> |
105 | | - <br/> |
106 | | - If you have a use case for other source sets and a hierarchy, |
107 | | - please <a href="https://github.com/Kotlin/kotlinx-rpc/issues/new?template=feature_request.md">report it</a>. |
108 | | - </note> |
109 | 97 | </li> |
110 | 98 | <li> |
111 | | - Android source sets are not supported yet. <b>WIP</b> |
| 99 | + Android source set support is not available yet but will be included in a future release. |
112 | 100 | </li> |
113 | 101 | </list> |
114 | 102 | <p> |
|
133 | 121 | } |
134 | 122 | </code-block> |
135 | 123 | <p> |
136 | | - By default, four source directories will be generated: |
| 124 | + By default, the following source directories are generated: |
137 | 125 | </p> |
138 | 126 | <list> |
139 | 127 | <li> |
140 | | - <code>java</code> - protobuf Java declarations, attached to <code>java</code> sources |
| 128 | + <code>java</code> - protobuf Java declarations, attached to <code>java</code> sources. |
141 | 129 | </li> |
142 | 130 | <li> |
143 | | - <code>grpc-java</code> - gRPC Java declarations, attached to <code>java</code> sources |
| 131 | + <code>grpc-java</code> - gRPC Java declarations, attached to <code>java</code> sources. |
144 | 132 | </li> |
145 | 133 | <li> |
146 | | - <code>grpc-kotlin</code> - gRPC Kotlin wrappers for Java, attached to <code>kotlin</code> sources |
| 134 | + <code>grpc-kotlin</code> - gRPC Kotlin wrappers for Java, attached to <code>kotlin</code> sources. |
147 | 135 | </li> |
148 | 136 | <li> |
149 | | - <code>kotlinx-multiplatform</code> - our wrappers for all of the above, attached to <code>kotlin</code> sources |
| 137 | + <code>kotlin-multiplatform</code> - wrappers for all of the above, attached to <code>kotlin</code> sources. |
150 | 138 | </li> |
151 | 139 | </list> |
152 | 140 | <note> |
153 | | - Only the declarations from the <code>kotlinx-multiplatform</code> source set are intended to be used. |
154 | | - The other ones are for internal use only and will be removed in the future. |
| 141 | + Only the declarations from the <code>kotlin-multiplatform</code> source set are intended to be used. |
| 142 | + The others are for internal use only and will be removed in a future release. |
155 | 143 | </note> |
156 | 144 | </chapter> |
| 145 | + <chapter title="Limitations" id="limitations"> |
| 146 | + <p> |
| 147 | + Source set hierarchy is not supported, and we have no plans to support it. |
| 148 | + That means, for example, |
| 149 | + that you can't have <code>jsMain</code> and <code>jsTest</code> source sets for proto files. |
| 150 | + The same applies for native and Wasm targets. |
| 151 | + Currently, <path>.proto</path> files are only supported in the <code>jvmMain</code> and <code>jvmTest</code> source sets. |
| 152 | + (Later to be replaced with <code>commonMain</code> and <code>commonTest</code>) |
| 153 | + <br/> |
| 154 | + <br/> |
| 155 | + If you have a use case for other source sets and a hierarchy, |
| 156 | + please <a href="https://github.com/Kotlin/kotlinx-rpc/issues/new?template=feature_request.md">report it</a>. |
| 157 | + </p> |
| 158 | + </chapter> |
157 | 159 | <chapter title="Protoc plugins" id="protoc-plugins"> |
158 | 160 | <p> |
159 | | - To generate code, we need to use <a href="https://protobuf.dev/reference/other/">protoc plugins</a>. |
| 161 | + To generate code, we use <a href="https://protobuf.dev/reference/other/"><emphasis>protoc</emphasis> plugins</a>. |
160 | 162 | By default, we use the following plugins: |
161 | 163 | </p> |
162 | 164 | <list> |
|
172 | 174 | plugin. |
173 | 175 | </li> |
174 | 176 | <li> |
175 | | - <code>kotlinx-multiplatform</code> - out own protoc plugin. |
| 177 | + <code>kotlin-multiplatform</code> - out own protoc plugin. |
176 | 178 | </li> |
177 | 179 | </list> |
178 | 180 | <p> |
|
195 | 197 | </code-block> |
196 | 198 | <p> |
197 | 199 | <code>protocPlugins</code> is a <code>NamedDomainObjectContainer<ProtocPlugin></code>, |
198 | | - which allows to add your own plugins. |
| 200 | + which allows you to add your own plugins. |
199 | 201 | </p> |
200 | 202 | <p> |
201 | | - Every plugin is a <code>ProtocPlugin</code> class, that can be configured like this: |
| 203 | + Each plugin is represented by a <code>ProtocPlugin</code> and can be configured like this: |
202 | 204 | </p> |
203 | 205 | <code-block lang="Kotlin"> |
204 | | - // or like protocPlugins.kotlinMultiplatform for default plugins |
| 206 | + // Or use protocPlugins.kotlinMultiplatform for default plugins |
205 | 207 | protocPlugins.create("myPlugin") { |
206 | 208 | isJava = true // add generated code to the java source set |
207 | 209 |
|
208 | | - // add plugin options |
| 210 | + // Add plugin options |
209 | 211 | options.put("myOption") |
210 | 212 | options.put("myOption1", "myValue") |
211 | 213 |
|
|
229 | 231 | locator = "buf.build/grpc/go" |
230 | 232 | } |
231 | 233 |
|
232 | | - // other Buf configuration options: |
| 234 | + // Additional Buf configuration options: |
233 | 235 | strategy = ProtocPlugin.Strategy.All |
234 | 236 | includeImports = false |
235 | 237 | includeWkt = false |
|
241 | 243 | Buf's plugin <a href="https://buf.build/docs/configuration/v2/buf-gen-yaml#plugins">configuration</a> |
242 | 244 | options: |
243 | 245 | </p> |
244 | | - <list> |
245 | | - <li> |
| 246 | + <deflist> |
| 247 | + <def title="strategy" id="strategy"> |
246 | 248 | <a href="https://buf.build/docs/configuration/v2/buf-gen-yaml/#strategy">strategy</a> |
247 | 249 | — <code>All</code> or <code>Directory</code> |
248 | | - </li> |
249 | | - <li> |
| 250 | + </def> |
| 251 | + <def title="includeImports" id="includeImports"> |
250 | 252 | <a href="https://buf.build/docs/configuration/v2/buf-gen-yaml/#include_imports">includeImports</a> |
251 | 253 | — <code>true</code> or <code>false</code> |
252 | | - </li> |
253 | | - <li> |
| 254 | + </def> |
| 255 | + <def title="includeWkt" id="includeWkt"> |
254 | 256 | <a href="https://buf.build/docs/configuration/v2/buf-gen-yaml/#include_wkt">includeWkt</a> |
255 | 257 | — <code>true</code> or <code>false</code> |
256 | | - </li> |
257 | | - <li> |
| 258 | + </def> |
| 259 | + <def title="types" id="types"> |
258 | 260 | <a href="https://buf.build/docs/configuration/v2/buf-gen-yaml/#types">types</a> |
259 | 261 | — a list of types to generate. |
260 | | - </li> |
261 | | - <li> |
| 262 | + </def> |
| 263 | + <def title="excludeTypes" id="excludeTypes"> |
262 | 264 | <a href="https://buf.build/docs/configuration/v2/buf-gen-yaml/#exclude-types">excludeTypes</a> |
263 | 265 | — a list of types to exclude from generation. |
264 | | - </li> |
265 | | - </list> |
| 266 | + </def> |
| 267 | + </deflist> |
266 | 268 | <p> |
267 | | - A plugin, once added to the <code>protocPlugins</code> container, can be used in a source set: |
| 269 | + Once a plugin is added to the <code>protocPlugins</code> container, it can be used in a source set: |
268 | 270 | </p> |
269 | 271 | <code-block lang="Kotlin"> |
270 | 272 | protoSourceSets { |
|
283 | 285 | </p> |
284 | 286 | <note> |
285 | 287 | We <b>don't</b> use Buf's <code>build.buf</code> Gradle Plugin |
286 | | - and prohibit using it in projects with our plugin to prevent conflicts. |
| 288 | + and disallow using it in projects that apply our plugin, in order to avoid conflicts. |
287 | 289 | </note> |
288 | 290 | <chapter title="Generated Workspace" id="generated-workspace"> |
289 | 291 | <p> |
290 | | - To make UX smooth, we introduce a concept of a <b>generated workspace</b>. |
| 292 | + To improve the developer experience, we introduce the concept of a <b>generated workspace</b>. |
291 | 293 | It's a directory that contains all the necessary files for Buf to work: |
292 | 294 | </p> |
293 | 295 | <list> |
294 | 296 | <li> |
295 | | - Filtered <code>.proto</code> files |
| 297 | + Filtered <path>.proto</path> files |
296 | 298 | </li> |
297 | 299 | <li> |
298 | | - Generated <code>buf.yaml</code> file |
| 300 | + Generated <path>buf.yaml</path> file |
299 | 301 | </li> |
300 | 302 | <li> |
301 | | - Generated <code>buf.gen.yaml</code> file |
| 303 | + Generated <path>buf.gen.yaml</path> file |
302 | 304 | </li> |
303 | 305 | <li> |
304 | 306 | Automatically managed imports from a <code>main</code> source set to a <code>test</code> source set, |
305 | 307 | making imports intuitive. |
306 | 308 | </li> |
307 | 309 | </list> |
308 | 310 | <p> |
309 | | - This workspace is created automatically for each source set, |
310 | | - and can be found in the <code>build/protoBuild</code> directory. |
| 311 | + This workspace is created automatically for each source set |
| 312 | + and can be found in the <path>build/protoBuild</path> directory. |
311 | 313 | You don't need to do anything with it, unless you want to customise it. |
312 | 314 | </p> |
313 | 315 | </chapter> |
314 | 316 | <chapter title="Tasks" id="buf-tasks"> |
315 | 317 | <p> |
316 | | - We create the following tasks if the project is configured to use <code>grpc</code>: |
| 318 | + If your project is configured to use gRPC, the following tasks will be generated: |
317 | 319 | </p> |
318 | 320 | <list> |
319 | 321 | <li> |
320 | 322 | <code>generateBufYaml<sourceSet></code> |
321 | | - — generates <code>buf.yaml</code> |
| 323 | + — generates <path>buf.yaml</path> |
322 | 324 | <br/> |
323 | 325 | <br/> |
324 | 326 | Type: <code>kotlinx.rpc.buf.tasks.GenerateBufYaml</code> |
325 | 327 | </li> |
326 | 328 | <li> |
327 | 329 | <code>generateBufGenYaml<sourceSet></code> |
328 | | - — generates <code>buf.gen.yaml</code> |
| 330 | + — generates <path>buf.gen.yaml</path> |
329 | 331 | <br/> |
330 | 332 | <br/> |
331 | 333 | Type: <code>kotlinx.rpc.buf.tasks.GenerateBufGenYaml</code> |
|
359 | 361 | rpc { |
360 | 362 | grpc { |
361 | 363 | buf { |
362 | | - // configure Buf here |
| 364 | + // Configure Buf |
363 | 365 | logFormat = BufExtenstion.LogFormat.Text |
364 | 366 | timeout = 60.seconds |
365 | 367 |
|
366 | 368 | generate { |
367 | | - // configure Buf generate here |
| 369 | + // Configure Buf generate |
368 | 370 |
|
369 | 371 | includeImports = false |
370 | 372 | includeWkt = false |
|
377 | 379 | <p> |
378 | 380 | General configuration options: |
379 | 381 | </p> |
380 | | - <list> |
381 | | - <li> |
| 382 | + <deflist> |
| 383 | + <def title="logFormat" id="logFormat"> |
382 | 384 | <a href="https://buf.build/docs/reference/cli/buf/#log-format">logFormat</a> |
383 | 385 | — either <code>Text</code>, <code>Color</code>, <code>Json</code> or <code>Default</code> |
384 | | - </li> |
385 | | - <li> |
| 386 | + </def> |
| 387 | + <def title="timeout" id="timeout"> |
386 | 388 | <a href="https://buf.build/docs/reference/cli/buf/#timeout">timeout</a> |
387 | 389 | — timeout for the <code>buf</code> commands, always converted to whole seconds |
388 | | - </li> |
389 | | - <li> |
390 | | - Gradle's <code>--debug</code> enables Buf's <code>--debug</code> option. |
391 | | - </li> |
392 | | - </list> |
| 390 | + </def> |
| 391 | + <def title="--debug" id="debug"> |
| 392 | + Running Gradle with <code>--debug</code> enables Buf's <code>--debug</code> option as well. |
| 393 | + </def> |
| 394 | + </deflist> |
393 | 395 | <p> |
394 | 396 | <code>buf generate</code> configuration options: |
395 | 397 | </p> |
396 | | - <list> |
397 | | - <li> |
| 398 | + <deflist> |
| 399 | + <def title="includeImports" id="generate_includeImports"> |
398 | 400 | <a href="https://buf.build/docs/reference/cli/buf/generate/#include-imports">includeImports</a> |
399 | 401 | — <code>true</code> or <code>false</code> |
400 | | - </li> |
401 | | - <li> |
| 402 | + </def> |
| 403 | + <def title="includeWkt" id="generate_includeWkt"> |
402 | 404 | <a href="https://buf.build/docs/reference/cli/buf/generate/#include-wkt">includeWkt</a> |
403 | 405 | — <code>true</code> or <code>false</code> |
404 | | - </li> |
405 | | - <li> |
| 406 | + </def> |
| 407 | + <def title="errorFormat" id="generate_errorFormat"> |
406 | 408 | <a href="https://buf.build/docs/reference/cli/buf/generate/#error-format">errorFormat</a> |
407 | 409 | — either <code>Text</code>, <code>Json</code>, <code>Msvs</code>, |
408 | 410 | <code>Junit</code>, <code>GithubActions</code> or <code>Default</code> |
409 | | - </li> |
410 | | - </list> |
| 411 | + </def> |
| 412 | + </deflist> |
411 | 413 | </chapter> |
412 | 414 | <chapter title="Custom tasks" id="buf-custom-tasks"> |
413 | 415 | <p> |
414 | | - We only support <code>generate</code> tasks for now. |
415 | | - But Buf has great capabilities for managing <code>.proto</code> files, |
416 | | - like linting, detection of breaking changes, etc. |
417 | | - So we made it possible to create custom buf tasks. |
| 416 | + Currently, we only support <code>generate</code> tasks. |
| 417 | + However, because of Buf's capabilities for managing <path>.proto</path> files, |
| 418 | + like linting and detection of breaking changes, |
| 419 | + we provide a way to create custom Buf tasks. |
418 | 420 | </p> |
419 | 421 | <p> |
420 | | - To create a custom task, it must be a subclass of the <code>kotlinx.rpc.buf.tasks.BufExecTask</code>. |
421 | | - It doesn't need to define a <code>@TaskAction</code>, just a set of arguments and a command to execute. |
| 422 | + To create a custom task, extend the <code>kotlinx.rpc.buf.tasks.BufExecTask</code> class. |
| 423 | + You don't need to define a <code>@TaskAction</code>; just a set of arguments and a command to execute. |
422 | 424 | </p> |
423 | 425 | <p> |
424 | | - Registering the task can be done in two ways: |
| 426 | + You can register the task in two ways: |
425 | 427 | </p> |
426 | 428 | <list> |
427 | 429 | <li> |
|
443 | 445 | These tasks can be executed on a generated workspace for all proto source sets. |
444 | 446 | </p> |
445 | 447 | <note> |
446 | | - Note that the tasks are not plugged into the build cycle, |
447 | | - so they won't be executed automatically. |
| 448 | + These tasks are not plugged into the Gradle build cycle, |
| 449 | + so you must run them manually |
448 | 450 | </note> |
449 | 451 | </li> |
450 | 452 | <li> |
|
458 | 460 | } |
459 | 461 | </code-block> |
460 | 462 | <p> |
461 | | - It is just a regular Gradle task that has access to the Buf's executable |
| 463 | + It is a standard Gradle task that has access to the Buf's executable |
462 | 464 | and some predefined properties. |
463 | 465 | </p> |
464 | 466 | </li> |
|
0 commit comments