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.
54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
use zap::{message, serialize, Word};
|
|
|
|
#[test]
|
|
pub fn serialize_read_message_no_alloc() {
|
|
let mut buffer = [zap::word(0, 0, 0, 0, 0, 0, 0, 0); 200];
|
|
{
|
|
let allocator =
|
|
message::SingleSegmentAllocator::new(zap::Word::words_to_bytes_mut(&mut buffer[..]));
|
|
let mut msg = message::Builder::new(allocator);
|
|
msg.set_root("hello world!").unwrap();
|
|
|
|
let mut out_buffer = [zap::word(0, 0, 0, 0, 0, 0, 0, 0); 256];
|
|
|
|
serialize::write_message(Word::words_to_bytes_mut(&mut out_buffer), &msg).unwrap();
|
|
|
|
let mut read_buffer = [zap::word(0, 0, 0, 0, 0, 0, 0, 0); 256];
|
|
|
|
let reader = serialize::read_message_no_alloc(
|
|
&mut Word::words_to_bytes(&out_buffer),
|
|
Word::words_to_bytes_mut(&mut read_buffer),
|
|
message::ReaderOptions::new(),
|
|
)
|
|
.unwrap();
|
|
|
|
let s: zap::text::Reader = reader.get_root().unwrap();
|
|
assert_eq!("hello world!", s);
|
|
}
|
|
}
|
|
|
|
#[repr(C, align(8))]
|
|
struct BufferWrapper<const N: usize> {
|
|
bytes: [u8; N],
|
|
}
|
|
|
|
impl<const N: usize> AsRef<[u8]> for BufferWrapper<N> {
|
|
fn as_ref(&self) -> &[u8] {
|
|
&self.bytes[..]
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
pub fn no_alloc_buffer_segments_from_buffer() {
|
|
let buffer = BufferWrapper {
|
|
bytes: [
|
|
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x42, 0x00,
|
|
0x00, 0x00, 97, 98, 99, 100, 101, 102, 103, 0, // "abcdefg" with null terminator
|
|
],
|
|
};
|
|
let segs = serialize::NoAllocBufferSegments::from_buffer(buffer, Default::default()).unwrap();
|
|
let message = message::Reader::new(segs, Default::default());
|
|
let t = message.get_root::<zap::text::Reader>().unwrap();
|
|
assert_eq!(t, "abcdefg");
|
|
}
|