Expand description
Code generator for typed boomslang host extensions.
An extension declares host functions that Python code (running on CPython
compiled to WASM) can call into the embedding Java or Rust host. The
declaration lives in the extension crate’s build.rs, written with the
builder DSL in this crate: ExtensionSpec describes the extension and
its functions, and Build selects which artifacts to
emit before Build::generate writes them out. The primary artifacts are
a Rust guest module (PyO3 wrappers plus WASM imports, written to
OUT_DIR) and an ABI JSON contract; the ABI JSON in turn drives host
adapter generation — either via the boomslang-hostgen CLI or the
generate_java / generate_rust_host functions — so hosts can be
regenerated without rebuilding the guest.
§Examples
A typical build.rs:
use boomslang_hostgen::{Build, ExtensionSpec, Type};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ext = ExtensionSpec::new("myext")
.wasm_module("myext")
.prewarm(["myext_support"])
.function("do_thing", |f| {
f.param("input", Type::String).returns(Type::String)
});
Build::new(ext).emit().generate()
}The extension crate then consumes the generated guest module with
include!(concat!(env!("OUT_DIR"), "/ext_myext.rs")); and calls the
included register() function to add the Python module to CPython’s
init table.
Structs§
- Build
- Selects which artifacts to generate from an
ExtensionSpec. - Extension
- Extension-level metadata within a
Manifest. - Extension
Spec - Builder for an extension
Manifest, used frombuild.rs. - Function
- A single host function exposed to Python.
- Function
Spec - Builder for a single
Function, used insideExtensionSpec::function. - Manifest
- The full extension contract: ABI version, extension metadata, and the list of host functions.
- Param
- A typed parameter of a
Function.
Enums§
- Type
- Value types supported across the guest/host boundary.
Functions§
- generate_
java - Generates Java (Chicory) host function bindings from an ABI JSON file.
- generate_
java_ code - Renders the Java (Chicory) host adapter source for a manifest: a
<Name>HostFunctionsclass in the given package, with typed handler interfaces and ChicoryHostFunctionregistrations. Unlikegenerate_java, this function does not validate the manifest. - generate_
rust_ code - Renders the Rust guest module source for a manifest: WASM import
declarations, PyO3 wrapper functions, and the
register()/prewarm()entry points.Build::emit_rust_guestwrites this to$OUT_DIR/ext_<name>.rs; unlikeBuild::generate, this function does not validate the manifest. - generate_
rust_ host - Generates Rust (Wasmtime) host function bindings from an ABI JSON file.
- generate_
rust_ host_ code - Renders the Rust (Wasmtime) host adapter source for a manifest: a
<Name>HostFunctionsstruct with a builder for wiring typed handler closures into a Wasmtime linker. Validates the manifest first. - read_
abi - Reads and validates an ABI JSON file (see
Manifestfor the validation rules, including the exact ABI version check).