Giter VIP home page Giter VIP logo

cairo-rs-py's Introduction

cairo-rs-py

rust codecov

cairo-rs-py adds Python bindings to the cairo-rs Cairo VM.

Dependencies

  • Rust and Cargo
  • Pyenv and Python 3.9
  • GMP
  • make

Using cairo-rs-py

To setup the Python environment, and install necessary Python libraries, run make deps.

Finally, install into the python environment with maturin develop --release.

After that, you can access the cairo-rs VM from Python code. As an example, after compiling the program array_sum into cairo_programs/array_sum.json, you can run it with the VM using:

import cairo_rs_py

with open(f"cairo_programs/array_sum.json") as file:
    runner = cairo_rs_py.CairoRunner(file.read(), "main", "all", False)
    runner.cairo_run(True)

Testing

To run the test suite:

make full-test

Script to try out cairo-rs-py

The build_envs.sh script will build two Python virtual environments:

  • cairo-lang containing a pristine install of cairo-lang==0.10.3;
  • cairo-rs-py containing a patched install of cairo-lang==0.10.3 that uses cairo-rs-py as 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.sh

Both virtualenvs will be created under the /scripts directory.

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:

source activate scripts/cairo-rs-py/bin/activate

After activating the cairo-rs-py virtualenv you can try out any Cairo project and it will use cairo-rs.

Note that the script assumes you have a Rust toolchain, Python 3.9 and the venv program installed.

How to manually install the script dependencies

cairo-lang requires the gmp library to build. You can install it on Debian-based GNU/Linux distributions with:

sudo apt install -y libgmp3-dev

In Mac you can use Homebrew:

brew install gmp

In Mac you'll also need to tell the script where to find the gmp lib:

export CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib
sh build_envs.sh

cairo-rs-py's People

Contributors

fmoletta avatar pefontana avatar entropidelic avatar mmsc2 avatar juanbono avatar azteca1998 avatar juan-m-v avatar santiagopittella avatar jrigada avatar raefko avatar unbalancedparentheses avatar oppen avatar megaredhand avatar hermanobst avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.