Skip to content

Commit 5fa909d

Browse files
authored
Merge pull request #68 from alex/monkey-patch-different
Make setuptools-rust play nice with cffi
2 parents c571b34 + 215ce76 commit 5fa909d

File tree

14 files changed

+500
-164
lines changed

14 files changed

+500
-164
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ script:
2626
- cd html-py-ever
2727
- pip install -r requirements-dev.txt
2828
- python setup.py install
29-
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then cd test && pytest; fi
29+
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then cd test && pytest && cd ..; fi
30+
- cd ..
31+
- cd examples/
32+
# PEP517 build isolation means we don't use the setuptools-rust locally,
33+
# instead it installs from PyPI!
34+
- pip install -U pip
35+
- pip install --no-use-pep517 -e rust_with_cffi/
36+
- pytest rust_with_cffi/tests.py

examples/rust_with_cffi/Cargo.lock

Lines changed: 286 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rust_with_cffi/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "rust_with_cffi"
3+
version = "0.1.0"
4+
authors = ["Alex Gaynor <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
pyo3 = { version = "0.11.1", features = ["extension-module"]}
9+
10+
[lib]
11+
name = "rust_with_cffi"
12+
crate-type = ["cdylib"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cffi
2+
3+
4+
ffi = cffi.FFI()
5+
ffi.cdef("""
6+
int cffi_func(void);
7+
""")
8+
ffi.set_source("rust_with_cffi.cffi", """
9+
int cffi_func(void) {
10+
return 15;
11+
}
12+
""")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel", "setuptools-rust", "cffi"]

examples/rust_with_cffi/rust_with_cffi/__init__.py

Whitespace-only changes.

examples/rust_with_cffi/setup.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
import sys
3+
4+
from setuptools import setup
5+
6+
from setuptools_rust import RustExtension
7+
8+
setup_requires = ["setuptools-rust>=0.10.1", "wheel", "cffi"]
9+
install_requires = ["cffi"]
10+
11+
setup(
12+
name="rust-with-cffi",
13+
version="0.1.0",
14+
classifiers=[
15+
"License :: OSI Approved :: MIT License",
16+
"Development Status :: 3 - Alpha",
17+
"Intended Audience :: Developers",
18+
"Programming Language :: Python",
19+
"Programming Language :: Rust",
20+
"Operating System :: POSIX",
21+
"Operating System :: MacOS :: MacOS X",
22+
],
23+
packages=["rust_with_cffi"],
24+
rust_extensions=[RustExtension("rust_with_cffi.rust")],
25+
cffi_modules=["cffi_module.py:ffi"],
26+
install_requires=install_requires,
27+
setup_requires=setup_requires,
28+
include_package_data=True,
29+
zip_safe=False,
30+
)

examples/rust_with_cffi/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use pyo3::prelude::*;
2+
use pyo3::wrap_pyfunction;
3+
4+
#[pyfunction]
5+
fn rust_func() -> PyResult<u64> {
6+
return Ok(14);
7+
}
8+
9+
#[pymodule]
10+
fn rust(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
11+
m.add_wrapped(wrap_pyfunction!(rust_func))?;
12+
13+
Ok(())
14+
}

examples/rust_with_cffi/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from rust_with_cffi import rust
2+
from rust_with_cffi.cffi import lib
3+
4+
5+
def test_rust():
6+
assert rust.rust_func() == 14
7+
8+
9+
def test_cffi():
10+
assert lib.cffi_func() == 15

0 commit comments

Comments
 (0)