Skip to main content

Crate capnpc_embedded

Crate capnpc_embedded 

Source
Expand description

Compile Cap’n Proto schemas from a build.rs with no system capnp and no C/C++ toolchain.

The Cap’n Proto schema compiler is embedded as a single, architecture- independent WebAssembly module (capnp.wasm) and executed in-process by a pure-Rust WASM engine. CompileCommand::compile returns the raw CodeGeneratorRequest the compiler produces — no subprocess, no native binary, no network.

This crate deliberately does not depend on capnpc/capnp. You feed the returned request to your own chosen capnpc version, so nothing here couples you to a particular capnp runtime:

// build.rs
let request = capnpc_embedded::CompileCommand::new()
    .src_prefix("schema")
    .file("schema/foo.capnp")
    .compile()
    .expect("capnp compile failed");

capnpc::codegen::CodeGenerationCommand::new()
    .output_directory(std::env::var("OUT_DIR").unwrap())
    .run(&request[..])
    .expect("capnp codegen failed");

Structs§

CompileCommand
A builder for compiling Cap’n Proto schemas into a CodeGeneratorRequest.
Error
An error produced while compiling schemas.

Type Aliases§

Result
Result alias for schema compilation.