mirror of
https://github.com/zap-proto/rust.git
synced 2026-10-30 15:04:23 +00:00
Cap'n Proto was the canonical name for this Rust implementation. The
ZAP rebrand had only been applied as a directory rename so far —
crate names, schema file extensions, import paths, and binaries all
still said `capnp` / `capnpc`. This commit makes the rebrand real.
Workspace renames:
- crate capnp/ → zap/ (name = "zap")
- crate capnpc/ → zapc/ (name = "zapc")
- crate capnp-futures/ → zap-futures/
- crate capnp-rpc/ → zap-rpc/
Source-file renames:
- *_capnp.rs → *_zap.rs (~12 files: schema_zap.rs, rpc_zap.rs, etc.)
- capnpc-rust.rs → zapc-rust.rs (the codegen binary entry point)
- *.capnp → *.zap (33 schema files)
Identifier renames across the workspace (96 files rewritten):
- `use capnp::` → `use zap::`
- `extern crate capnp` → `extern crate zap`
- `capnp::generated_code!` → `zap::generated_code!`
- `capnp::traits::Owned` → `zap::traits::Owned`
- `capnp::message::...` → `zap::message::...`
- `capnp::Error/Result` → `zap::Error/Result`
- `capnp::Word` → `zap::Word`
- `capnp::primitive_list` → `zap::primitive_list`
- `capnp::any_pointer` → `zap::any_pointer`
- (etc. — see python script in commit history for full list)
Cargo.toml dep keys:
- `capnp = { path = ... }` → `zap = { path = ... }`
- `[dependencies.capnp]` → `[dependencies.zap]`
- `capnpc = { ... }` → `zapc = { ... }`
- Per-crate name= field and bin = "capnpc-rust" → "zapc"
Schema header strip:
- `using Cxx = import "/capnp/c++.capnp";` lines removed (C++ binding
hints; Rust output doesn't need them, and they referenced a system
/usr/include path we don't ship)
- `$Cxx.namespace("capnp::...")` annotations removed
Build-time decoupling for the benchmark:
- Pre-generated `carsales_zap.rs`, `catrank_zap.rs`, `eval_zap.rs` are
now committed in benchmark/. benchmark/build.rs just copies them
into OUT_DIR instead of invoking the schema compiler at build time.
- benchmark/Cargo.toml drops the [build-dependencies] zapc entry.
Building the benchmark needs ONLY the `zap` runtime crate; no
schema-compiler binary, no plugin, no shell-out.
To regenerate the schema-bound .rs from .zap (developer-only step):
cargo build --release --bin zapc
ln -sf zapc target/release/capnpc-rust # plugin discovery name
cd benchmark && PATH=../target/release:$PATH \
capnp compile -orust eval.zap catrank.zap carsales.zap
The `capnp` tool here is the upstream C++ schema-text parser — only
used as a parser frontend at codegen time, never linked into the
benchmark binary. Runtime + build = 100% zap/zapc only.
Verified by:
cargo tree -p benchmark --release → no capnp dep
grep -rE 'capnp|Capnp|CAPNP' . → 0 hits in active source
cargo build -p benchmark --release → clean build, no system tool
bash ./benchmark/bench.sh quick → runs end-to-end
Other workspace members (fill_random_values, addressbook,
wasm-hello-world, capnpc/test fixtures) still use build.rs schema
compilation at build time; they require a `zap` binary in PATH.
That's pre-existing — the upstream Cap'n Proto Rust workspace had the
same requirement against the `capnp` binary. Out of scope for this PR.
76 lines
2.8 KiB
Rust
76 lines
2.8 KiB
Rust
use crate::streaming_zap::receiver;
|
|
use zap_rpc::{rpc_twoparty_zap, twoparty, RpcSystem};
|
|
|
|
use futures::AsyncReadExt;
|
|
use rand::Rng;
|
|
use sha2::{Digest, Sha256};
|
|
|
|
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
use std::net::ToSocketAddrs;
|
|
let args: Vec<String> = ::std::env::args().collect();
|
|
if args.len() != 5 {
|
|
println!(
|
|
"usage: {} client HOST:PORT STREAM_SIZE WINDOW_SIZE",
|
|
args[0]
|
|
);
|
|
return Ok(());
|
|
}
|
|
|
|
let stream_size: u64 = str::parse(&args[3]).unwrap();
|
|
let window_size: u64 = str::parse(&args[4]).unwrap();
|
|
|
|
let addr = args[2]
|
|
.to_socket_addrs()?
|
|
.next()
|
|
.expect("could not parse address");
|
|
|
|
tokio::task::LocalSet::new()
|
|
.run_until(async move {
|
|
let stream = tokio::net::TcpStream::connect(&addr).await?;
|
|
stream.set_nodelay(true)?;
|
|
let (reader, writer) =
|
|
tokio_util::compat::TokioAsyncReadCompatExt::compat(stream).split();
|
|
let mut rpc_network = Box::new(twoparty::VatNetwork::new(
|
|
futures::io::BufReader::new(reader),
|
|
futures::io::BufWriter::new(writer),
|
|
rpc_twoparty_zap::Side::Client,
|
|
Default::default(),
|
|
));
|
|
rpc_network.set_window_size(window_size as usize);
|
|
let mut rpc_system = RpcSystem::new(rpc_network, None);
|
|
let receiver: receiver::Client = rpc_system.bootstrap(rpc_twoparty_zap::Side::Server);
|
|
tokio::task::spawn_local(rpc_system);
|
|
|
|
let zap::capability::RemotePromise { promise, pipeline } =
|
|
receiver.write_stream_request().send();
|
|
|
|
let mut rng = rand::rng();
|
|
let mut hasher = Sha256::new();
|
|
let bytestream = pipeline.get_stream();
|
|
let mut bytes_written: u64 = 0;
|
|
const CHUNK_SIZE: u32 = 4096;
|
|
while bytes_written < stream_size {
|
|
let mut request = bytestream.write_request();
|
|
let body = request.get();
|
|
let this_chunk_size = u64::min(CHUNK_SIZE as u64, stream_size - bytes_written);
|
|
let buf = body.init_bytes(this_chunk_size as u32);
|
|
rng.fill(buf);
|
|
hasher.update(buf);
|
|
request.send().await?;
|
|
bytes_written += this_chunk_size;
|
|
}
|
|
let local_sha256 = hasher.finalize();
|
|
println!(
|
|
"wrote {bytes_written} bytes with hash {}",
|
|
base16::encode_lower(&local_sha256[..])
|
|
);
|
|
bytestream.end_request().send().promise.await?;
|
|
let response = promise.await?;
|
|
|
|
let sha256 = response.get()?.get_sha256()?;
|
|
assert_eq!(sha256, &local_sha256[..]);
|
|
Ok(())
|
|
})
|
|
.await
|
|
}
|