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/
.cambrian-manifest.json # list of generated files with SHA-256 hashes
src/
Counter.sol # Solidity ^0.8.24: Counter + CambrianFactory
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.
On EVM every entity is deployed with CREATE2 through the generated
CambrianFactory contract, emitted in the same file. Counter’s constructor
takes the factory address, so deploy the factory and call
deployCounter() on it rather than new Counter() directly.
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-git when needed,
then prints the usual forge test / profile hints. In project mode the
contracts live in src/_counter_project.sol; src/Counter.sol is a stub
that imports it.
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
Core.lean # vendored domain-free foundations (U256, results, ...)
Evm.lean # vendored EVM domain (MsgCtx, SysCtx, WorldState)
Prelude.lean # imports SimpAttrs, Core and Evm
Generated/
World.lean
Counter.lean
CounterRoutes.lean
CounterSpec.lean # when test / property sources are included
Adding counter.test.cam through --project (with target: lean) also
emits specification modules derived from those tests.
Useful flags while iterating
# Parse, validate and check target compatibility without writing files
./target/release/cambrian-transpiler contracts/counter.cam --check --target lean
# See the parsed program without writing files
./target/release/cambrian-transpiler contracts/counter.cam --dump-ast
Next steps
- Language Guide for the full surface
- Targets for per-backend details