Skip to content

Commit

Permalink
Initial binding infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
dwt committed Jun 27, 2024
1 parent ea0335c commit 8454be8
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 0 deletions.
157 changes: 157 additions & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions crates/servicepoint_binding_py/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions crates/servicepoint_binding_py/Makefile
Original file line number Diff line number Diff line change
@@ -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))"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

17 changes: 17 additions & 0 deletions crates/servicepoint_binding_py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions crates/servicepoint_binding_py/servicepoint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.so
5 changes: 5 additions & 0 deletions crates/servicepoint_binding_py/servicepoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import rust_bindings

__doc__ = rust_bindings.__doc__
if hasattr(rust_bindings, "__all__"):
__all__ = rust_bindings.__all__
16 changes: 16 additions & 0 deletions crates/servicepoint_binding_py/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit 8454be8

Please sign in to comment.