Skip to content

Commit e1e0949

Browse files
committed
Extract descriptor types into buffa-descriptor crate
Moves the generated FileDescriptorProto/DescriptorProto types and vendored descriptor.proto sources from buffa-codegen into a new buffa-descriptor crate that depends only on buffa. This makes the descriptor types available without pulling in quote/syn/prettyplease, laying the foundation for runtime reflection. buffa-codegen re-exports buffa_descriptor::generated so all existing crate::generated:: paths resolve unchanged. gen_descriptor_types now takes an explicit output directory argument, eliminating the previous cwd-sensitivity.
1 parent 950b63a commit e1e0949

File tree

25 files changed

+123
-41
lines changed

25 files changed

+123
-41
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ jobs:
9898
- name: Check buffa-types no_std
9999
run: cargo check -p buffa-types --no-default-features
100100

101+
- name: Check buffa-descriptor no_std
102+
run: cargo check -p buffa-descriptor --no-default-features
103+
101104
- name: Check workspace 32-bit
102105
run: cargo check --workspace --target i686-unknown-linux-gnu
103106

@@ -118,7 +121,7 @@ jobs:
118121
- uses: Swatinem/rust-cache@v2
119122

120123
- name: Regenerate bootstrap descriptor types
121-
# Proto sources are vendored in buffa-codegen/protos/ (pinned),
124+
# Proto sources are vendored in buffa-descriptor/protos/ (pinned),
122125
# so this is independent of the installed protoc's bundled includes.
123126
run: scripts/gen-bootstrap-types.sh
124127

@@ -143,7 +146,7 @@ jobs:
143146

144147
- name: Check for differences
145148
run: |
146-
if ! git diff --exit-code buffa-codegen/src/generated/ buffa-types/src/generated/; then
149+
if ! git diff --exit-code buffa-descriptor/src/generated/ buffa-types/src/generated/; then
147150
echo "::error::Checked-in generated code is stale. Run 'task gen-wkt-types' and/or regenerate bootstrap types, then commit."
148151
exit 1
149152
fi

.github/workflows/publish-crates.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ jobs:
8383
- name: Publish buffa-types
8484
run: /tmp/publish.sh buffa-types $DRY_RUN_FLAG
8585

86+
- name: Publish buffa-descriptor
87+
run: /tmp/publish.sh buffa-descriptor $DRY_RUN_FLAG
88+
8689
- name: Publish buffa-codegen
8790
run: /tmp/publish.sh buffa-codegen $DRY_RUN_FLAG
8891

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If a change to `buffa-codegen` (notably `message.rs`, `impl_message.rs`, `view.r
1010

1111
```bash
1212
task gen-wkt-types # buffa-types/src/generated/ — WKTs for consumer use
13-
task gen-bootstrap-types # buffa-codegen/src/generated/ — only if the change affects descriptor types
13+
task gen-bootstrap-types # buffa-descriptor/src/generated/ — only if the change affects descriptor types
1414
```
1515

1616
Most codegen changes don't touch descriptor-specific paths, so `gen-wkt-types` is usually sufficient.

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ docker run --rm -v /tmp/conf:/out -e CONFORMANCE_OUT=/out buffa-conformance
6969

7070
```bash
7171
task tools-image # rebuild and push the multi-arch tools image
72-
task vendor-bootstrap-protos # re-fetch buffa-codegen/protos/ from the new release tag
72+
task vendor-bootstrap-protos # re-fetch buffa-descriptor/protos/ from the new release tag
7373
task gen-bootstrap-types # regenerate checked-in descriptor types
7474
```
7575

76-
Commit the refreshed `buffa-codegen/protos/` and `buffa-codegen/src/generated/` alongside the version bump.
76+
Commit the refreshed `buffa-descriptor/protos/` and `buffa-descriptor/src/generated/` alongside the version bump.
7777

7878
## Checked-In Generated Code
7979

8080
Three sets of generated code are checked into the repo and **must be regenerated** whenever codegen output changes (e.g. changes to `imports.rs`, `message.rs`, `oneof.rs`, etc.):
8181

82-
1. **Bootstrap descriptor types** (`buffa-codegen/src/generated/`): Used by codegen itself to parse `.proto` descriptors. Regenerate with `task gen-bootstrap-types`. The source protos are vendored in `buffa-codegen/protos/` (pinned; refresh with `task vendor-bootstrap-protos` when bumping the protobuf version), so output is independent of your local protoc's bundled includes — only a protoc binary ≥ v27 is needed. Only needs regeneration when a codegen change affects the descriptor types themselves — most changes don't.
82+
1. **Bootstrap descriptor types** (`buffa-descriptor/src/generated/`): Used by codegen itself to parse `.proto` descriptors. Regenerate with `task gen-bootstrap-types`. The source protos are vendored in `buffa-descriptor/protos/` (pinned; refresh with `task vendor-bootstrap-protos` when bumping the protobuf version), so output is independent of your local protoc's bundled includes — only a protoc binary ≥ v27 is needed. Only needs regeneration when a codegen change affects the descriptor types themselves — most changes don't.
8383

8484
2. **Well-known types** (`buffa-types/src/generated/`): `Timestamp`, `Duration`, `Any`, `Struct`/`Value`, `FieldMask`, `Empty`, wrappers. Checked in (rather than generated at build time) so that consumers of `buffa-types` don't need `protoc` or the `buffa-build`/`buffa-codegen` toolchain. Regenerate with `task gen-wkt-types`. The WKT `.proto` sources are vendored in `buffa-types/protos/` (not read from the protoc installation) so the output is pinned. **This is the one most likely to need regeneration** — WKTs use views, unknown-field preservation, and the `arbitrary` derive, so almost any codegen output-format change touches them. If in doubt, run it and check `git status`.
8585

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "2"
33
members = [
44
"buffa",
55
"buffa-types",
6+
"buffa-descriptor",
67
"buffa-codegen",
78
"buffa-build",
89
"buffa-test",
@@ -32,6 +33,7 @@ categories = ["encoding", "no-std"]
3233
[workspace.dependencies]
3334
buffa = { path = "buffa", version = "0.2.0", default-features = false }
3435
buffa-types = { path = "buffa-types", version = "0.2.0" }
36+
buffa-descriptor = { path = "buffa-descriptor", version = "0.2.0" }
3537
buffa-codegen = { path = "buffa-codegen", version = "0.2.0" }
3638
buffa-build = { path = "buffa-build", version = "0.2.0" }
3739
buffa-test = { path = "buffa-test", version = "0.2.0" }

DESIGN.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ The WKT wire format is completely vanilla — two varints for `Timestamp`, etc.
6767

6868
Both layer on top of the generated `Message` impl via `include!()` + sibling modules; the checked-in code and the hand-written extensions coexist cleanly.
6969

70+
### `buffa-descriptor` — Protobuf Descriptor Types
71+
72+
Self-hosted Rust types for `google/protobuf/descriptor.proto` and `google/protobuf/compiler/plugin.proto`, generated by `buffa-codegen` itself. These are the types that `buffa-codegen` uses to parse protoc's `CodeGeneratorRequest`, and the foundation for future runtime reflection.
73+
74+
The generated code is checked in (regenerate via `task gen-bootstrap-types`). The only runtime dependency is `buffa` — no quote/syn/prettyplease — so the crate is `no_std`-capable and dependency-light enough to depend on from the runtime without pulling in the codegen toolchain.
75+
7076
### `buffa-codegen` — Shared Code Generation Logic
7177

7278
The code generation library, shared between `protoc-gen-buffa` and `buffa-build`. Takes protobuf descriptors (from protoc's `FileDescriptorProto`) and emits Rust source code.
@@ -101,7 +107,7 @@ protoc --buffa_out=. --plugin=protoc-gen-buffa my_service.proto
101107

102108
Reads a `CodeGeneratorRequest` from stdin, passes the file descriptors to `buffa-codegen`, writes a `CodeGeneratorResponse` to stdout.
103109

104-
**Bootstrapping:** The `CodeGeneratorRequest` and `CodeGeneratorResponse` messages are themselves protobuf — we decode/encode them using buffa's own generated descriptor and compiler types (checked into `buffa-codegen/src/generated/`), eliminating any external protobuf library dependency from the build graph.
110+
**Bootstrapping:** The `CodeGeneratorRequest` and `CodeGeneratorResponse` messages are themselves protobuf — we decode/encode them using buffa's own generated descriptor and compiler types (checked into `buffa-descriptor/src/generated/`), eliminating any external protobuf library dependency from the build graph.
105111

106112
### `buffa-build` — Build Script Integration
107113

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ let decoded: MyMessage = serde_json::from_str(&json).unwrap();
132132
|---|---|
133133
| `buffa` | Core runtime: `Message` trait, wire format codec, `no_std` support |
134134
| `buffa-types` | Well-known types: Timestamp, Duration, Any, Struct, wrappers, etc. |
135+
| `buffa-descriptor` | Protobuf descriptor types (`FileDescriptorProto`, `DescriptorProto`, ...) |
135136
| `buffa-codegen` | Code generation from protobuf descriptors |
136137
| `buffa-build` | `build.rs` helper for invoking codegen via `protoc` |
137138
| `protoc-gen-buffa` | `protoc` plugin binary |

Taskfile.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,23 +385,23 @@ tasks:
385385
# ── Checked-in generated code ─────────────────────────────────────────
386386
#
387387
# Two sets of generated code are checked into the repo:
388-
# - buffa-codegen/src/generated/ (bootstrap descriptor types)
388+
# - buffa-descriptor/src/generated/ (bootstrap descriptor types)
389389
# - buffa-types/src/generated/ (well-known types)
390390
# CI (check-generated-code) fails if either is stale.
391391

392392
gen-bootstrap-types:
393393
desc: >-
394-
Regenerate buffa-codegen/src/generated/ (descriptor.proto + plugin.proto
394+
Regenerate buffa-descriptor/src/generated/ (descriptor.proto + plugin.proto
395395
types used by codegen itself to parse descriptors). Only needed when a
396396
codegen change affects the descriptor types themselves — most codegen
397-
changes don't. Proto sources are vendored in buffa-codegen/protos/;
397+
changes don't. Proto sources are vendored in buffa-descriptor/protos/;
398398
only a protoc binary (v27+) is required.
399399
cmds:
400400
- scripts/gen-bootstrap-types.sh
401401

402402
vendor-bootstrap-protos:
403403
desc: >-
404-
Re-fetch buffa-codegen/protos/ from the protobuf release matching
404+
Re-fetch buffa-descriptor/protos/ from the protobuf release matching
405405
TOOLS_IMAGE. Run this when bumping the protobuf version, then follow
406406
with `task gen-bootstrap-types` and commit both. Uses gh (authenticated
407407
API) rather than raw curl to avoid GitHub's anonymous rate limit.
@@ -416,15 +416,15 @@ tasks:
416416
gh CLI must be authenticated. Run: gh auth login
417417
cmds:
418418
- echo "Vendoring descriptor.proto + plugin.proto from protobuf v{{.PROTO_VER}}"
419-
- mkdir -p buffa-codegen/protos/google/protobuf/compiler
419+
- mkdir -p buffa-descriptor/protos/google/protobuf/compiler
420420
- >-
421421
{{.GH_RAW}} '{{.SRC}}/descriptor.proto?ref=v{{.PROTO_VER}}'
422-
> buffa-codegen/protos/google/protobuf/descriptor.proto
422+
> buffa-descriptor/protos/google/protobuf/descriptor.proto
423423
- >-
424424
{{.GH_RAW}} '{{.SRC}}/compiler/plugin.proto?ref=v{{.PROTO_VER}}'
425-
> buffa-codegen/protos/google/protobuf/compiler/plugin.proto
426-
- wc -l buffa-codegen/protos/google/protobuf/descriptor.proto
427-
buffa-codegen/protos/google/protobuf/compiler/plugin.proto
425+
> buffa-descriptor/protos/google/protobuf/compiler/plugin.proto
426+
- wc -l buffa-descriptor/protos/google/protobuf/descriptor.proto
427+
buffa-descriptor/protos/google/protobuf/compiler/plugin.proto
428428

429429
gen-wkt-types:
430430
desc: >-

benchmarks/Dockerfile.bench-buffa

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY Cargo.toml Cargo.lock ./
1717
COPY buffa/ buffa/
1818
COPY buffa-build/ buffa-build/
1919
COPY buffa-codegen/ buffa-codegen/
20+
COPY buffa-descriptor/ buffa-descriptor/
2021
COPY buffa-test/ buffa-test/
2122
COPY buffa-types/ buffa-types/
2223
COPY protoc-gen-buffa/ protoc-gen-buffa/

0 commit comments

Comments
 (0)