Repository navigation
Releases
v0.4.3: built with mise instead of Bazel; references and real validation in the examples
The generated code and the runtime are the same as in 0.4.2. For a consumer, one thing changes: building the plugin from source (cargo install protoc-gen-protocontract-buffa) needs Rust 1.100.0. The release binaries need no Rust, and their names and checksums-sha256.txt are as before.
Added
examples/glossaryuses references to a service: a catalog service,
Glossaries, keeps glossaries by topic, takes one as a reference in a
message field (Add(Shelf)), and returns one (Open(Topic)gives a
GlossaryRef). The consumer opens its topic and annotates through the
glossary it gets back; the application wires it all. No change to the
plugin or the runtime.
Changed
-
examples/refsvalidates for real:AlarmandTickdeclare
protovalidate rules (a required, non-empty label, a required clock, at
most three backups, no time before the epoch),Alarms.Setfails with
the newALARMS_ERROR_CODE_INVALID_ALARM, and the tests check each rule.
The README describesvalidate=truewith an example. protovalidate's
protos come from mise (http:protovalidate1.2.2, staged by
mise run protos), not from the Buf Schema Registry. -
The example's protovalidate moves to
protovalidate-buffa0.8.0 with
protoc-gen-protovalidate-buffa0.11.0 (released together:time
replaceschrono). TheValidateimpl thatvalidate=trueemits is
unchanged and builds against both. -
Every dependency is declared once, in the root
[workspace.dependencies],
and an unused dependency fails the build (cargo::unused_dependencies,
Cargo 1.100). Nothing changes for a consumer of the crates. -
The repository builds with Cargo and mise
instead of Bazel:mise run gateis the gate (generated files, clippy,
rustfmt, cargo-deny, buf lint and format, markdownlint, tests),
mise run generaterefreshes the golden files and the examples, and
mise run formatformats in place. The release workflow runs the gate
on the same six platforms, the golden check now on Windows ARM64 too.
The plugin's binaries, their names, andchecksums-sha256.txtare
unchanged, so thebazel_utilscatalog and a misegithub:backend
keep working; the crates are unchanged. -
The dependency check is cargo-deny (
deny.toml): advisories as before,
plus licences, duplicate crates, and sources. -
The pinned toolchain is Rust 1.100.0 (was 1.99.1), and building the
plugin from source (cargo install protoc-gen-protocontract-buffa) now
needs it. The runtime and the generated code still need Rust 1.92; the
generated code is the same. -
Cargo.locktakes the newest version of each dependency that is at
least two days old (tokio 1.54.1, syn 3.0.10, and others), which the
plugin's release binaries are built with. The version ranges in
Cargo.toml, what a consumer resolves against, are unchanged.
Removed
- The Bazel module
protocontract_buffa(MODULE.bazeland every
BUILD.bazel). No consumer took it throughbazel_dep; a Bazel build
takes the plugin from thebazel_utilscatalog as before.
v0.4.2: a dropped bridge stream starts no more work
Fixed
- A stream that
OffloadorBlockingpulls from a sync iterator on the
blocking pool (anOffloadreply stream, aBlocking::feedrequest
stream) no longer calls the iterator'snextonce its reader is gone.
Before, after each item was handed over the pull callednextagain
without checking, and only the send after it found the stream dropped:
one more unit of the implementation's work ran for nobody, possibly
after the caller had dropped the stream and moved on. Anextalready
running when the stream is dropped still finishes.
Changed
- Build pin:
bazel_utils0.4.2. It adds plugin versions to its catalog
and changes nothing this build uses; the generated code is the same.
Upgrading
No code change is needed: update protocontract to 0.4.2
(cargo update -p protocontract). The plugin's generated code is the same
as in 0.4.1.
v0.4.1: the docs of reference modules link their type
Fixed
- The doc comment on the module of a reference type links the type through
that module ([ClockRef](clock_ref::ClockRef)): the comment sits
outside the module, where the type is not in scope, so rustdoc with
warnings denied failed withunresolved link. Regenerate to get it.
v0.4.0: references to a service in messages, requests, and replies
Added
- References to a service. An empty message marked
option (protocontract.v1.service) = "pkg.Service";stands for an
implementation of that service: the plugin emits a type for it
(<module>::<Name>, e.g.clock_ref::ClockRef) that holds the
implementation in the form it was given, and buffa maps the message to it
with anextern_path, so a field, a request, or a reply can carry an
implementation. The receiver takes the form it needs withto_sync,
to_async_inline, orto_async_offload. A reference does not survive
encoding: decoded it isRuntimeCode::Unboundwhen used, and it has no
JSON form. The option is declared inprotocontract/v1/options.proto,
shipped in theprotocontractcrate underproto/. - Plugin parameters
json=<true|false>andvalidate=<true|false>: with
buffa'sjson=true, reference types get serde impls too; next to
protoc-gen-protovalidate-buffa, they implementValidate(always
valid), which it calls on every message field. RuntimeCode::UnboundandRuntimeCode::NoRuntime.- Every
Dyn<Service>Asynchandle hasptr_eq: whether two handles hold
the same implementation. examples/refs: a reference in a field, a list, a request, and a reply.
Changed
RuntimeCodehas two more variants, so an exhaustivematchon it no
longer compiles: add an arm forUnboundandNoRuntime, or a
wildcard.- Build pins:
bazel_utils0.4.0 and Buf CLI v1.74.0. The pins alone do not
change the generated code. - buildifier, markdownlint, buf lint, rustfmt, and cargo-audit now run on
Windows too, and the golden checks of the generated code on Windows
ARM64: the reasons they were off are gone (bazel_utilsruns its test
scripts on Windows since 0.3.0, and catalogs every plugin there). Only
the rustdoc tests stay off on Windows, where rules_rust cannot link them;
cargo testruns them. The release workflow names each of these tests,
so a platform that cannot run one fails.
Upgrading from 0.3
- Take
protocontract = "0.4"and the 0.4.0 plugin together. - An exhaustive
matchonRuntimeCodeneeds arms forUnboundand
NoRuntime, or a wildcard. - Nothing else changes in the generated code of an existing contract but
the newDyn<Service>Async::ptr_eq. - To use references: import
protocontract/v1/options.proto(in the
protocontractcrate, underproto/), mark an empty message with
option (protocontract.v1.service) = "pkg.Service";, and map it to
<mount>::<module>::<Name>with the sameextern_pathin both
protoc-gen-buffaand this plugin.
v0.3.1: ready for crates.io, dependency ranges, rustfmt in the gate
Added
protocontractandprotoc-gen-protocontract-buffaare ready for
crates.io: keywords, categories, the license text in each package, and
docs.rs buildsprotocontractwith every feature, so it showsOffload
andBlocking. A logo for the README and the rustdoc pages.bazel test //...checks the formatting of the hand-written Rust
(//rust:fmt, rustfmt of the pinned toolchain).
Changed
- The workspace takes its dependencies as caret ranges instead of exact
pins (buffa = "0.9.2", was"=0.9.2"), so a consumer of
protocontractis not held to one version of buffa, futures-core, or
tokio.Cargo.lockstill fixes the versions this repository builds and
tests. - The README takes
protocontractfrom crates.io
(protocontract = "0.3") and the plugin withcargo install, links to
GitHub by absolute URLs, and corrects the names of the runtime's codes
(RuntimeCode::Panicked, notPANICKED), thestrategy: allof the
examplebuf.gen.yaml, and how the static release binaries are built.
Consumers of the generated code and the runtime change nothing: the
generated code, the runtime API, and the plugin parameters are the same
as in 0.3.0.
v0.3.0: renamed to protocontract-buffa and protoc-gen-protocontract-buffa
Changed
- Breaking: the project is renamed to protocontract-buffa. The
repository isgithub.com/sonalect/protocontract-buffa.rs(GitHub
redirectssonalect/proto-contract.rs), the plugin and its binary are
protoc-gen-protocontract-buffa(wasprotoc-gen-contract-rust), and
the Bazel module isprotocontract_buffa(wascontract). The
generated code is the same except for its header,
// @generated by protoc-gen-protocontract-buffa. DO NOT EDIT.; the
runtime crate keeps its name,protocontract, and the output files keep
theirs (<stem>.__contract.rs,<pkg>.mod.rs). - The minimum Rust version of
protocontractand of the generated code is
1.92 (it was 1.99.1 in 0.2.2): 1.92 is the oldest rustc that compiles the
generated handles of bidi-streaming methods. The release workflow builds
and tests both with Rust 1.92. The plugin, built from source with
cargo install, needs Rust 1.99.1.
What a consumer changes
buf.gen.yaml:local: protoc-gen-protocontract-buffainstead of
local: protoc-gen-contract-rust.- The
protocontractgit dependency:
git = "https://github.com/sonalect/protocontract-buffa.rs", tag = "v0.3.0". - Release binaries are named
protoc-gen-protocontract-buffa-v0.3.0-<os>-<arch>; a script or catalog
that downloads them takes the new names. - No Rust code changes: no renamed items, no new signatures, no plugin
parameter changes.
v0.2.2: Rust 1.99.1 and refreshed build pins
Changed
- Build pins refreshed:
bazel_utils0.3.4 (a prebuiltprotocon
Windows ARM64 instead of one compiled from source), Rust toolchain 1.99.1,
syn3.0.9, andtokio1.53.3. The generated code is unchanged. - The minimum Rust version (
rust-version) is 1.99.1.
Consumers of the generated code and the runtime change nothing in their
code: no renamed items, no new signatures, no plugin parameter changes.
They need Rust 1.99.1 or newer to build protocontract 0.2.2.
v0.2.1: refreshed build pins and Ubuntu 26.04 release builds
Changed
- The plugin's release binaries are built and checked on Ubuntu 26.04 for
Linux (amd64 and arm64). They stay static musl binaries. - Build pins refreshed: Bazel 9.3.0,
bazel_utils0.3.2,
protoc-gen-connect-rustv0.9.1 for the golden generate, andsyn3.0.7.
The generated code is unchanged.
Consumers of the generated code and the runtime change nothing: no renamed
items, no new signatures, no plugin parameter changes.
v0.2.0: open error codes, the protocontract crate, and a worked example
One error type for every contract, with codes the contract declares itself, a renamed runtime crate, and an example of a provider and a consumer that know only the generated API.
Added
examples/glossary: a contract in use. A proto with a service and its
error codes, the crate generated from it, a provider that implements the
traits, a consumer that calls them without knowing the provider, and the
application that wires the two (cargo run -p glossary-app).- Open error codes:
protocontract::ErrorCode, implemented by every protobuf
enum thatprotoc-gen-buffagenerates and by hand for a Rust enum, and
protocontract::Code, a code with its type erased. A contract declares the
codes its callers may branch on as anenumnext to itsservice. protocontract::Fault, the trait of a failure (code,retryable,
backtrace), andprotocontract::Failure, the ready-made fault (code,
message,with_retryable,with_source, a captured backtrace). Any
Faultconverts intoprotocontract::Errorwith?.Error::is,code_as,retryable,stack,backtrace,
downcast_ref, andcontext; theprotocontract::Contextextension adds a
stack frame to the error of aResult(.context("load"),
.with_context(|| …)).- The plugin finds a service's error-code enum by name
(GreeterErrorCode, thenGreeterServiceErrorCode, in the package of
GreeterService), emits the aliasGreeterServiceErrorCodenext to the
traits, and names it in their rustdoc. A service without such an enum is
generated as before; a message or enum already named like the alias
fails the run. protocontract::RuntimeCode:PANICKED(Offload),CANNOT_BLOCK
(Blockinginside a current-thread runtime),CANCELLED(a blocking
task dropped by its runtime).
Changed
- Breaking. The runtime crate
contractis nowprotocontract
(directoryrust/protocontract, Bazel target//rust/protocontract).
Depend onprotocontractand replacecontract::paths; the plugin's
runtime=default is::protocontract. A crate that mounts the traits
may now name their modulecontract. - Breaking.
contract::Statusis nowprotocontract::Error: every
generated method returnsResult<_, protocontract::Error>. Build one with
Error::new(code, message), wherecodeis a value of the contract's
error enum, or from aFailureor aFaultof your own. - Breaking. The bridges report
RuntimeCodevalues instead of
INTERNALandFAILED_PRECONDITION. - The runtime depends on
buffa(forErrorCodeon its enums) instead of
buffa-types. - Each method's parameter is named after its message in snake case
(word: Word,greet_request: GreetRequest), plural for an inbound
stream (items), instead ofrequestandrequests. Implementations
are unaffected: Rust does not bind parameter names.
Removed
- Breaking. The fixed
google.rpc.Codeset (contract::Codeas an
enum) and the per-code constructors (Status::invalid_argument, …):
codes are open (see Added). - Breaking.
Status::with_details,details, andinto_parts: the
calls stay in one process, so the wire payloads ofgoogle.rpc.Status
have no use. - Breaking.
PartialEqon the error: a fault cannot be compared.
Compare codes (error.is(code)) instead.
Upgrading from 0.1.0
- Depend on
protocontractinstead ofcontract, from tagv0.2.0,
and replacecontract::paths withprotocontract::. A plugin run
withruntime=set keeps its path; without it the generated code now
names::protocontract. - Rename
StatustoErrorin implementations and callers. - Declare the codes of each service as a proto enum named
<Service>ErrorCodenext to it (forservice Greeter,
enum GreeterErrorCode), and replaceStatus::invalid_argument(msg)
and the other per-code constructors with
Error::new(GreeterErrorCode::…, msg); useFailurefor a retryable
failure or one with a source. - Branch with
error.is(code)orerror.code_as::<GreeterErrorCode>()
instead of comparingerror.code()withCode::…; compare codes, not
errors, in tests. - Code that matched
INTERNALorFAILED_PRECONDITIONfromOffloador
BlockingmatchesRuntimeCode::Panickedor
RuntimeCode::CannotBlock.
v0.1.0: plain Rust sync and async traits for protobuf services
First release.
Added
-
protoc-gen-contract-rust, a protoc plugin that emits, per protobuf
service:<Service>Sync, whose methods returnResult<Reply, contract::Status>.
It is dyn-compatible:Arc<dyn <Service>Sync>.<Service>Async, whose methods return
impl Future<Output = Result<Reply, Status>> + Send, so implementations
write plainasync fnand generic callers pay no allocation.Dyn<Service>Async, a cloneable handle (new,from_arc) that holds
any<Service>Asyncimplementation behind dynamic dispatch, implements
the trait itself, and implementsDebug.
Requests are taken by value and replies returned owned. Comments in the
.protobecome rustdoc. -
Streaming methods of every kind: server, client, and bidirectional. The
sync form takes and returnscontract::BoxIter<'static, _>, the async
formimpl contract::Stream; items areResult<_, Status>, a reply
stream sits inside the call'sResult, and no stream borrows the
service. -
Bridges between the forms, for every kind of method:
contract::Inline
(a sync implementation's async form, run insidepoll),
contract::Offload(the same on tokio's blocking pool), and
contract::Blocking(an async implementation's sync form).Offload
andBlockingcome with the runtime'stokiofeature.Blockinginside
a current-thread runtime fails withFAILED_PRECONDITIONinstead of
panicking, and every bridge ends a stream after its firstErr. -
Plugin parameters
buffa_module=(crateincluded),extern_path=,
file_per_package, andelement_memory_limit=, as
protoc-gen-connect-rustreads them, plusruntime=for the path of the
runtime crate andgate_tokio_feature[=<name>]to put theOffloadand
Blockingimpls behind a Cargo feature. Message paths are absolute and
matchprotoc-gen-buffa0.9.2. Output is a<stem>.__contract.rsper
proto and a<pkg>.mod.rsstitcher per package for
protoc-gen-buffa-packaging(filter=services), or one
<dotted.pkg>.rsper package withfile_per_package. The output can sit
next toprotoc-gen-connect-rust's, in the same modules. -
The plugin refuses, with a message that names the proto element: a
message type no mapping covers, two methods with one Rust name, a
generated name that another item of the package's module (buffa,
connect-rust, or Contract) already has, and any unknown parameter. -
Runtime crate
contract:Status(code, message,Anydetails; a
mirror ofgoogle.rpc.Status),Code(the 17google.rpc.Codevalues),
BoxFuture,BoxIter,BoxStream,Stream(re-exported from
futures-core),IterStream,Inline, and withtokioChannelStream,
Offload, andBlocking. -
Release binaries of the plugin for Linux, macOS, and Windows on amd64
and arm64, static where the platform allows (macOS links only system
libraries), with their sha256 inchecksums-sha256.txt.