Extension SDK and registry
The extension line has three layers:
crisol-extension-sdkis the typed guest API. It wraps the smallworkbench.host_*imports and keeps the module ABI explicit.crisol-extensionsloads the module, checks the manifest and capabilities, and exposes commands, panels, viewer formats, and plot layers to the host.ExtensionRegistryis the index an application reads to discover, verify, and update extensions.
Scaffold
cargo xtask new-extension ../hello-ext --name hello-ext --title "Hello"
cd ../hello-ext
cargo build --target wasm32-unknown-unknown --releaseThe generator copies templates/extension, fills the crate name, title, reverse-DNS id, and the local SDK path. It writes extension.json next to the .wasm:
{
"id": "com.example.hello-ext",
"version": "0.1.0",
"name": "Hello Ext",
"api": { "min": "0.15", "max": "0.16" },
"entry": "hello-ext.wasm",
"capabilities": ["commands"]
}Guest API
use crisol_extension_sdk::{Contribution, log, read_command, register};
#[unsafe(no_mangle)]
pub extern "C" fn init() -> i32 {
register(
Contribution::Command,
r#"{"id":"hello.run","title":"Hello"}"#,
);
register(
Contribution::Plot,
r#"{"id":"hello.layer","title":"Hello layer"}"#,
);
0
}
#[unsafe(no_mangle)]
pub extern "C" fn on_command(pointer: i32, length: i32) -> i32 {
let id = unsafe { read_command(pointer as usize, length as usize) };
log(&format!("hello ran {id}"));
0
}
fn main() {}Contribution is Command, Panel, Viewer, or Plot (kind 0..=3). The JSON shape is {"id","title"} for commands, panels, and plots, and {"id","extensions"} for viewer formats. register returns the host status; a negative value means the capability is missing or the payload was rejected.
Registry
use std::collections::BTreeMap;
use crisol_extensions::ExtensionRegistry;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let index = r#"{
"version": 1,
"entries": [
{
"id": "com.example.hello",
"name": "Hello",
"version": "1.2.0",
"url": "https://example.invalid/hello.wasm",
"sha256": "0000000000000000000000000000000000000000000000000000000000000000",
"description": "Demo extension"
}
]
}"#;
let registry = ExtensionRegistry::from_json(index)?;
let entry = registry.get("com.example.hello").expect("entry");
assert_eq!(entry.version, "1.2.0");
let installed = BTreeMap::from([("com.example.hello".to_owned(), "1.1.0".to_owned())]);
assert_eq!(registry.updates(&installed).len(), 1);
let same = BTreeMap::from([("com.example.hello".to_owned(), "1.2.0".to_owned())]);
assert!(registry.updates(&same).is_empty());
println!("extension registry ok");
Ok(())
}from_json rejects a hash that is not 64 hex characters. Before loading a downloaded module, call registry.verify(entry, &bytes); it compares the SHA-256 and returns ExtensionError::Checksum { expected, actual }. signature is optional and is checked only when the application installs a verifier on ExtensionManager.
WASI preview 2 components
The default runtime is core WebAssembly on wasmi, with no WASI. The optional component feature adds ComponentRuntime on wasmtime for modules that export the crisol:extension world:
package crisol:extension@0.1.0;
world extension {
export init: func() -> s32;
export on-command: func(id: string) -> s32;
}use crisol_extensions::ComponentRuntime;
fn main() {
let engine = ComponentRuntime::engine();
assert!(ComponentRuntime::new(b"not a component", &engine).is_err());
}Enable it with crisol-extensions = { version = "1.15", features = ["component"] }. The core runtime remains the default because it is smaller and runs C and no_std guests without a component toolchain.
Plot contributions
A plot contribution is a layer kind, not a renderer: the host asks the extension for the layer metadata and draws it with the same Plot pipeline. Register it with Contribution::Plot; the manager exposes it in ExtensionInfo::plots and the extension manager view lists it beside commands, panels, and viewers.
Checks
cargo test -p crisol-extensions registry
cargo test -p crisol-extensions --features component component
cargo xtask new-extension /tmp/hello-ext --name hello-ext --title "Hello"
cargo build --manifest-path /tmp/hello-ext/Cargo.toml --target wasm32-unknown-unknown --release