Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
⚡ Cairo Native ⚡
A compiler to convert Cairo's intermediate representation "Sierra" code to machine code via MLIR and LLVM.
For in-depth documentation, see the developer documentation.
Disclaimer
🚧 Cairo Native is still being built therefore API breaking changes might happen often so use it at your own risk. 🚧
For versions under 1.0
cargo
doesn't comply with
semver, so we advise to pin the version the version you
use. This can be done by adding cairo-native = "0.1.0"
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, on macOS you can use brew
- Rust 1.78.0 or later, since we make use of the u128 abi change.
- Git
Setup
This step applies to all operating systems.
Run the following make target to install the dependencies (both Linux and macOS):
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.
If you are on Debian/Ubuntu, check out the repository https://apt.llvm.org/ Then you can install with:
If you decide to build from source, here are some indications:
# Go to https://github.com/llvm/llvm-project/releases
# Download the latest LLVM 19 release:
# The blob to download is called llvm-project-19.x.x.src.tar.xz
# For example
# The following cmake command configures the build to be installed to /opt/llvm-19
Setup a environment variable called MLIR_SYS_190_PREFIX
, LLVM_SYS_191_PREFIX
and TABLEGEN_190_PREFIX
pointing to the llvm directory:
# For Debian/Ubuntu using the repository, the path will be /usr/lib/llvm-19
Alternatively, if installed from Debian/Ubuntu repository, then you can use
env.sh
to automatically setup the environment variables.
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.
Make targets:
Running make
by itself will check whether the required LLVM installation and
corelib is found, and then list available targets.
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 cairo-native-compile
cairo-native-dump
cairo-native-run
cairo-native-test
cairo-native-stress
scarb-native-dump
scarb-native-test
cairo-native-compile
<PATH> The
cairo-native-dump
<INPUT>
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 -
<PATH> The
)
cairo-native-test
This tool mimics the cairo-test
tool
and is identical to it in interface, the only feature it doesn't have is the profiler.
<PATH> The
)
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.
This will run all the tests (functions marked with the #[test]
attribute).
cairo-native-stress
This tool runs a stress test on Cairo Native.
<ROUNDS>
)
To quickly run a stress test and save logs as json, run:
This takes a lot of time to finish (it will probably crash first), you can kill the program at any time.
To plot the results, run:
To clear the cache directory, run:
scarb-native-dump
This tool mimics the scarb build
command.
You can download it on our releases page.
This tool should be run at the directory where a Scarb.toml
file is and it will
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.
You can download it on our releases page.
) )
)
Benchmarking
Requirements
- hyperfine:
cargo install hyperfine
- cairo 2.9.0-dev.0
- Cairo Corelibs
- LLVM 19 with MLIR
You need to setup some environment variables:
$MLIR_SYS_190_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations.
$LLVM_SYS_191_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations.
$TABLEGEN_190_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations.
You can then run the bench
makefile target:
The bench
target will run the ./scripts/bench-hyperfine.sh
script.
This script runs hyperfine commands to compare the execution time of programs in the ./programs/benches/
folder.
Each program is compiled and executed via the execution engine with the cairo-native-run
command and via the cairo-vm with the cairo-run
command provided by the cairo
codebase.
The cairo-run
command should be available in the $PATH
and ideally compiled with cargo build --release
.
If you want the benchmarks to run using a specific build, or the cairo-run
commands conflicts with something (e.g. the cairo-svg package binaries in macos) then the command to run cairo-run
with a full path can be specified with the $CAIRO_RUN
environment variable.