Build a VM application
Compile an accepted application closure to LemaIR in pure Rust, cache the verified compile memo in vm-code-cache, verify ConstantTime and SecretFlow guarantees, and register a local lema-vm-runner worker.
When Lema compiles an executable program, it never invokes a C compiler (leanc and clang were retired in Decision 0052) and it never reads loose source files from disk. Instead, Lema compiles the accepted canonical objects inside your store directly to LemaIR (lema.ir/v1, crates/lema-ir/) in pure Rust, caches the verified compile memo inside <store>/vm-code-cache, and binds the resulting artifact to your local lema-vm-runner worker binary (Target::Vm, "vm").
During everyday development inside a Lema project, lema run and lema release handle lema.exec/v2 synthesis and compilation automatically. Follow the steps on this page when you want to import an explicit lema.exec-source/v2 manifest, inspect or customize execution budgets (--steps, --allocation-bytes, --bigint-bits, --call-depth, --seconds), verify ConstantTime and SecretFlow static guarantees, or register an installed lema-vm-runner binary on a deployment host.
Before you start
- Matching
lemaandlema-vm-runnerbinaries built from the same commit (Set up a machine for Lema). - A store where the application’s entry declaration and transitive dependencies have been accepted by the pinned Lean 4.34.1 kernel.
1. Quick path: automatic project builds (lema run and lema release)
If you are working inside a lema.json project (Work with a Lema project), you do not need to write a manifest file by hand:
lema add src/Main.lean
lema run Hello.app --input input.txt
lema release Hello.appWhen you run lema run or lema release:
- Lema inspects the accepted type of
Hello.appin.lema/store, automatically infers theProgcommand families it uses (tasks,actors,sessions,tcp,udp,block,random,clock,secret,exchange, orserve), and writes or updates a storedlema.exec/v2record (crates/lema-cli/src/exec_records.rs). - Lema compiles the accepted closure to
LemaIRand writes a verified compile memo into.lema/store/vm-code-cache(LEMA-352). Whenever the accepted root IDs, compiler version, and target (vm) remain unchanged, subsequent runs reuse.lema/store/vm-code-cacheimmediately without recompiling.
2. Import an explicit lema.exec-source/v2 manifest (lema exec import)
For production applications such as the Collector (apps/collector-vm.json) or the Escrow Ledger (apps/escrow-ledger-vm.json), an explicit lema.exec-source/v2 manifest pins the entry alias, allowed command families, resource budgets, wall-clock deadline, and required static guarantee profiles:
{
"schema": "lema.exec-source/v2",
"doc": "Collector over BlockStore and SecretExchange.",
"entry": {
"kind": "app",
"root": "Lema.Cap.Collector.Fixture.app",
"families": ["block", "clock", "exchange"]
},
"roots": ["Lema.Cap.Collector.Fixture.app"],
"limits": {
"steps": 100000000000,
"allocation_bytes": 536870912,
"bigint_bits": 1048576,
"call_depth": 8192
},
"seconds": 240,
"guarantees": [
{"profile": "ConstantTime", "scope": "application"},
{"profile": "SecretFlow.SigV4", "scope": "application"},
{"profile": "SecretFlow.BearerHeader", "scope": "application"}
]
}Import the lema.exec-source/v2 manifest into your store as a resolved lema.exec/v2 record under an entry alias (such as collector.vm):
lema exec import --manifest apps/collector-vm.json --entry collector.vm --expect noneYou can also construct a lema.exec/v2 record directly from command-line flags without a JSON file:
lema exec import --entry app.vm --root Hello.app \
--families block,clock --expect current(lema.exec-source/v1 application manifests are retired and refused per LEMA-314; pure lema.exec-source/v1 vectors test manifests in lema test remain supported for regression vector suites.)
3. Build the VM artifact and register the worker (lema build)
Compile the lema.exec/v2 entry to a named VM artifact and register your lema-vm-runner binary in the store:
lema build collector.vm --name collector --worker /usr/local/bin/lema-vm-runner{
"status": "built",
"target": "vm",
"name": "collector",
"id": "d841a902c7e3…",
"guarantees": [
{"profile": "ConstantTime", "verdict": "holds"},
{"profile": "SecretFlow.SigV4", "verdict": "holds"},
{"profile": "SecretFlow.BearerHeader", "verdict": "holds"}
]
}Look at what lema build does in pure Rust (making zero native Lean or C compiler calls):
- Verifies the accepted closure: Confirms that every declaration reachable from
collector.vmcarries a valid kernel receipt in the store under the store’s axiom policy. - Compiles to
LemaIRand caches the compile memo (<store>/vm-code-cache): Translates the canonical expressions into register-basedLemaIR(lema.ir/v1, prepared with flat code, a single register stack, shared branch slots, and linear secret storage) and caches the verified compile memo in<store>/vm-code-cache. - Runs static guarantee analyzers (
ConstantTimeandSecretFlow):ConstantTimechecks overLemaIRthat no secret value decides a branch condition, indexes memory, or reaches a variable-time primitive.SecretFlow.<role>checks structurally that secrets only enter through approved pinnedexchangeorservedrivers and that their continuations never leak secret bytes.- If any requested profile fails,
lema buildrefuses the build and prints the first offendingLemaIRinstruction and function name.
- Registers the local worker (
<store>/vm-workers/<sha256>.json): Hashes/usr/local/bin/lema-vm-runner, verifies that its version and target ABI matchlema, writes the worker registration inside the store, and writes the artifact directory (manifest.json, compiledLemaIRcode, and worker binding).
Why deployment hosts run lema build once after checkpoint import
When you transfer a store to a deployment host using lema export / lema import (or lema checkpoint), the imported store never automatically trusts a binary worker path on the receiving machine. Running lema build collector.vm --name collector --worker /usr/local/bin/lema-vm-runner on the deployment host requires no Lean installation, registers /usr/local/bin/lema-vm-runner in <store>/vm-workers/, and reproduces the exact same artifact id when the store closure and worker bytes match.
4. Cut a release and run (lema release and lema run --release)
Once built, bind the artifact to your deployment configuration (lema-cap.json) and run it through the release gate (Release an application):
lema release create --artifact collector --deployment /srv/collector/deploy
lema run --release $RELEASE_ID --artifact collector --deployment /srv/collector/deploy --input collector.inputRemember that any application that uses secrets (Io::Secret, exchange, or serve) must hold ConstantTime and SecretFlow.<role> receipts and must be executed via lema run --release; unverified direct runs are refused by the admission gate (LEMA-421).
Common refusals
| Refusal message contains | Cause and fix |
|---|---|
missing or different worker registration | The worker binary has not been registered in this store yet (or was updated). Run lema build ENTRY --name NAME --worker PATH on this store. |
ConstantTime failed or SecretFlow... failed | A secret value branched, indexed memory, or flowed outside an approved pinned exchange/server sink. Fix the offending function reported in the diagnostic. |
application uses secrets and must run through a release | You ran lema run without --release on an app that names Io::Secret, exchange, or serve. Create a release (lema release) and run lema run --release. |
lema.exec-source/v1 is retired for applications | Upgrade the manifest schema to lema.exec-source/v2 (LEMA-314). |
Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility