Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Compile and Test

This page turns contracts/counter.cam into backend projects you can build and test. Run the commands from the cambrian-lang repository root (or pass absolute paths to the .cam file). Examples use ./target/release/cambrian-transpiler; substitute cambrian-transpiler if the binary is on your PATH.

EVM: transpile and Foundry

Entity only

./target/release/cambrian-transpiler contracts/counter.cam \
  -o /tmp/counter-evm --target evm

Output for the plain entity:

/tmp/counter-evm/
  src/
    Counter.sol    # Solidity ^0.8.24 contract

The transpiler prints a reminder such as cd /tmp/counter-evm && bash setup.sh && forge test. With only the entity source (no test / fuzz / invariant declarations), that Foundry scaffolding is not emitted—you still have a readable Counter.sol to compile or deploy with your own Foundry project.

With Cambrian tests (Foundry harness)

To generate foundry.toml, setup.sh, and test/Counter.t.sol, include contracts/counter.test.cam via a project file. Source paths are resolved relative to the YAML file’s directory.

From the cambrian-lang root, write counter-evm.yaml:

name: counter
target: evm
output_dir: /tmp/counter-evm
sources:
  - contracts/counter.cam
  - contracts/counter.test.cam
./target/release/cambrian-transpiler --project counter-evm.yaml
cd /tmp/counter-evm
bash setup.sh    # installs forge-std into lib/ if missing
forge test

setup.sh runs forge install foundry-rs/forge-std --no-commit when needed, then prints the usual forge test / profile hints.

Lean: same source, Lake project

./target/release/cambrian-transpiler contracts/counter.cam \
  -o /tmp/counter-lean --target lean
cd /tmp/counter-lean && lake build

Or let the CLI run Lake for you:

./target/release/cambrian-transpiler contracts/counter.cam \
  -o /tmp/counter-lean --target lean --check-lean

Typical layout (for contracts/counter.cam on current transpilers):

/tmp/counter-lean/
  lakefile.toml
  lean-toolchain
  Cambrian.lean
  Cambrian/
    SimpAttrs.lean
    Prelude.lean          # bundled prelude (Core / Evm pieces live here)
    Generated/
      World.lean
      Counter.lean
      CounterRoutes.lean
      CounterSpec.lean    # when test / property sources are included
  ...

Older docs sometimes listed separate Core.lean / Evm.lean files; those modules are vendored inside Prelude.lean for entity-only emits.

Adding counter.test.cam through --project (with target: lean) also emits specification modules derived from those tests.

Useful flags while iterating

# See the parsed program without writing files
./target/release/cambrian-transpiler contracts/counter.cam --dump-ast

# Emit source maps next to generated code (supported backends)
./target/release/cambrian-transpiler contracts/counter.cam \
  -o /tmp/counter-evm --target evm --source-map

Next steps