Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions examples/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ buf_lint_test(
#
# Output naming is deterministic given the proto file path: a file at
# `proto/anthropic/connectrpc/examples/greet/v1/greet.proto` becomes
# `anthropic.connectrpc.examples.greet.v1.greet.rs`. The packaging plugin
# emits a `mod.rs` that nests `pub mod` blocks matching the proto's
# `package` declaration and `include!`s the per-file output as a sibling.
# `anthropic.connectrpc.examples.greet.v1.greet.rs` (buffa message types)
# plus the `....greet.__view.rs` companion (zero-copy views), and
# `....greet.__connect.rs` (connectrpc service stubs). The packaging
# plugin emits a per-package `<pkg>.mod.rs` stitcher that `include!`s the
# per-file outputs as siblings, and a root `mod.rs` that nests `pub mod`
# blocks matching the proto's `package` declaration.
#
# Two output trees are produced — one with buffa message types, one with
# connectrpc service stubs — because the plugins emit colliding filenames
# (both `mod.rs` and `<package>.rs`).
# (both trees get `mod.rs` and `<pkg>.mod.rs`).
genrule(
name = "gen_code",
srcs = ["proto/anthropic/connectrpc/examples/greet/v1/greet.proto"],
outs = [
"generated/buffa/mod.rs",
"generated/buffa/anthropic.connectrpc.examples.greet.v1.mod.rs",
"generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.rs",
"generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.__view.rs",
"generated/connect/mod.rs",
"generated/connect/anthropic.connectrpc.examples.greet.v1.greet.rs",
"generated/connect/anthropic.connectrpc.examples.greet.v1.mod.rs",
"generated/connect/anthropic.connectrpc.examples.greet.v1.greet.__connect.rs",
],
cmd = """
mkdir -p $(@D)/generated/buffa $(@D)/generated/connect
Expand Down Expand Up @@ -81,9 +87,12 @@ genrule(
],
outs = [
"generated_buf/buffa/mod.rs",
"generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.mod.rs",
"generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.greet.rs",
"generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.greet.__view.rs",
"generated_buf/connect/mod.rs",
"generated_buf/connect/anthropic.connectrpc.examples.greet.v1.greet.rs",
"generated_buf/connect/anthropic.connectrpc.examples.greet.v1.mod.rs",
"generated_buf/connect/anthropic.connectrpc.examples.greet.v1.greet.__connect.rs",
],
cmd = """
mkdir -p $(@D)/generated_buf/buffa $(@D)/generated_buf/connect
Expand Down Expand Up @@ -126,22 +135,34 @@ sh_test(
args = [
"$(location :generated/buffa/mod.rs)",
"$(location :generated_buf/buffa/mod.rs)",
"$(location :generated/buffa/anthropic.connectrpc.examples.greet.v1.mod.rs)",
"$(location :generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.mod.rs)",
"$(location :generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.rs)",
"$(location :generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.greet.rs)",
"$(location :generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.__view.rs)",
"$(location :generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.greet.__view.rs)",
"$(location :generated/connect/mod.rs)",
"$(location :generated_buf/connect/mod.rs)",
"$(location :generated/connect/anthropic.connectrpc.examples.greet.v1.greet.rs)",
"$(location :generated_buf/connect/anthropic.connectrpc.examples.greet.v1.greet.rs)",
"$(location :generated/connect/anthropic.connectrpc.examples.greet.v1.mod.rs)",
"$(location :generated_buf/connect/anthropic.connectrpc.examples.greet.v1.mod.rs)",
"$(location :generated/connect/anthropic.connectrpc.examples.greet.v1.greet.__connect.rs)",
"$(location :generated_buf/connect/anthropic.connectrpc.examples.greet.v1.greet.__connect.rs)",
],
data = [
":generated/buffa/mod.rs",
":generated/buffa/anthropic.connectrpc.examples.greet.v1.mod.rs",
":generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.rs",
":generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.__view.rs",
":generated/connect/mod.rs",
":generated/connect/anthropic.connectrpc.examples.greet.v1.greet.rs",
":generated/connect/anthropic.connectrpc.examples.greet.v1.mod.rs",
":generated/connect/anthropic.connectrpc.examples.greet.v1.greet.__connect.rs",
":generated_buf/buffa/mod.rs",
":generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.mod.rs",
":generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.greet.rs",
":generated_buf/buffa/anthropic.connectrpc.examples.greet.v1.greet.__view.rs",
":generated_buf/connect/mod.rs",
":generated_buf/connect/anthropic.connectrpc.examples.greet.v1.greet.rs",
":generated_buf/connect/anthropic.connectrpc.examples.greet.v1.mod.rs",
":generated_buf/connect/anthropic.connectrpc.examples.greet.v1.greet.__connect.rs",
],
)

Expand All @@ -152,9 +173,12 @@ rust_library(
srcs = [
"src/lib.rs",
"generated/buffa/mod.rs",
"generated/buffa/anthropic.connectrpc.examples.greet.v1.mod.rs",
"generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.rs",
"generated/buffa/anthropic.connectrpc.examples.greet.v1.greet.__view.rs",
"generated/connect/mod.rs",
"generated/connect/anthropic.connectrpc.examples.greet.v1.greet.rs",
"generated/connect/anthropic.connectrpc.examples.greet.v1.mod.rs",
"generated/connect/anthropic.connectrpc.examples.greet.v1.greet.__connect.rs",
],
crate_root = "src/lib.rs",
edition = "2021",
Expand Down
82 changes: 78 additions & 4 deletions examples/bazel/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/bazel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ publish = false
path = "stub.rs"

[dependencies]
buffa = { version = "0.6.0", features = ["json"] }
connectrpc = { version = "0.6.1", default-features = false, features = ["server", "client"] }
buffa = { version = "0.7.0", features = ["json"] }
connectrpc = { version = "0.7.0", default-features = false, features = ["server", "client"] }
futures = "0.3"
http-body = "1"
serde = { version = "1", features = ["derive"] }
Expand Down
21 changes: 13 additions & 8 deletions examples/bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ work cleanly under Bazel. A `bazel test //...` invocation:

1. Runs `protoc` with all three plugins (`protoc-gen-buffa`,
`protoc-gen-buffa-packaging`, `protoc-gen-connect-rust`) via a
`genrule`, producing four `.rs` files. A second `genrule` runs the
`genrule`, producing seven `.rs` files. A second `genrule` runs the
same plugins through `buf generate` (driven by the `rules_buf`
toolchain) and a `sh_test` proves the two output trees are
byte-identical.
2. Pulls `buffa`, `connectrpc`, and their transitive deps from crates.io
via `rules_rust` + `crates_universe`.
3. Compiles a `rust_library` whose srcs include `src/lib.rs` plus the
four generated files.
seven generated files.
4. Runs three `rust_test`s that exercise the generated message types
(construction, encode/decode round-trip via `buffa::Message`) and
the connectrpc service-stub constants.
Expand Down Expand Up @@ -89,15 +89,20 @@ plugins and emit byte-identical output (verified by

Output naming is deterministic from the proto file path: a file at
`proto/anthropic/connectrpc/examples/greet/v1/greet.proto` becomes
`anthropic.connectrpc.examples.greet.v1.greet.rs`. The packaging plugin
emits a `mod.rs` that nests `pub mod` blocks matching the proto's
`package` declaration and `include!`s the per-file output as a sibling.
`anthropic.connectrpc.examples.greet.v1.greet.rs` (message types) plus
the `....greet.__view.rs` companion (zero-copy views) from
`protoc-gen-buffa`, and `....greet.__connect.rs` (service stubs) from
`protoc-gen-connect-rust`. The packaging plugin emits a per-package
`<pkg>.mod.rs` stitcher that `include!`s the per-file outputs as
siblings, and a root `mod.rs` that nests `pub mod` blocks matching the
proto's `package` declaration.

Two output trees per genrule — one with buffa message types, one with
connectrpc service stubs — because the plugins emit colliding filenames
(both `mod.rs` and `<package>.rs`). The packaging plugin runs twice,
once over each tree (the second invocation passes `filter=services` so
files without services are skipped from the connect output).
(both trees get `mod.rs` and `<pkg>.mod.rs`). The packaging plugin runs
twice, once over each tree (the second invocation passes
`filter=services` so files without services are skipped from the
connect output).

The generated `mod.rs` files use sibling-relative `include!("foo.rs")`,
so consuming the output requires no `env!("OUT_DIR")` indirection.
Expand Down
Loading