Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setuptools-rust play nice with cffi #68

Merged
merged 2 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ script:
- cd html-py-ever
- pip install -r requirements-dev.txt
- python setup.py install
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then cd test && pytest; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then cd test && pytest && cd ..; fi
- cd ..
- cd examples/
# PEP517 build isolation means we don't use the setuptools-rust locally,
# instead it installs from PyPI!
- pip install -U pip
- pip install --no-use-pep517 -e rust_with_cffi/
- pytest rust_with_cffi/tests.py
286 changes: 286 additions & 0 deletions examples/rust_with_cffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/rust_with_cffi/Cargo.toml
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 <[email protected]>"]
edition = "2018"

[dependencies]
pyo3 = { version = "0.11.1", features = ["extension-module"]}

[lib]
name = "rust_with_cffi"
crate-type = ["cdylib"]
12 changes: 12 additions & 0 deletions examples/rust_with_cffi/cffi_module.py
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;
}
""")
2 changes: 2 additions & 0 deletions examples/rust_with_cffi/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust", "cffi"]
Empty file.
30 changes: 30 additions & 0 deletions examples/rust_with_cffi/setup.py
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,
)
14 changes: 14 additions & 0 deletions examples/rust_with_cffi/src/lib.rs
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(())
}
10 changes: 10 additions & 0 deletions examples/rust_with_cffi/tests.py
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
Loading