Repository navigation
Commit 9781651
authored
feat(rust): flat-crate proto_rust_library + prost/tonic interop fixes (#425)
* Auto-sync root Cargo.toml workspace members and proto_compile_assets deps
After GenerateRules has run for every package, rewrite two marker-delimited
sections at the repo root:
- Cargo.toml between `# gazelle:proto_rust_members start/end` —
populated with one entry per package that emitted a proto_rust_library.
- BUILD.bazel between `# gazelle:vendor_proto_sources_deps start/end` —
populated with the underlying _lib target of each proto_rust_library
plus every proto_compiled_sources rule.
Both rewrites are no-ops when the markers (or the target file) are absent,
so existing repos without the markers see no change. Entries are sorted
and deduplicated; the file is only rewritten when content actually changes.
* proto_rust_library: flat-crate convention — drop pkg attr, _rs suffix, nested extern paths
The consuming Starlark proto_rust_library macro now exposes all generated
types at the crate root, so several pieces of namespace plumbing that
the gazelle extension was emitting are no longer needed and have been
removed:
- pkg attribute on the generated rule (rust_library.go): the macro
doesn't accept it anymore. RustLibrary.Pkg() is retained as an
internal helper that still feeds Name() and Reexports() — only the
SetAttr("pkg", ...) emission is gone.
- _rs suffix on crate names (rust_keywords.go): RustCrateName returns
the package with dots replaced by underscores, with no trailing
"_rs". E.g. "google.api" -> "google_api" (was "google_api_rs"). The
crate name now IS the namespace, matching the flat-root layout.
- Nested ::module::path on extern_path entries (extern_paths.go):
`extern_path=.{pkg}=::{crate}::{module}` is shortened to
`extern_path=.{pkg}=::{crate}` for transitive deps, and the
self-extern override `extern_path=.{pkg}=crate::{module}::...` is
shortened to `extern_path=.{pkg}=crate`. Both reflect the same
flat-root convention.
* gencopy: print a ProTip with the .update target when a check fails
When `bazel test //path:foo_proto_compile_test` fails because a checked-in
generated file has drifted from what `protoc` would produce, the existing
error tells you which file pair mismatched and shows the diff, but leaves
the developer to figure out which target regenerates the source-of-truth
copy.
Append a one-line ProTip to the mismatch error message, naming the
`.update` target so it can be copy-pasted into `bazel run`:
gencopy mismatch "foo.pb.go.gen" vs. "foo.pb.go" (-want +got):
...
ProTip: to regenerate, run:
bazel run //proto:foo_proto_compile.update
The label is derived from pkg.TargetLabel (the proto_compile rule's full
label, including any external-repo prefix) by replacing the rule-name
component with cfg.UpdateTargetLabelName -- both already populated by the
proto_compile_gencopy_test Starlark rule via gencopy_config().
* fix: enumerate all protos
* fix: extern path resolution for WKT
* fix(rust): service-only libs, plugin order, output_mappings for path-mismatched pkgs
Three independent failures surfaced by running protoc-gen-prost,
protoc-gen-prost-serde, and protoc-gen-tonic together across a real
monorepo:
1. Service-only proto_libraries (no messages/enums) caused tonic to
error with "Tried to insert into file that doesn't exist": tonic
appends client/server code into prost's {package}.rs at the
@@protoc_insertion_point(module) marker, but ProtocGenProstPlugin
skipped libraries with no messages or enums. shouldApply and
outputs now also fire on HasServices() so prost emits a stub .rs
for tonic to insert into. Two new tests in protoc-gen-prost_test.
2. Plugin order was non-deterministic: BUILD.bazel attr ordering
(preserved by bazel-gazelle's standard list-merge) put tonic
before prost, so tonic's insertion ran before prost created its
target file — yielding the "Tried to insert into file that
doesn't exist" / "Tried to write the same file twice" pair.
proto_compile.bzl now sorts plugins by name inside the rule impl,
so protoc CLI ordering is independent of attr ordering.
3. proto packages whose path doesn't match the bazel package dir
(e.g. "trumid.common.auth" living at //trumid/common/auth/proto,
or "grpc.health.v1" living at //thirdparty/.../grpc/health/v1)
failed with `mv: ... No such file or directory` because prost
writes to its proto-package-derived path while proto_compile.bzl
expected the output at the bazel pkg. The output_mappings
computation in proto_rust_library.ProvideRule only handled the
Rust-keyword-escape case (e.g. google.type → google/r#type).
Generalized: emit mappings whenever RustProtocOutputDir(pkg)
differs from pc.Rel, regardless of whether keywords are involved.
Extracted RustProtocOutputDir helper; existing
RustKeywordEscapeMappings retained for back-compat with the
exposed Starlark function.
* checkpoint: per-file progress
* per-file-imports checkpoint
* checkpoint: refactor without per_file
* checkpoint: all rlibs compile
* apply buildifier.fix
* fix(rust): deduplicate extern paths and apply rewrites
* fix(rust): exclude per-file crates from Cargo workspace
* fix(rust): enroll per-file Cargo manifests
* fix(rust): enroll per-file Cargo deps transitively
* fix(rust): manage per-file Cargo exclusions
* fix(rust): expose per-file Cargo path dependencies
* fix(rust): document Cargo path patches
* Revert "fix(rust): document Cargo path patches"
This reverts commit 4aa32a1.
* Revert "fix(rust): expose per-file Cargo path dependencies"
This reverts commit b5078bb.1 parent 4518136 commit 9781651
31 files changed
Lines changed: 1845 additions & 157 deletions
File tree
- cmd/gencopy
- example/thing
- pkg
- language/protobuf
- plugin/neoeinstein
- prost_serde
- prost
- tonic
- protoc
- rule/rules_rust
- rules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| |||
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
132 | 152 | | |
133 | 153 | | |
134 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
147 | 183 | | |
148 | 184 | | |
149 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
120 | 127 | | |
121 | 128 | | |
122 | 129 | | |
123 | 130 | | |
| 131 | + | |
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
107 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
136 | 144 | | |
137 | 145 | | |
138 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
139 | 155 | | |
140 | 156 | | |
141 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
154 | 176 | | |
155 | 177 | | |
156 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| |||
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
54 | 63 | | |
55 | 64 | | |
56 | 65 | | |
| |||
67 | 76 | | |
68 | 77 | | |
69 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
70 | 92 | | |
71 | 93 | | |
72 | 94 | | |
| |||
0 commit comments