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
9 changes: 5 additions & 4 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ inputs:
required: true
protoc:
description: >-
Install protoc. Required by any job that builds kit-rpc (buffa-build
shells out to protoc; the .proto schemas use Edition 2023, needing
protoc >= 25, newer than apt's protobuf-compiler). Set "false" for jobs
that never compile kit-rpc (e.g. the keystore-only matrix).
Install protoc. Required by any job that runs kit-rpc-codegen
(buffa-build shells out to protoc; the .proto schemas use Edition 2023,
needing protoc >= 25, newer than apt's protobuf-compiler). Building
kit-rpc needs no protoc. Set "false" for jobs that never run the
generators.
required: false
default: "true"
protoc-version:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ jobs:
- uses: ./.github/actions/setup-rust
with:
cache-prefix: "rust-proto-generated"
targets: "wasm32-unknown-unknown"

- name: Regenerate and compare
run: bash scripts/check-generated-fresh.sh
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- `kit-rpc` compiles its checked-in generated code as ordinary source: it has no build script and no build dependencies, so no crate that depends on it builds `buffa-build`, `buffa-codegen`, `buffa-descriptor`, `connectrpc-build`, `connectrpc-codegen`, `prettyplease` or `anyhow` for it. The generators moved to the unpublished `kit-rpc-codegen` crate, which `scripts/regen-rpc-proto.sh` and `scripts/regen-transport-proto.sh` run.
- `kit checkout` in a repository with no `.kit/index` file, as `kit clone --no-checkout` leaves it, is the first checkout, as in git: nothing is tracked yet, so no file counts as a local change and no tracked path is removed. A file the checkout would write over still refuses it.
- **Breaking:** the ssh `ListRefs` request and reply page, as Connect's do (SPEC-TRANSPORT §4.2.3): `kit serve` returns at most 1,000 refs a page, and `kit+ssh` remotes read every page. A new `kit serve` refuses a `ListRefs` with no `page_size`, so a client from before this change cannot list refs on it and has to be upgraded; a new client against an old `kit serve` works as before, up to the old limit of one frame.
- `kit_core::protocol::RefListing::OneFrame`, `kit_sync::push::MAX_TAG_LISTING_BYTES` and `TagPushRejection::TooManyTags` are removed: no remote lists in one frame any more, so a tag push no longer refuses a create over a listing bound. A push of tags to a `kit serve` that predates paging is not bounded either, so a tag listing there that grows past one frame fails for every client until that server is upgraded. The `tag listing failed` message no longer says "possibly too many tags".
Expand Down
3 changes: 2 additions & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ Each Total is Source plus Tests plus Generated.
Generated code is a documented exception to the rule against checked-in
generated output. The code generator needs `protoc`, and many hosts ship a `protoc` too old
for protobuf edition 2023. A normal build needs neither, because
`rust/crates/kit-rpc/generated/` stays in the tree. The
`rust/crates/kit-rpc/generated/` stays in the tree and compiles as ordinary
source. The generators live in the `kit-rpc-codegen` tool crate. The
README in that directory gives the reason.
`scripts/check-generated-fresh.sh` regenerates the code and fails when the
checked-in copy differs. Only `kit-rpc` holds generated code.
Expand Down
2 changes: 1 addition & 1 deletion docs/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ Review the file list of a crate with `cargo package --list -p <crate>`.

| Publishes to crates.io | Stays off crates.io (`publish = false`) |
|---|---|
| In publish (dependency) order: `kit-core`, `kit-rpc`, `kit-attest`, `kit-keystore`, `kit-transport-file`, `kit-serve`, `kit-client`, `kit-sync`, `kit-transport-memory`, `kit-transport-connect`, `kit-transport-s3`, `kit-transport-ssh`, `kit-git-bridge`, `libkit`, and `kit-bin` (so `cargo install kit-bin` works) | `kit-sign-file`, `kit-test-util`, `kit-formal-conformance`, `fuzz`, `benches`, and `kit-wasm`, which `release.yml` publishes to npm. |
| In publish (dependency) order: `kit-core`, `kit-rpc`, `kit-attest`, `kit-keystore`, `kit-transport-file`, `kit-serve`, `kit-client`, `kit-sync`, `kit-transport-memory`, `kit-transport-connect`, `kit-transport-s3`, `kit-transport-ssh`, `kit-git-bridge`, `libkit`, and `kit-bin` (so `cargo install kit-bin` works) | `kit-sign-file`, `kit-test-util`, `kit-formal-conformance`, `kit-rpc-codegen`, `fuzz`, `benches`, and `kit-wasm`, which `release.yml` publishes to npm. |

The published crates depend only on each other, forming a closed,
dependency-ordered set. The table lists them in that order.
Expand Down
10 changes: 8 additions & 2 deletions rust/Cargo.lock

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

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"crates/kit-core",
"crates/kit-test-util",
"crates/kit-rpc",
"crates/kit-rpc-codegen",
"crates/kit-attest",
"crates/kit-keystore",
"crates/kit-git-bridge",
Expand Down
23 changes: 23 additions & 0 deletions rust/crates/kit-rpc-codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Regenerates the protocol code that `kit-rpc` checks in under `generated/`.
# Run by `scripts/regen-rpc-proto.sh` and `scripts/regen-transport-proto.sh`.
#
# `publish = false`, never a dependency of anything. Keeping the code
# generators here keeps `buffa-build`, `connectrpc-build` and their tree out of
# the build of every crate that depends on `kit-rpc`.
[package]
name = "kit-rpc-codegen"
description = "Regenerates the protocol code kit-rpc checks in"
publish = false
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true
authors.workspace = true

[lints]
workspace = true

[dependencies]
buffa-build = "0.9.2"
connectrpc-build = "0.9.0"
107 changes: 107 additions & 0 deletions rust/crates/kit-rpc-codegen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//! Regenerates the protocol code that `kit-rpc` checks in.
//!
//! `kit-rpc-codegen rpc` writes `generated/` from the signer, SSH, verify and
//! common schemas. `kit-rpc-codegen transport` writes `generated/transport/`
//! from the canonical transport and health schemas. Both need `protoc` 27 or
//! newer on `PATH` (or in `PROTOC`), because the schemas use protobuf edition
//! 2023. Run them through `scripts/regen-rpc-proto.sh` and
//! `scripts/regen-transport-proto.sh`.

use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};

type Result<T> = std::result::Result<T, Box<dyn Error>>;

fn main() -> Result<()> {
// `rust/crates/kit-rpc-codegen` -> `rust/crates` -> `rust` -> repo root.
let repo = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../..");
let crate_dir = repo.join("rust/crates/kit-rpc");
match std::env::args().nth(1).as_deref() {
Some("rpc") => rpc(&repo, &crate_dir),
Some("transport") => transport(&repo, &crate_dir),
_ => Err("usage: kit-rpc-codegen <rpc|transport>".into()),
}
}

/// Removes the `.rs` files directly under `dir` and makes sure it exists.
fn clear(dir: &Path) -> Result<()> {
fs::create_dir_all(dir)?;
for entry in fs::read_dir(dir)? {
let path = entry?.path();
if path.is_file() && path.extension().is_some_and(|e| e == "rs") {
fs::remove_file(path)?;
}
}
Ok(())
}

fn rpc(repo: &Path, crate_dir: &Path) -> Result<()> {
let proto_dir = crate_dir.join("proto");
// The shared ref types (`kit.common.v1.RefExpectation` and `RefEntry`)
// live in the repository's canonical proto root.
let common_dir = repo.join("proto");
let files = [
proto_dir.join("kit/rpc/v1/common.proto"),
proto_dir.join("kit/rpc/v1/signer/signer.proto"),
proto_dir.join("kit/rpc/v1/ssh/ssh.proto"),
proto_dir.join("kit/rpc/v1/verify/verify.proto"),
common_dir.join("kit/common/v1/refs.proto"),
];
let out = crate_dir.join("generated");
clear(&out)?;
buffa_build::Config::new()
.files(&files)
.includes(&[&proto_dir, &common_dir])
.include_file("_includes.rs")
// `arbitrary::Arbitrary` derives, gated behind kit-rpc's opt-in
// `arbitrary` feature, for the fuzz harness.
.generate_arbitrary(true)
.out_dir(&out)
.compile()?;
Ok(())
}

fn transport(repo: &Path, crate_dir: &Path) -> Result<()> {
let root = repo.join("proto");
let files = [
root.join("kit/transport/v1/transport.proto"),
root.join("grpc/health/v1/health.proto"),
];
let out = crate_dir.join("generated/transport");
clear(&out)?;
connectrpc_build::Config::new()
.files(&files)
.includes(&[&root])
.include_file("_connectrpc.rs")
.out_dir(&out)
.emit_rerun_directives(false)
.compile()?;
gate_bindings(&out)
}

/// Keeps one generated message tree while letting a consumer leave out the
/// Connect runtime: the service bindings compile only with kit-rpc's
/// `transport` feature.
fn gate_bindings(out: &Path) -> Result<()> {
const GATED: [(&str, &str); 2] = [
(
"kit.transport.v1.mod.rs",
"include!(\"kit.transport.v1.transport.__connect.rs\");",
),
(
"grpc.health.v1.mod.rs",
"include!(\"grpc.health.v1.health.__connect.rs\");",
),
];
for (module, include) in GATED {
let path: PathBuf = out.join(module);
let source = fs::read_to_string(&path)?;
if !source.contains(include) {
return Err(format!("{module} has no `{include}` to gate").into());
}
let gated = format!("#[cfg(feature = \"transport\")]\n{include}");
fs::write(&path, source.replace(include, &gated))?;
}
Ok(())
}
21 changes: 7 additions & 14 deletions rust/crates/kit-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ categories = ["encoding", "data-structures"]
readme = "README.md"
# Ship the sources only. The tests use goldens and helpers that live outside
# this package, so they cannot run from a published copy.
include = ["src/**", "/build.rs", "/generated/**", "/proto/**", "/README.md", "/LICENSE-APACHE", "/LICENSE-MIT"]
include = ["src/**", "/generated/**", "/proto/**", "/README.md", "/LICENSE-APACHE", "/LICENSE-MIT"]
version.workspace = true
edition.workspace = true
rust-version.workspace = true
Expand All @@ -22,7 +22,7 @@ authors.workspace = true
# only.
[lints.clippy]
# Drop pedantic + nursery + cargo for this crate. The buffa-generated
# code (~640 KiB into $OUT_DIR) inherits docstrings from our .proto
# code (~640 KiB under generated/) inherits docstrings from our .proto
# files and uses code patterns that pedantic flags hundreds of times.
# We keep `clippy::all` (the correctness + style baseline) and our
# own hand-written code in src/ stays under it.
Expand All @@ -40,7 +40,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ["cfg(kani)"] }

[features]
# Shared wasm-clean TransportService and health messages and Connect bindings.
transport = ["transport-messages", "dep:connectrpc", "dep:connectrpc-build"]
transport = ["transport-messages", "dep:connectrpc"]
# Canonical messages without Connect runtime bindings (no tokio dependency).
transport-messages = ["dep:serde", "buffa/json"]
# Opt-in `arbitrary::Arbitrary` derives on all generated wire types,
Expand Down Expand Up @@ -73,19 +73,12 @@ thiserror = "2.0.21"
# features on, so their builds still get `pack-zstd` via that edge.
kit-core = { version = "=0.10.0", path = "../kit-core", default-features = false }

[build-dependencies]
connectrpc-build = { version = "0.9.0", optional = true }
buffa-build = "0.9.2"

# cargo-machete scans only the Rust sources under src/. It cannot see these
# dependencies, so it lists them as unused. Each one is used.
# - serde, connectrpc and arbitrary: the generated modules under generated/
# name `::serde`, `::connectrpc` and `::arbitrary::Arbitrary`. build.rs
# stages them into OUT_DIR, and src/lib.rs includes them.
# - buffa-build and connectrpc-build: build.rs calls them when
# KIT_RPC_CODEGEN is set.
# dependencies, so it lists them as unused. Each one is used: the generated
# modules under generated/ name `::serde`, `::connectrpc` and
# `::arbitrary::Arbitrary`, and src/lib.rs includes them.
[package.metadata.cargo-machete]
ignored = ["arbitrary", "buffa-build", "connectrpc", "connectrpc-build", "serde"]
ignored = ["arbitrary", "connectrpc", "serde"]

[package.metadata.docs.rs]
# Build docs with every feature so docs.rs renders the feature-gated API.
Expand Down
9 changes: 5 additions & 4 deletions rust/crates/kit-rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ Both protocols use the same length-prefixed framing:
[u32 LE length][N bytes protobuf-encoded Frame]
```

Generated code is vendored (not built fresh from `.proto` on every build);
regenerate it with `scripts/regen-rpc-proto.sh` after editing a schema.
Generated code is checked in under `generated/` and compiled as ordinary
source: kit-rpc has no build script and no build dependencies. Regenerate it
with `scripts/regen-rpc-proto.sh` after editing a schema.

## Shared Connect transport bindings

Expand All @@ -52,5 +53,5 @@ do not enable it. Refresh `generated/transport/` with
For runtime-independent clients, enable `transport-messages` instead. It
exposes the same message types at the same paths, without service bindings,
ConnectRPC or tokio. The `transport` feature includes this feature. Both
features stage the same generated files; the build script gates only the
binding includes, including during regeneration. `kit-client` uses this surface.
features compile the same generated files; the generator gates only the
binding includes. `kit-client` uses this surface.
Loading
Loading