Skip to content
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a282628
Add some docs. Fix some issues.
azteca1998 Dec 11, 2024
6b8f6d0
More docs.
azteca1998 Dec 12, 2024
03bce62
Minor changes
DiegoCivi Jun 12, 2025
655d438
More minor changes
DiegoCivi Jun 12, 2025
5fc6372
Refactor on src layout
DiegoCivi Jun 12, 2025
b6ada90
Update examples on overview.md
DiegoCivi Jun 13, 2025
6cd39dd
Minor changes on overview.md example
DiegoCivi Jun 13, 2025
f36784d
Minor change
DiegoCivi Jun 13, 2025
107ee68
Remove wrong enum explanation
DiegoCivi Jun 13, 2025
b2cfadb
Fix merge mistake
DiegoCivi Jun 14, 2025
a465209
Remove JitValue references
DiegoCivi Jun 17, 2025
34e5c6a
Apply comments
DiegoCivi Jun 18, 2025
722ea69
Remove outdated link
DiegoCivi Jun 18, 2025
5b18317
Change cairo-native-run example file
DiegoCivi Jun 19, 2025
5ef2c42
Update runtime info
DiegoCivi Jun 19, 2025
49f3d6a
Update tools help message
DiegoCivi Jun 19, 2025
c42454d
Undo changes on compile.rs
DiegoCivi Jun 19, 2025
8002c24
Update example on overview.md
DiegoCivi Jun 23, 2025
cac4d34
Add AotContractExecutor
DiegoCivi Jun 23, 2025
2d9365f
Merge branch 'main' into update-documentation
FrancoGiachetta Jun 25, 2025
4a78d2b
Merge branch 'main' into update-documentation
DiegoCivi Jul 15, 2025
88b8c87
Update sierra-emu references
DiegoCivi Jul 15, 2025
56b4723
Merge branch 'update-documentation' of github.com:lambdaclass/cairo_n…
DiegoCivi Jul 15, 2025
b755bab
API usage refactor
DiegoCivi Jul 17, 2025
580521a
Refactor of project layout
DiegoCivi Jul 17, 2025
da5c08d
Add tool info
DiegoCivi Jul 17, 2025
286c666
Merge branch 'main' into update-documentation
DiegoCivi Jul 17, 2025
ee28e90
Refactor of runtime explanation
DiegoCivi Jul 17, 2025
2822583
Minor changes
DiegoCivi Jul 17, 2025
717935e
Update docs/overview.md
DiegoCivi Jul 18, 2025
663b5c5
Update docs/execution_walkthrough.md
DiegoCivi Jul 18, 2025
da4c780
Update docs/execution_walkthrough.md
DiegoCivi Jul 18, 2025
ffb66ad
Merge branch 'main' into update-documentation
DiegoCivi Jul 18, 2025
a6858ab
Refactor of starknet-native-compile description
DiegoCivi Jul 22, 2025
567fc74
cairo -> sierra
DiegoCivi Jul 22, 2025
753f850
Update docs/compilation_walkthrough.md
DiegoCivi Jul 22, 2025
82022da
Update docs/compilation_walkthrough.md
DiegoCivi Jul 22, 2025
ab53ab1
Update docs/compilation_walkthrough.md
DiegoCivi Jul 22, 2025
aea8b7e
Update docs/compilation_walkthrough.md
DiegoCivi Jul 22, 2025
76a7235
Minor changes
DiegoCivi Jul 28, 2025
3e9307d
Merge branch 'main' into update-documentation
DiegoCivi Aug 25, 2025
dc471bb
Merge branch 'main' into update-documentation
DiegoCivi Sep 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ endif
.PHONY: deps-macos
deps-macos: build-cairo-2-compiler-macos install-scarb-macos
-brew install llvm@19 --quiet
@echo "You can execute the env-macos.sh script to setup the needed env variables."
@echo "You can execute the env.sh script to setup the needed env variables."

# CI use only
.PHONY: deps-ci-linux build-cairo-2-compiler install-scarb
Expand Down
110 changes: 87 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ to machine code via MLIR and LLVM.

- [Getting Started](#getting-started)
- [Included Tools](#included-tools)
- [Scripts](#scripts)
- [cairo-native-compile](#cairo-native-compile)
- [cairo-native-dump](#cairo-native-dump)
- [cairo-native-run](#cairo-native-run)
- [cairo-native-test](#cairo-native-test)
- [cairo-native-stress](#cairo-native-stress)
- [scarb-native-dump](#scarb-native-dump)
- [scarb-native-test](#scarb-native-test)
- [starknet-native-compile](#starknet-native-compile)
- [Benchmarking](#benchmarking)

For in-depth documentation, see the [developer documentation][].
Expand All @@ -46,6 +46,7 @@ use. This can be done by adding `cairo-native = "0.5.0-rc.6"` to your Cargo.toml
## Getting Started

### Dependencies

- Linux or macOS (aarch64 included) only for now
- LLVM 19 with MLIR: On debian you can use [apt.llvm.org](https://apt.llvm.org/),
on macOS you can use brew
Expand All @@ -54,6 +55,7 @@ use. This can be done by adding `cairo-native = "0.5.0-rc.6"` to your Cargo.toml
- Git

### Setup

> This step applies to all operating systems.

Run the following make target to install the dependencies (**both Linux and macOS**):
Expand All @@ -63,6 +65,7 @@ make deps
```

#### Linux

Since Linux distributions change widely, you need to install LLVM 19 via your
package manager, compile it or check if the current release has a Linux binary.

Expand Down Expand Up @@ -125,6 +128,7 @@ source env.sh
```

#### MacOS

The makefile `deps` target (which you should have ran before) installs LLVM 19
with brew for you, afterwards you need to execute the `env.sh` script to setup
the needed environment variables.
Expand All @@ -134,13 +138,14 @@ source env.sh
```

### Make targets:

Running `make` by itself will check whether the required LLVM installation and
corelib is found, and then list available targets.

```bash
% make
LLVM is correctly set at /opt/homebrew/opt/llvm.
./scripts/check-corelib-version.sh 2.12.0-dev.0
./scripts/check-corelib-version.sh 2.12.0-dev.1
Usage:
deps: Installs the necesary dependencies.
build: Builds the cairo-native library and binaries in release mode.
Expand All @@ -154,28 +159,30 @@ Usage:
doc-open: Builds and opens documentation in browser.
bench: Runs the hyperfine benchmark script.
bench-ci: Runs the criterion benchmarks for CI.
install: Invokes cargo to install the cairo-native tools.
install: Invokes cargo to install cairo-native tools.
clean: Cleans the built artifacts.
stress-test Runs a command which runs stress tests.
stress-plot Plots the results of the stress test command.
stress-clean Clean the cache of AOT compiled code of the stress test command.
```

## Included Tools

Aside from the compilation and execution engine library, Cairo Native includes
a few command-line tools to aid development, and some useful scripts.

These are:
- The contents of the `/scripts/` folder
These are the contents of the `/src/bin` folder
- `cairo-native-compile`
- `cairo-native-dump`
- `cairo-native-run`
- `cairo-native-test`
- `cairo-native-stress`
- `scarb-native-dump`
- `scarb-native-test`
- `starknet-native-compile`

### `cairo-native-compile`

```bash
Compiles a Cairo project outputting the generated MLIR and the shared library.
Exits with 1 if the compilation or run fails, otherwise 0.
Expand All @@ -197,6 +204,7 @@ Options:
```

### `cairo-native-dump`

```bash
Usage: cairo-native-dump [OPTIONS] <INPUT>

Expand All @@ -210,10 +218,11 @@ Options:
```

### `cairo-native-run`

This tool allows to run programs using the JIT engine, like the `cairo-run`
tool, the parameters can only be felt values.

Example: `echo '1' | cairo-native-run 'program.cairo' 'program::program::main' --inputs - --outputs -`
Example: `cairo-native-run --available-gas 10000 './programs/array_get.cairo'`

```bash
Exits with 1 if the compilation or run fails, otherwise 0.
Expand All @@ -234,6 +243,7 @@ Options:
```

### `cairo-native-test`

This tool mimics the `cairo-test`
[tool](https://github.com/starkware-libs/cairo/tree/main/crates/cairo-lang-test-runner)
and is identical to it in interface, the only feature it doesn't have is the profiler.
Expand All @@ -245,36 +255,66 @@ Exits with 1 if the compilation or run fails, otherwise 0.
Usage: cairo-native-test [OPTIONS] <PATH>

Arguments:
<PATH> The Cairo project path to compile and run its tests
<PATH>
The Cairo project path to compile and run its tests

Options:
-s, --single-file Whether path is a single file
--allow-warnings Allows the compilation to succeed with warnings
-f, --filter <FILTER> The filter for the tests, running only tests containing the filter string [default: ]
--include-ignored Should we run ignored tests as well
--ignored Should we run only the ignored tests
--starknet Should we add the starknet plugin to run the tests
--run-mode <RUN_MODE> Run with JIT or AOT (compiled) [default: jit] [possible values: aot, jit]
-O, --opt-level <OPT_LEVEL> Optimization level, Valid: 0, 1, 2, 3. Values higher than 3 are considered as 3 [default: 0]
-h, --help Print help
-V, --version Print version
-s, --single-file
Whether path is a single file

--allow-warnings
Allows the compilation to succeed with warnings

-f, --filter <FILTER>
The filter for the tests, running only tests containing the filter string

[default: ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no default, I think it's preferable to specify none or null, or something similar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure its possible to specify another default value in this case. The default is an empty string --filter "", and the --help command is managed by clap.

Copy link
Contributor

@FrancoGiachetta FrancoGiachetta Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm saying is that I would make more explicit the fact that it's an empty string. It could lead to misunderstandings. I think that something like "", as you said, would be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrancoGiachetta do you mean that we should add something like [default: ""] to that message on the readme? If thats the case, that can be done but it would look different from what the -h message shows on the terminal since that is how clap shows it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its a good idea to have the README message differ from the actual command usage message. If we can configure clap to show [default: ""] it would be great, but it doesn't look easy/possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does not look straightforward. It looks weird in the README though, as if we had forgotten to add that default value. But well, you can this dismiss this comment if you feel like matching the output of clap would be better.


--skip-compilation <SKIP_COMPILATION>
Skips compilation for tests/functions containing any of the given filters. Unlike `--filter`, the matching tests are not even compiled by native.

DISCLAIMER: This is a hacky and temporary flag, used to run corelib tests when not all libfuncs are implemented.

--include-ignored
Should we run ignored tests as well

--ignored
Should we run only the ignored tests

--starknet
Should we add the starknet plugin to run the tests

--run-mode <RUN_MODE>
Run with JIT or AOT (compiled)

[default: jit]
[possible values: aot, jit]

-O, --opt-level <OPT_LEVEL>
Optimization level, Valid: 0, 1, 2, 3. Values higher than 3 are considered as 3

[default: 0]

-h, --help
Print help (see a summary with '-h')

-V, --version
Print version
```

For single files, you can use the `-s, --single-file` option.

For a project, it needs to have a `cairo_project.toml` specifying the
`crate_roots`. You can find an example under the `cairo-tests/` folder, which
is a cairo project that works with this tool.

```bash
cairo-native-test -s myfile.cairo

cairo-native-test ./cairo-tests/
```

For a project, it needs to have a `cairo_project.toml` specifying the
`crate_roots`.

This will run all the tests (functions marked with the `#[test]` attribute).

### `cairo-native-stress`

This tool runs a stress test on Cairo Native.

```bash
Expand Down Expand Up @@ -315,6 +355,7 @@ make stress-clean
```

### `scarb-native-dump`

This tool mimics the `scarb build` [command](https://github.com/software-mansion/scarb/tree/main/extensions/scarb-cairo-test).
You can download it on our [releases](https://github.com/lambdaclass/cairo_native/releases) page.

Expand All @@ -323,6 +364,7 @@ behave like `scarb build`, leaving the MLIR files under the `target/` folder
besides the generated JSON sierra files.

### `scarb-native-test`

This tool mimics the `scarb test` [command](https://github.com/software-mansion/scarb/tree/main/extensions/scarb-cairo-test).
You can download it on our [releases](https://github.com/lambdaclass/cairo_native/releases) page.

Expand All @@ -339,15 +381,37 @@ Options:
-f, --filter <FILTER> Run only tests whose name contain FILTER [default: ]
--include-ignored Run ignored and not ignored tests
--ignored Run only ignored tests
-t, --test-kind <TEST_KIND> Choose test kind to run [possible values: unit, integration, all]
--run-mode <RUN_MODE> Run with JIT or AOT (compiled) [default: jit] [possible values: aot, jit]
-O, --opt-level <OPT_LEVEL> Optimization level, Valid: 0, 1, 2, 3. Values higher than 3 are considered as 3 [default: 0]
-h, --help Print help
-V, --version Print version
```

### `starknet-native-compile`

```bash
Given a Sierra file (as saved in Starknet's contract tree), extracts the sierra_program from
felts into readable Sierra code, compiles it to native, and saves the result to the given output
path.

Usage: starknet-native-compile [OPTIONS] <PATH> <OUTPUT>

Arguments:
<PATH> The path of the Sierra file to compile
<OUTPUT> The output file path

Options:
-O, --opt-level <OPT_LEVEL> Optimization level, Valid: 0, 1, 2, 3. Values higher than 3 are considered as 3 [default: 0]
--stats <STATS> Output path for compilation statistics
-h, --help Print help
-V, --version Print version
```

## Benchmarking

### Requirements

- [hyperfine](https://github.com/sharkdp/hyperfine): `cargo install hyperfine`
- [cairo 2.12.0-dev.0](https://github.com/starkware-libs/cairo)
- Cairo Corelibs
Expand Down
1 change: 0 additions & 1 deletion benches/compile_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ pub fn bench_compile_time(c: &mut Criterion) {
}

criterion_group!(benches, bench_compile_time);

criterion_main!(benches);
2 changes: 1 addition & 1 deletion benches/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn prepare_programs(path: &str) -> Vec<(Arc<Program>, String)> {
.collect::<Vec<_>>()
}

#[allow(unused)] // its used but clippy doesn't detect it well
#[allow(unused)] // Used in `benches/libfuncs.rs`, but not in the others.
pub fn create_vm_runner(program: &Program) -> SierraCasmRunner {
SierraCasmRunner::new(
program.clone(),
Expand Down
Loading
Loading