-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a module which tests that this works with cffi
- Loading branch information
Showing
9 changed files
with
373 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "rust_with_cffi" | ||
version = "0.1.0" | ||
authors = ["Alex Gaynor <alex.gaynor@gmail.com>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
pyo3 = { version = "0.11.1", features = ["extension-module"]} | ||
|
||
[lib] | ||
name = "rust_with_cffi" | ||
crate-type = ["cdylib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import cffi | ||
|
||
|
||
ffi = cffi.FFI() | ||
ffi.cdef(""" | ||
int cffi_func(void); | ||
""") | ||
ffi.set_source("rust_with_cffi.cffi", """ | ||
int cffi_func(void) { | ||
return 15; | ||
} | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "setuptools-rust", "cffi"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
|
||
from setuptools import setup | ||
|
||
from setuptools_rust import RustExtension | ||
|
||
setup_requires = ["setuptools-rust>=0.10.1", "wheel", "cffi"] | ||
install_requires = ["cffi"] | ||
|
||
setup( | ||
name="rust-with-cffi", | ||
version="0.1.0", | ||
classifiers=[ | ||
"License :: OSI Approved :: MIT License", | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Developers", | ||
"Programming Language :: Python", | ||
"Programming Language :: Rust", | ||
"Operating System :: POSIX", | ||
"Operating System :: MacOS :: MacOS X", | ||
], | ||
packages=["rust_with_cffi"], | ||
rust_extensions=[RustExtension("rust_with_cffi.rust")], | ||
cffi_modules=["cffi_module.py:ffi"], | ||
install_requires=install_requires, | ||
setup_requires=setup_requires, | ||
include_package_data=True, | ||
zip_safe=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use pyo3::prelude::*; | ||
use pyo3::wrap_pyfunction; | ||
|
||
#[pyfunction] | ||
fn rust_func() -> PyResult<u64> { | ||
return Ok(14); | ||
} | ||
|
||
#[pymodule] | ||
fn rust(_py: Python<'_>, m: &PyModule) -> PyResult<()> { | ||
m.add_wrapped(wrap_pyfunction!(rust_func))?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rust_with_cffi import rust | ||
from rust_with_cffi.cffi import lib | ||
|
||
|
||
def test_rust(): | ||
assert rust.rust_func() == 14 | ||
|
||
|
||
def test_cffi(): | ||
assert lib.cffi_func() == 15 |