diff --git a/crates/servicepoint_binding_py/Cargo.toml b/crates/servicepoint_binding_py/Cargo.toml new file mode 100644 index 0000000..443c2e9 --- /dev/null +++ b/crates/servicepoint_binding_py/Cargo.toml @@ -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" diff --git a/crates/servicepoint_binding_py/Makefile b/crates/servicepoint_binding_py/Makefile new file mode 100644 index 0000000..7f4729c --- /dev/null +++ b/crates/servicepoint_binding_py/Makefile @@ -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))" diff --git a/crates/servicepoint_binding_py/Readme.md b/crates/servicepoint_binding_py/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/crates/servicepoint_binding_py/examples/fnord_sign/example.py b/crates/servicepoint_binding_py/examples/fnord_sign/example.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/crates/servicepoint_binding_py/examples/fnord_sign/example.py @@ -0,0 +1 @@ + diff --git a/crates/servicepoint_binding_py/examples/fnord_sign/pyproject.toml b/crates/servicepoint_binding_py/examples/fnord_sign/pyproject.toml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/crates/servicepoint_binding_py/examples/fnord_sign/pyproject.toml @@ -0,0 +1 @@ + diff --git a/crates/servicepoint_binding_py/pyproject.toml b/crates/servicepoint_binding_py/pyproject.toml new file mode 100644 index 0000000..036c09a --- /dev/null +++ b/crates/servicepoint_binding_py/pyproject.toml @@ -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"] diff --git a/crates/servicepoint_binding_py/servicepoint/.gitignore b/crates/servicepoint_binding_py/servicepoint/.gitignore new file mode 100644 index 0000000..140f8cf --- /dev/null +++ b/crates/servicepoint_binding_py/servicepoint/.gitignore @@ -0,0 +1 @@ +*.so diff --git a/crates/servicepoint_binding_py/servicepoint/__init__.py b/crates/servicepoint_binding_py/servicepoint/__init__.py new file mode 100644 index 0000000..b7abcca --- /dev/null +++ b/crates/servicepoint_binding_py/servicepoint/__init__.py @@ -0,0 +1,5 @@ +from . import rust_bindings + +__doc__ = rust_bindings.__doc__ +if hasattr(rust_bindings, "__all__"): + __all__ = rust_bindings.__all__ diff --git a/crates/servicepoint_binding_py/src/lib.rs b/crates/servicepoint_binding_py/src/lib.rs new file mode 100644 index 0000000..cc880d9 --- /dev/null +++ b/crates/servicepoint_binding_py/src/lib.rs @@ -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 { + 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(()) +}