-
Notifications
You must be signed in to change notification settings - Fork 49
Update documentation #1254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update documentation #1254
Changes from 33 commits
a282628
6b8f6d0
03bce62
655d438
5fc6372
b6ada90
6cd39dd
f36784d
107ee68
b2cfadb
a465209
34e5c6a
722ea69
5b18317
5ef2c42
49f3d6a
c42454d
8002c24
cac4d34
2d9365f
4a78d2b
88b8c87
56b4723
b755bab
580521a
da5c08d
286c666
ee28e90
2822583
717935e
663b5c5
da4c780
ffb66ad
a6858ab
567fc74
753f850
82022da
ab53ab1
aea8b7e
76a7235
3e9307d
dc471bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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][]. | ||
|
|
@@ -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 | ||
|
|
@@ -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**): | ||
|
|
@@ -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. | ||
|
|
||
|
|
@@ -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. | ||
|
|
@@ -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. | ||
|
|
@@ -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. | ||
|
|
@@ -197,6 +204,7 @@ Options: | |
| ``` | ||
|
|
||
| ### `cairo-native-dump` | ||
|
|
||
| ```bash | ||
| Usage: cairo-native-dump [OPTIONS] <INPUT> | ||
|
|
||
|
|
@@ -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. | ||
|
|
@@ -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. | ||
|
|
@@ -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: ] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's no default, I think it's preferable to specify
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FrancoGiachetta do you mean that we should add something like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| --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 | ||
|
|
@@ -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. | ||
|
|
||
|
|
@@ -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. | ||
|
|
||
|
|
@@ -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. | ||
FrancoGiachetta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Usage: starknet-native-compile [OPTIONS] <PATH> <OUTPUT> | ||
|
|
||
| Arguments: | ||
| <PATH> The path of the Sierra file to compile | ||
| <OUTPUT> The output file path | ||
FrancoGiachetta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.