Skip to content

Instantly share code, notes, and snippets.

@mcpherrinm
Created June 13, 2014 20:31
calling rust from python
mm@cereal:~/dytest$ rustc -C prefer-dynamic --crate-type=dylib fooz.rs
mm@cereal:~/dytest$ cat fooz.rs
#[no_mangle]
pub extern "C" fn foo(x: int) {
println!("Cowabunga, {}", x);
}
mm@cereal:~/dytest$ cat test.py
import ctypes
fooz = ctypes.CDLL("/home/mm/dytest/libfooz-afaf02c9-0.0.so")
fooz.foo(3)
mm@cereal:~/dytest$ python test.py
Cowabunga, 3
mm@cereal:~/dytest$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment