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.
170 lines
5.4 KiB
Rust
170 lines
5.4 KiB
Rust
#![cfg(all(
|
|
target_endian = "little",
|
|
feature = "alloc",
|
|
not(feature = "unaligned")
|
|
))]
|
|
|
|
use zap::{message, primitive_list};
|
|
|
|
#[test]
|
|
pub fn primitive_list_as_slice() {
|
|
let mut msg = message::Builder::new_default();
|
|
|
|
{
|
|
let mut void_list = msg.initn_root::<primitive_list::Builder<()>>(0);
|
|
assert_eq!(void_list.as_slice().unwrap().len(), 0);
|
|
assert_eq!(void_list.into_reader().as_slice().unwrap().len(), 0);
|
|
}
|
|
|
|
{
|
|
let mut void_list = msg.initn_root::<primitive_list::Builder<()>>(5);
|
|
assert_eq!(void_list.as_slice().unwrap(), &[(), (), (), (), ()]);
|
|
assert_eq!(
|
|
void_list.into_reader().as_slice().unwrap(),
|
|
&[(), (), (), (), ()]
|
|
);
|
|
}
|
|
|
|
{
|
|
let mut bool_list = msg.initn_root::<primitive_list::Builder<bool>>(8);
|
|
|
|
bool_list.set(0, true);
|
|
bool_list.set(1, true);
|
|
|
|
// Rust's slices cannot represent bit-packed bools.
|
|
assert!(bool_list.as_slice().is_none());
|
|
assert!(bool_list.into_reader().as_slice().is_none());
|
|
}
|
|
|
|
{
|
|
let mut u8list = msg.initn_root::<primitive_list::Builder<u8>>(0);
|
|
assert_eq!(u8list.as_slice().unwrap().len(), 0);
|
|
assert_eq!(u8list.into_reader().as_slice().unwrap().len(), 0);
|
|
}
|
|
|
|
{
|
|
let mut u8list = msg.initn_root::<primitive_list::Builder<u8>>(3);
|
|
u8list.set(0, 0);
|
|
u8list.set(1, 1);
|
|
u8list.set(2, 2);
|
|
assert_eq!(u8list.as_slice().unwrap(), &[0, 1, 2]);
|
|
}
|
|
|
|
{
|
|
let mut u16list = msg.initn_root::<primitive_list::Builder<u16>>(0);
|
|
assert_eq!(u16list.as_slice().unwrap().len(), 0);
|
|
assert_eq!(u16list.into_reader().as_slice().unwrap().len(), 0);
|
|
}
|
|
|
|
{
|
|
let mut u16list = msg.initn_root::<primitive_list::Builder<u16>>(4);
|
|
u16list.set(0, 0xab);
|
|
u16list.set(1, 0xcd);
|
|
u16list.set(2, 0xde);
|
|
u16list.set(3, 0xff);
|
|
assert_eq!(u16list.as_slice().unwrap(), &[0xab, 0xcd, 0xde, 0xff]);
|
|
assert_eq!(
|
|
u16list.into_reader().as_slice().unwrap(),
|
|
&[0xab, 0xcd, 0xde, 0xff]
|
|
);
|
|
}
|
|
|
|
{
|
|
let mut u32list = msg.initn_root::<primitive_list::Builder<u32>>(0);
|
|
assert_eq!(u32list.as_slice().unwrap().len(), 0);
|
|
assert_eq!(u32list.into_reader().as_slice().unwrap().len(), 0);
|
|
}
|
|
|
|
{
|
|
let mut u32list = msg.initn_root::<primitive_list::Builder<u32>>(4);
|
|
u32list.set(0, 0xab);
|
|
u32list.set(1, 0xcd);
|
|
u32list.set(2, 0xde);
|
|
u32list.set(3, 0xff);
|
|
assert_eq!(u32list.as_slice().unwrap(), &[0xab, 0xcd, 0xde, 0xff]);
|
|
assert_eq!(
|
|
u32list.into_reader().as_slice().unwrap(),
|
|
&[0xab, 0xcd, 0xde, 0xff]
|
|
);
|
|
}
|
|
|
|
{
|
|
let mut u64list = msg.initn_root::<primitive_list::Builder<u64>>(0);
|
|
assert_eq!(u64list.as_slice().unwrap().len(), 0);
|
|
assert_eq!(u64list.into_reader().as_slice().unwrap().len(), 0);
|
|
}
|
|
|
|
{
|
|
let mut u64list = msg.initn_root::<primitive_list::Builder<u64>>(4);
|
|
u64list.set(0, 0xab);
|
|
u64list.set(1, 0xcd);
|
|
u64list.set(2, 0xde);
|
|
u64list.set(3, 0xff);
|
|
assert_eq!(u64list.as_slice().unwrap(), &[0xab, 0xcd, 0xde, 0xff]);
|
|
assert_eq!(
|
|
u64list.into_reader().as_slice().unwrap(),
|
|
&[0xab, 0xcd, 0xde, 0xff]
|
|
);
|
|
}
|
|
|
|
{
|
|
let mut f32list = msg.initn_root::<primitive_list::Builder<f32>>(0);
|
|
assert_eq!(f32list.as_slice().unwrap().len(), 0);
|
|
assert_eq!(f32list.into_reader().as_slice().unwrap().len(), 0);
|
|
}
|
|
|
|
{
|
|
let mut f32list = msg.initn_root::<primitive_list::Builder<f32>>(5);
|
|
f32list.set(0, 0.3);
|
|
f32list.set(1, 0.0);
|
|
f32list.set(2, f32::NEG_INFINITY);
|
|
f32list.set(3, -0.0);
|
|
f32list.set(4, f32::MAX);
|
|
assert_eq!(
|
|
f32list.as_slice().unwrap(),
|
|
&[0.3, 0.0, f32::NEG_INFINITY, -0.0, f32::MAX]
|
|
);
|
|
assert_eq!(
|
|
f32list.into_reader().as_slice().unwrap(),
|
|
&[0.3, 0.0, f32::NEG_INFINITY, -0.0, f32::MAX]
|
|
);
|
|
}
|
|
|
|
{
|
|
let mut f64list = msg.initn_root::<primitive_list::Builder<f64>>(0);
|
|
assert_eq!(f64list.as_slice().unwrap().len(), 0);
|
|
assert_eq!(f64list.into_reader().as_slice().unwrap().len(), 0);
|
|
}
|
|
|
|
{
|
|
let mut f64list = msg.initn_root::<primitive_list::Builder<f64>>(5);
|
|
f64list.set(0, 0.3);
|
|
f64list.set(1, 0.0);
|
|
f64list.set(2, f64::NEG_INFINITY);
|
|
f64list.set(3, -0.0);
|
|
f64list.set(4, f64::MAX);
|
|
assert_eq!(
|
|
f64list.as_slice().unwrap(),
|
|
&[0.3, 0.0, f64::NEG_INFINITY, -0.0, f64::MAX]
|
|
);
|
|
assert_eq!(
|
|
f64list.into_reader().as_slice().unwrap(),
|
|
&[0.3, 0.0, f64::NEG_INFINITY, -0.0, f64::MAX]
|
|
);
|
|
}
|
|
|
|
{
|
|
// Test the case when the list elements are InlineComposite.
|
|
use zap::{schema_zap, struct_list};
|
|
let nodelist = msg.initn_root::<struct_list::Builder<schema_zap::node::Owned>>(2);
|
|
nodelist.get(0).set_id(0xabcd);
|
|
let mut u64list = msg.get_root::<primitive_list::Builder<u64>>().unwrap();
|
|
assert!(u64list.as_slice().is_none());
|
|
assert_eq!(u64list.get(0), 0xabcd);
|
|
|
|
let u64list = u64list.into_reader();
|
|
assert!(u64list.as_slice().is_none());
|
|
assert_eq!(u64list.get(0), 0xabcd);
|
|
}
|
|
}
|