Package: cairo-rs-py
🐍 Cairo-rs-py 🐍FFI Python bindings for cairo-rsReport Bug·Request FeatureTable of ContentsAboutGetting StartedDependenciesInstallationUsageTestingDemoHow to manually install the script dependenciesBenchmarkingRelated ProjectsLicense📖 Aboutcairo-rs-pyadds Python bindings to thecairo-rsCairo VM.🌅 Getting StartedDependenciesRust and CargoPyenv and Python 3.9GMPmakeInstallationTo set up the Python environment, and install necessary Python libraries, runmake deps. This command builds two virtual environments, one intended for the Rust VM and the other one for the Original Python VM. It also initializes the submodules of some of the projects we integrated with.After setting up the environments, you can install the python binary usingmaturin develop --release.Finally, install into the python environment withmaturin develop --release. For mac installation, these flags might be necessary:maturin develop --release -m cairo-rs-py/Cargo.toml --no-default-features --features extension.🚀 UsageAfter installation, you can access the cairo-rs VM from Python code. As an example, after compiling the programarray_sumintocairo_programs/array_sum.json, you can run it with the VM using:importcairo_rs_pywithopen(f"cairo_programs/array_sum.json")asfile:runner=cairo_rs_py.CairoRunner(file.read(),"main","all",False)runner.cairo_run(True)TestingTo run the test suite:makefull-testDemoThebuild_envs.shscript will build two Python virtual environments:cairo-langcontaining a pristine installation ofcairo-lang==0.10.3;cairo-rs-pycontaining a patched installation ofcairo-lang==0.10.3that usescairo-rs-pyas dependency.
It will also install the required dependencies automatically in Debian-based distributions, CentOs, Fedora and OSX.
If you use another OS, you can check how to install them manually below.To run the script:./scripts/build_envs.shBoth virtual environment will be created under the/scriptsdirectory.To actually use any of the implementations, you would have to activate the environment you want. For example, to use the cairo-rs-py integration you need to run:sourcescripts/cairo-rs-py/bin/activateAfter activating the cairo-rs-py virtualenv you can try out any Cairo project and it will use cairo-rs. In some cases some projects are coupled to cairo-run or need some extra patching to be able to use the Cairo-rs runner (e.g. Protostar, Zerosync).Note that the script assumes you have a Rust toolchain, Python 3.9 and thevenvprogram installed.How to manually install the script dependenciescairo-langrequires thegmplibrary to build.
You can install it on Debian-based GNU/Linux distributions with:sudoaptinstall-ylibgmp3-devIn Mac you can use Homebrew:brewinstallgmpIn Mac you'll also need to tell the script where to find the gmp lib:exportCFLAGS=-I/opt/homebrew/opt/gmp/includeLDFLAGS=-L/opt/homebrew/opt/gmp/lib
shbuild_envs.sh📊 BenchmarkingTo run the benchmarks of the projects we integrated with, first you need to set up the dependencies:makebenchmark-depsLastly, run make + the project you desire to try:benchmark-devnet🌞 Related Projectscairo-rs: A fast implementation of the Cairo VM in Rust.starknet_in_rust: implementation of Starknet in Rust, powered by the cairo-rs VM.⚖️ LicenseThis project is licensed under the Apache 2.0 license.SeeLICENSEfor more information.