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.
217 lines
6.5 KiB
Plaintext
217 lines
6.5 KiB
Plaintext
# Copyright (c) 2013-2016 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.
|
|
#
|
|
|
|
@0xa7c73bdce79c15a0;
|
|
|
|
enum TestEnum {
|
|
foo @0;
|
|
bar @1;
|
|
baz @2;
|
|
qux @3;
|
|
quux @4;
|
|
corge @5;
|
|
grault @6;
|
|
garply @7;
|
|
}
|
|
|
|
struct TestAllTypes {
|
|
voidField @0 : Void;
|
|
boolField @1 : Bool;
|
|
int8Field @2 : Int8;
|
|
int16Field @3 : Int16;
|
|
int32Field @4 : Int32;
|
|
int64Field @5 : Int64;
|
|
uInt8Field @6 : UInt8;
|
|
uInt16Field @7 : UInt16;
|
|
uInt32Field @8 : UInt32;
|
|
uInt64Field @9 : UInt64;
|
|
float32Field @10 : Float32;
|
|
float64Field @11 : Float64;
|
|
textField @12 : Text;
|
|
dataField @13 : Data;
|
|
structField @14 : TestAllTypes;
|
|
enumField @15 : TestEnum;
|
|
interfaceField @16 : TestInterface;
|
|
|
|
voidList @17 : List(Void);
|
|
boolList @18 : List(Bool);
|
|
int8List @19 : List(Int8);
|
|
int16List @20 : List(Int16);
|
|
int32List @21 : List(Int32);
|
|
int64List @22 : List(Int64);
|
|
uInt8List @23 : List(UInt8);
|
|
uInt16List @24 : List(UInt16);
|
|
uInt32List @25 : List(UInt32);
|
|
uInt64List @26 : List(UInt64);
|
|
float32List @27 : List(Float32);
|
|
float64List @28 : List(Float64);
|
|
textList @29 : List(Text);
|
|
dataList @30 : List(Data);
|
|
structList @31 : List(TestAllTypes);
|
|
enumList @32 : List(TestEnum);
|
|
interfaceList @33 : List(Void); # TODO
|
|
}
|
|
|
|
interface Bootstrap {
|
|
testInterface @0 () -> (cap: TestInterface);
|
|
testExtends @1 () -> (cap: TestExtends);
|
|
testExtends2 @2 () -> (cap: TestExtends2);
|
|
testPipeline @3 () -> (cap: TestPipeline);
|
|
testCallOrder @4 () -> (cap: TestCallOrder);
|
|
testMoreStuff @5 () -> (cap: TestMoreStuff);
|
|
testCapabilityServerSet @6 () -> (cap: TestCapabilityServerSet);
|
|
testPromiseResolve @7 () -> (cap: TestPromiseResolve);
|
|
}
|
|
|
|
interface TestInterface {
|
|
foo @0 (i :UInt32, j :Bool) -> (x :Text);
|
|
bar @1 () -> ();
|
|
baz @2 (s: TestAllTypes);
|
|
}
|
|
|
|
interface TestExtends extends(TestInterface) {
|
|
qux @0 ();
|
|
corge @1 TestAllTypes -> ();
|
|
grault @2 () -> TestAllTypes;
|
|
}
|
|
|
|
interface TestExtends2 extends(TestExtends) {}
|
|
|
|
interface TestPipeline {
|
|
getCap @0 (n: UInt32, inCap :TestInterface) -> (s: Text, outBox :Box);
|
|
getNullCap @1 () -> (cap :TestInterface);
|
|
testPointers @2 (cap :TestInterface, obj :AnyPointer, list :List(TestInterface)) -> ();
|
|
|
|
getCapPipelineOnly @3 () -> (outBox :Box);
|
|
# Never returns, but uses setPipeline() to make the pipeline work.
|
|
|
|
struct Box {
|
|
cap @0 :TestInterface;
|
|
|
|
foo :group {
|
|
capInGroup @1 :TestInterface;
|
|
}
|
|
}
|
|
}
|
|
|
|
interface TestCallOrder {
|
|
getCallSequence @0 (expected: UInt32) -> (n: UInt32);
|
|
# First call returns 0, next returns 1, ...
|
|
#
|
|
# The input `expected` is ignored but useful for disambiguating debug logs.
|
|
}
|
|
|
|
interface TestTailCallee {
|
|
struct TailResult {
|
|
i @0 :UInt32;
|
|
t @1 :Text;
|
|
c @2 :TestCallOrder;
|
|
}
|
|
|
|
foo @0 (i :Int32, t :Text) -> TailResult;
|
|
}
|
|
|
|
interface TestTailCaller {
|
|
foo @0 (i :Int32, callee :TestTailCallee) -> TestTailCallee.TailResult;
|
|
}
|
|
|
|
interface TestStreaming {
|
|
doStreamI @0 (i :UInt32, throwError :Bool) -> stream;
|
|
doStreamJ @1 (j :UInt32, throwError :Bool) -> stream;
|
|
finishStream @2 () -> (totalI :UInt32, totalJ :UInt32);
|
|
# Test streaming. finishStream() returns the totals of the values streamed to the other calls.
|
|
}
|
|
|
|
interface TestHandle {}
|
|
|
|
interface TestMoreStuff extends(TestCallOrder) {
|
|
# Catch-all type that contains lots of testing methods.
|
|
|
|
callFoo @0 (cap :TestInterface) -> (s: Text);
|
|
# Call `cap.foo()`, check the result, and return "bar".
|
|
|
|
callFooWhenResolved @1 (cap :TestInterface) -> (s: Text);
|
|
# Like callFoo but waits for `cap` to resolve first.
|
|
|
|
neverReturn @2 (cap :TestInterface) -> (capCopy :TestInterface);
|
|
# Doesn't return. You should cancel it.
|
|
|
|
hold @3 (cap :TestInterface) -> ();
|
|
# Returns immediately but holds on to the capability.
|
|
|
|
callHeld @4 () -> (s: Text);
|
|
# Calls the capability previously held using `hold` (and keeps holding it).
|
|
|
|
getHeld @5 () -> (cap :TestInterface);
|
|
# Returns the capability previously held using `hold` (and keeps holding it).
|
|
|
|
echo @6 (cap :TestCallOrder) -> (cap :TestCallOrder);
|
|
# Just returns the input cap.
|
|
|
|
expectCancel @7 (cap :TestInterface) -> ();
|
|
# evalLater()-loops forever, holding `cap`. Must be canceled.
|
|
|
|
methodWithDefaults @8 (a :Text, b :UInt32 = 123, c :Text = "foo") -> (d :Text, e :Text = "bar");
|
|
|
|
getHandle @9 () -> (handle :TestHandle);
|
|
# Get a new handle. Tests have an out-of-band way to check the current number of live handles, so
|
|
# this can be used to test garbage collection.
|
|
|
|
getNull @10 () -> (nullCap :TestMoreStuff);
|
|
# Always returns a null capability.
|
|
|
|
getHandleCount @11 () -> (count: Int64);
|
|
|
|
dontHold @12 (cap :TestInterface) -> ();
|
|
# Returns immediately and does not hold on to the capability.
|
|
|
|
callEachCapability @13 (caps :List(TestInterface)) -> ();
|
|
# Calls TestInterface::foo(123, true) on each cap.
|
|
|
|
getTestStreaming @14 () -> (cap :TestStreaming);
|
|
|
|
getTestSelf @15 () -> (cap :TestSelf);
|
|
}
|
|
|
|
interface TestCapabilityServerSet {
|
|
interface Handle {}
|
|
|
|
createHandle @0 () -> (handle :Handle);
|
|
checkHandle @1 (handle: Handle) -> (isOurs :Bool);
|
|
}
|
|
|
|
interface TestPromiseResolve {
|
|
interface Resolver {
|
|
resolveToAnotherPromise @0 ();
|
|
resolveToCap @1 ();
|
|
}
|
|
|
|
foo @0 () -> (cap: TestInterface, resolver: Resolver);
|
|
# Teturns a promise capability whose resolution can
|
|
# be triggered by a `resolver` capability.
|
|
}
|
|
|
|
interface TestSelf {
|
|
foo @0 () -> (x :UInt32);
|
|
getSelf @1 () -> (cap: TestSelf);
|
|
}
|