Skip to main content

Starlark — Rust runtime

Examples below assume this module is imported with an imports: entry under alias Starlark. If you import the module under a different name, substitute your alias accordingly.

The std/starlark module ships two controller implementations:

ImplementationDeclared asBacked by
nodejspkg:npm/@telorun/starlarkstarlark-webasm
rustpkg:cargo/telorun-starlarkNative 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:

  1. Probe rustc --version. Missing → fall back if the runtime spec allows it (e.g. runtime: [rust, any]); error if the spec is strict.
  2. Run cargo build --release --features napi in modules/starlark/rust/.
  3. Locate the produced dylib via cargo metadata and copy it to <libname>.node.
  4. Load via Node's require and 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

FormMeaning
(omitted)Same as runtime: auto — kernel-native first, fall through
runtime: autoBest effort: kernel-native first, then any other available controller
runtime: nativeStrict kernel-native (nodejs for the Node.js kernel)
runtime: nodejsStrict — only the nodejs controller. Fails on miss
runtime: rustStrict — 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.