#cargo #cdylib #cbindgen #python #edit #bindings #set #build #type #wheel

app cargo-wheel

Use milksnake and cbindgen to generate python binding to your Rust crate

3 unstable releases

Uses new Rust 2021

0.2.1 Jun 7, 2022
0.2.0 Jan 10, 2019
0.1.0 Nov 24, 2018

#673 in Development tools

MIT license

15KB
238 lines

cargo-wheel

Use milksnake and cbindgen to generate python binding to your Rust crate.

Quick start

Edit your Cargo.toml and set the crate type to cdylib

[lib]
crate-type = ["cdylib"]

Export functions or datastructures in your library to make them visible to C.

#[no_mangle]
pub extern fn greet() {
    println!("Hello from Rust");
}

Call cargo wheel to invoke cbindgen and set up a python package.

cargo wheel

Use cffi in the generated __init__.py to expose the functionality to python

from test_lib._native import ffi, lib

def greet():
    lib.greet()

Why you want to use cargo-wheel

To save boilerplate if creating python bindings for a Rust crate

Why you do not want to use cargo wheel

Scenarios where you want to invoke cargo from your setup.py rather than the other way around. E.g. If you want to replace python code with Rust in an existing wheel.

Dependencies

~44MB
~1M SLoC