Initial binding infrastructure

This commit is contained in:
Martin Häcker 2024-06-27 21:34:41 +02:00
parent 2b68c899b2
commit 0e312a9d28
9 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,13 @@
[package]
name = "servicepoint_binding_py"
metadata.maturin.name = "servicepoint"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "servicepoint_binding_py"
crate-type = ["cdylib"]
[dependencies]
pyo3 = "0.21.1"

View file

@ -0,0 +1,6 @@
.phony:
build:
cargo build
pip uninstall -y servicepoint
pip install --editable .
python -c "import servicepoint as s; print(dir(s)); print(dir(s.rust_bindings))"

View file

View file

@ -0,0 +1,17 @@
[build-system]
requires = ["maturin>=1.6,<2.0"]
build-backend = "maturin"
[project]
name = "servicepoint"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
[tool.maturin]
module-name = "servicepoint.rust_bindings"
features = ["pyo3/extension-module"]

View file

@ -0,0 +1 @@
*.so

View file

@ -0,0 +1,5 @@
from . import rust_bindings
__doc__ = rust_bindings.__doc__
if hasattr(rust_bindings, "__all__"):
__all__ = rust_bindings.__all__

View file

@ -0,0 +1,16 @@
use pyo3::prelude::*;
/// Formats the sum of two numbers as string.
#[pyfunction]
#[pyo3(name = "fnord")]
pub fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}
/// A Python module implemented in Rust.
#[pymodule]
#[pyo3(name = "rust_bindings")]
fn servicepoint_binding_py(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
Ok(())
}