Commit 1f07ec6
rust protobuf: use crate name aliases to disambiguate generated dependencies
Previously, whenever a proto_library depends on two proto_library targets with the same name from different packages, there is a possibility for crate name collisions. Collisions caused two different crates to be passed with the same name to a rust compilation action via the rustc --extern flag; result is a rust compilation error.
In addition, the aspect compiled the rust code with `force_all_deps_direct`. This is used to handle transitive public imports in protobuf. That has the effect of passing all transitive crate dependencies as-if they were direct via the rustc --extern flag. This compounds the previous issue, rising the risk for crate name collisions.
Here we address these two issues.
To support transitive public imports without `force_all_deps_direct`, we update the aspect to crawl through the `exports` attribute of proto_library targets and collect the rust providers of transitively exported proto libraries in a new RustProtoInfo.exports_dep_variant_infos field. The generated rust code for a consumer proto_library is then provided the rust providers of the transitively exported dependencies.
To address the crate naming collision amongst dependencies, we update the aspect to automatically compute and use disambiguating crate name aliases. These are crate names that encode the full target label of dependencies, in a matter similar to that rules_rust privately uses for its `rename_first_party_crates` functionality. Crucially, this is implemented in protobuf-rust itself and only affects the consumer side of the generated rust code. This avoids the need to synchronize the details between this and rules_rust; uniformly handles first- and third-party dependencies without the need to maintain an explicit distinction, and avoids some issues like running into system filename limits when trying to encode a long target's label into a crate name at crate creation time.
PiperOrigin-RevId: 8556636261 parent 7c67a4c commit 1f07ec6
File tree
25 files changed
+1053
-24
lines changed- rust
- bazel
- test
- encode_raw_string_as_crate_name
- p
- q
- rust_proto_library_unit_test
25 files changed
+1053
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
37 | | - | |
38 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
| |||
52 | 61 | | |
53 | 62 | | |
54 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
| |||
226 | 238 | | |
227 | 239 | | |
228 | 240 | | |
229 | | - | |
| 241 | + | |
230 | 242 | | |
231 | 243 | | |
232 | 244 | | |
| |||
237 | 249 | | |
238 | 250 | | |
239 | 251 | | |
| 252 | + | |
240 | 253 | | |
241 | 254 | | |
242 | 255 | | |
| |||
292 | 305 | | |
293 | 306 | | |
294 | 307 | | |
295 | | - | |
| 308 | + | |
296 | 309 | | |
297 | 310 | | |
298 | 311 | | |
| |||
302 | 315 | | |
303 | 316 | | |
304 | 317 | | |
305 | | - | |
306 | | - | |
307 | 318 | | |
308 | 319 | | |
309 | 320 | | |
| |||
343 | 354 | | |
344 | 355 | | |
345 | 356 | | |
346 | | - | |
347 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
348 | 364 | | |
349 | 365 | | |
350 | 366 | | |
351 | 367 | | |
352 | 368 | | |
353 | 369 | | |
354 | 370 | | |
| 371 | + | |
355 | 372 | | |
356 | 373 | | |
357 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
358 | 387 | | |
359 | 388 | | |
360 | 389 | | |
| |||
422 | 451 | | |
423 | 452 | | |
424 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
425 | 468 | | |
426 | 469 | | |
427 | 470 | | |
428 | 471 | | |
429 | 472 | | |
430 | | - | |
| 473 | + | |
| 474 | + | |
431 | 475 | | |
432 | 476 | | |
433 | 477 | | |
434 | 478 | | |
| 479 | + | |
435 | 480 | | |
436 | 481 | | |
437 | | - | |
| 482 | + | |
438 | 483 | | |
439 | 484 | | |
440 | 485 | | |
| |||
444 | 489 | | |
445 | 490 | | |
446 | 491 | | |
447 | | - | |
| 492 | + | |
448 | 493 | | |
449 | 494 | | |
450 | 495 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
468 | 470 | | |
469 | 471 | | |
470 | 472 | | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments