Skip to content

Generated bindings

From one interface, the block pipeline generates code for both sides of the block's boundary: Python for your block, and Rust for the kernel side. The files are written into the block's folder, archived into the Xratu package with it, and listed by hash in the block's capsule:

python/acme/billing/ledger_guest.py              Python binding for your block
rust/acme/billing/ledger.rs                      Rust binding for the kernel side
capsule/acme/billing/ledger_adapter_dispatch.py  dispatch module, see below

Every generated file starts with # @generated by XCI. Do not edit. and the interface id and hash it came from. The pipeline overwrites them on each run, and bake refuses a capsule whose generated files differ from what the compiler produces.

The Python binding

The Python binding gives your block typed classes for the interface's records, and a typed description of the methods your class implements:

@dataclass(frozen=True, slots=True)
class ChargeRequest:
    account: str  # field id 1
    amount: int  # field id 2

class LedgerGuest(Protocol):
    def charge(self, request: ChargeRequest, receipt: str) -> Awaitable[TaskRef]: ...
    # method ordinal 7; effect mutating_external; retry recoverable
    def charge_status(self, receipt: str) -> str | Awaitable[str]: ...
    # method ordinal 9; effect read_only; retry retry_safe

Your Ledger class implements LedgerGuest. The binding also lists each method's number, parameters, errors, delivery, effect and retry, and each resource.

The Rust binding

The Rust binding carries the same records as Rust types, and a constant set per method:

pub struct ChargeRequest {
    pub account: String, // field id 1
    pub amount: i128, // field id 2
}

pub mod charge {
    pub const ORDINAL: u32 = 7;
    pub const EFFECT: &str = "mutating_external";
}

Names are checked

Interface names are converted to Python and Rust names. When two different interface names would become the same name in either language, compilation stops before any file is written, and the error names both, so the generated code never holds two definitions under one name.

Related: Language neutrality covers why both sides are generated from one interface.