Files
zeekay ed429a2283 rename capnp/capnpc → zap/zapc — ZAP-native runtime, no Cap'n Proto
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.
2026-05-27 12:36:19 -07:00

159 lines
5.2 KiB
Rust

// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
// Licensed under the MIT License:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
use crate::catrank_zap::*;
use crate::common::*;
#[derive(Clone, Copy)]
pub struct ScoredResult<'a> {
score: f64,
result: search_result::Reader<'a>,
}
const URL_PREFIX: &str = "http://example.com";
pub struct CatRank;
impl crate::TestCase for CatRank {
type Request = search_result_list::Owned;
type Response = search_result_list::Owned;
type Expectation = i32;
fn setup_request(&self, rng: &mut FastRand, request: search_result_list::Builder) -> i32 {
let count = rng.next_less_than(1000);
let mut good_count: i32 = 0;
let mut list = request.init_results(count);
for i in 0..count {
let mut result = list.reborrow().get(i);
result.set_score(1000.0 - i as f64);
let url_size = rng.next_less_than(100);
let url_prefix_length = URL_PREFIX.len();
{
let mut url = result
.reborrow()
.init_url(url_size + url_prefix_length as u32);
url.push_str(URL_PREFIX);
for _ in 0..url_size {
url.push_ascii((97 + rng.next_less_than(26)) as u8);
}
}
let is_cat = rng.next_less_than(8) == 0;
let is_dog = rng.next_less_than(8) == 0;
if is_cat && !is_dog {
good_count += 1;
}
let mut snippet = " ".to_string();
let prefix = rng.next_less_than(20) as usize;
for _ in 0..prefix {
snippet.push_str(WORDS[rng.next_less_than(WORDS.len() as u32) as usize]);
}
if is_cat {
snippet.push_str("cat ")
}
if is_dog {
snippet.push_str("dog ")
}
let suffix = rng.next_less_than(20) as usize;
for _ in 0..suffix {
snippet.push_str(WORDS[rng.next_less_than(WORDS.len() as u32) as usize]);
}
result.set_snippet(&snippet[..]);
}
good_count
}
fn handle_request(
&self,
request: search_result_list::Reader,
response: search_result_list::Builder,
) -> ::zap::Result<()> {
let mut scored_results: Vec<ScoredResult> = Vec::new();
let results = request.get_results()?;
for i in 0..results.len() {
let result = results.get(i);
let mut score = result.get_score();
let snippet = result.get_snippet()?.to_str()?;
if snippet.contains(" cat ") {
score *= 10000.0;
}
if snippet.contains(" dog ") {
score /= 10000.0;
}
scored_results.push(ScoredResult { score, result });
}
// sort in decreasing order
scored_results.sort_by(|v1, v2| {
if v1.score < v2.score {
::std::cmp::Ordering::Greater
} else {
::std::cmp::Ordering::Less
}
});
let mut list = response.init_results(scored_results.len() as u32);
for i in 0..list.len() {
let mut item = list.reborrow().get(i);
let result = scored_results[i as usize];
item.set_score(result.score);
item.set_url(result.result.get_url()?);
item.set_snippet(result.result.get_snippet()?);
}
Ok(())
}
fn check_response(
&self,
response: search_result_list::Reader,
expected_good_count: i32,
) -> ::zap::Result<()> {
let mut good_count: i32 = 0;
let results = response.get_results()?;
for result in results {
if result.get_score() > 1001.0 {
good_count += 1;
} else {
break;
}
}
if good_count == expected_good_count {
Ok(())
} else {
Err(::zap::Error::failed(format!(
"check_response() expected {expected_good_count} but got {good_count}"
)))
}
}
}