Tooling for authoring perfscale libraries — WASM components that provide
value-generating functions to ${alias.fn(...)} tokens in
perfscale test payloads (RFC 005):
libraries:
- use: ./hello.wasm
capabilities: [] # explicit no-grants declaration; required by perfscale ≥ the upcoming release (pure component needs no grants)
steps:
- use: std/file-write@v1
with:
path: out.txt
content: "greeting: ${hello.greet(world)}" # → "greeting: hello, world!"The engine runs each library in a wasmtime sandbox under a fail-closed
capability model; the ABI contract (perfscale:library@0.3.0) is
ts/wit/library.wit, mirrored from the main repo's
single source of truth. The same TS package also authors WASM end-of-run
reporters (issue #9) — components rendering the canonical report@v1
document once per run; the reporter ABI (perfscale:reporter@0.1.0) is
ts/wit/reporter/reporter.wit. It also
authors custom steps (RFC 009) — actions dispatched as
lib/<alias>/<step>; the step ABI (perfscale:step@0.1.0) is
ts/wit/step/step.wit.
| Language | Status | Where |
|---|---|---|
| TypeScript / JavaScript | SDK + build tooling | ts/ (@perfscale/library-sdk) |
| Go | Stable SDK for ABI 0.3 + TinyGo example | go/ (github.com/Perfscale/sdk-libraries/go) |
| Rust | Full SDK, lives in the main repo | crates/perfscale-library-sdk |
$ cd ts && npm installWrite a library (mylib.ts):
import { args, defineLibrary } from "@perfscale/library-sdk";
export default defineLibrary({
name: "mylib",
functions: {
token: {
description: "Deterministic per-instance token; memo key reuses it within one message",
call(argv, ctx) {
const mint = () => `tok-${ctx.rng().nextU64().toString(16)}`;
const key = args.optionalString(argv, 0);
return key === undefined ? mint() : ctx.memo(key, mint);
},
},
},
});Build it to a WASM component with jco (ComponentizeJS embeds a JS engine — that is how TS becomes a component):
$ npx perfscale-library-build mylib.ts -o mylib.wasmReference it from your perfscale YAML (relative to the declaring file) and
call it from ${...} tokens in payloads.
The SDK also gives you:
-
Ctx— per-call context (messageSeq,iterationSeq,vuId,seed,timeMsasbigint),ctx.settings— the run's frozen settings snapshot plusextensions(validated config-extension blocks, see Config extensions),ctx.memo(key, fn)(keyed reuse within one message), andctx.rng()— a seeded xorshift64 PRNG bit-identical to the Rust SDK and the engine's built-in generator, soseed:runs reproduce. -
Args helpers (
args.string/int/float/optionalString) with author-friendly errors. -
testCall— a runtime-free harness fornode:testunit tests; no WASM needed:import assert from "node:assert/strict"; import { Ctx, testCall } from "@perfscale/library-sdk"; import lib from "./mylib.ts"; const ctx = new Ctx(42); assert.equal(testCall(lib, ctx, "token", []), testCall(lib, ctx, "token", []));
defineSteps declares components whose steps run as test actions via
use: lib/<alias>/<step> (alongside the built-in std/* actions), including
one-shot before:/after: setup steps. A step receives its with: block
and a StepCtx (iterationSeq/vuId/timeMs as bigint, stepName,
frozen run settings), and returns an ActionOutput: success, output
(stored under the step's outputs:, usable in later steps' check: and
${{ }} expressions), logs, custom metrics series ([a-z0-9_]), an
httpSample, and secretOutputPaths for log masking. Build with
perfscale-library-build --kind steps entry.ts -o s.wasm.
Security — the process gate: steps that spawn host processes via
ctx.exec need a double opt-in: the component declares
capabilities: [process] AND the run config sets
allow_process_actions: true (plus allow_library_capabilities: true); the
host connects the bounded host-exec import (no shell, replacement
environment, capped timeout/output) only then, and refuses to load the
component otherwise. Build these with --kind steps --process. Details and
examples: ts/README.md — Steps,
ts/examples/steps.
- jco (StarlingMonkey) components always import
wasi:filesystem/*andwasi:clocks/wall-clock, but that is toolchain noise: the SDK reports"pure": trueininfo()(it exposes no fs/clock APIs to authors), so engines honoring the pure marker waive the capability requirement and provide no preopens — declarecapabilities: [](explicit no-grants key, required by perfscale ≥ the upcoming release) and nothing more. On engines older than the pure-marker release the grant is still required (capabilities: [fs]on thelibraries:entry, onefsgrant satisfies both imports, plusallow_library_capabilities: truein the config) — old engines fail closed. The build already disableswasi:random,wasi:httpand timers, which the engine never grants — draw all randomness fromctx.rng()and all time fromctx.timeMs. - The WIT contract is vendored at
ts/wit/library.wit;ts/scripts/sync-wit.shre-fetches it pinned to a perfscale release tag (bumpPERFSCALE_TAGdeliberately).
Authoring (TS/JS) — a hermetic toolchain image, no host Node required:
$ docker build -t perfscale-library-build ts/docker
$ docker run --rm -v "$PWD:/src" -w /src perfscale-library-build mylib.ts -o mylib.wasmThe image is Node 24 + the published @perfscale/library-sdk (jco included);
pin the SDK with --build-arg SDK_VERSION=0.2.0 (ts/docker/Dockerfile).
Rust — the SDK lives in the engine repo; any rust:1.x image with
wasm32-wasip2 added (rustup target add wasm32-wasip2) builds components
with plain cargo. Go — the tinygo/tinygo image matches the recipe in
go/README.md.
Running libraries in Docker (engine images, mount layout, the install cache, and burned standalone binaries) is covered in the engine's Docker guide.
ts/ @perfscale/library-sdk — defineLibrary, defineSteps, Ctx,
StepCtx, Prng, testCall, testStep,
perfscale-library-build (jco componentize glue), example
go/ Stable Go SDK: Library, Ctx, Prng, Runtime, args helpers,
standard/config component exports, host tests, TinyGo example
Dual-licensed under MIT or Apache-2.0, same as the main perfscale repo.