Starlark — Rust runtime
Examples below assume this module is imported with an
imports:entry under aliasStarlark. If you import the module under a different name, substitute your alias accordingly.
The std/starlark module ships two controller implementations:
| Implementation | Declared as | Backed by |
|---|---|---|
nodejs | pkg:npm/@telorun/starlark | starlark-webasm |
rust | pkg:cargo/telorun-starlark | Native Rust addon (N-API) |
By default, importing std/starlark resolves to the kernel-native implementation — nodejs for the Node.js kernel today.
Opting into the Rust controller
The runtime: field selects the implementation. Use the object form of an imports: entry to set it:
kind: Telo.Application
metadata: { name: my-app, version: 1.0.0 }
imports:
Starlark:
source: std/starlark@0.6.0
runtime: rust
The kernel will:
- Probe
rustc --version. Missing → fall back if the runtime spec allows it (e.g.runtime: [rust, any]); error if the spec is strict. - Run
cargo build --release --features napiinmodules/starlark/rust/. - Locate the produced dylib via
cargo metadataand copy it to<libname>.node. - Load via Node's
requireand use it as the controller.
First-run cost is the cold cargo build (~30s). Subsequent runs hit Cargo's incremental cache and are sub-second.
Other runtime: forms
| Form | Meaning |
|---|---|
| (omitted) | Same as runtime: auto — kernel-native first, fall through |
runtime: auto | Best effort: kernel-native first, then any other available controller |
runtime: native | Strict kernel-native (nodejs for the Node.js kernel) |
runtime: nodejs | Strict — only the nodejs controller. Fails on miss |
runtime: rust | Strict — only the rust controller. Fails on miss |
runtime: [rust, nodejs] | Ordered fallback: try rust, then nodejs; fail if both miss |
runtime: [rust, any] | Rust preferred; fall through to anything else available |
Authoring a Rust controller
The Rust controller crate at modules/starlark/rust/ is a textbook Rust project — Cargo.toml + src/. The contributor never writes use napi::* or #[napi] attributes; the #[controller] macro from telorun-sdk generates all FFI plumbing.
See the SDK README for the controller-author contract.