diff --git a/Cargo.lock b/Cargo.lock index 0feeed0..598c75e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -333,6 +333,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indoc" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -374,6 +380,16 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.21" @@ -386,6 +402,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -407,12 +432,41 @@ version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + [[package]] name = "pkg-config" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -428,6 +482,69 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pyo3" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +dependencies = [ + "cfg-if", + "indoc", + "libc", + "memoffset", + "parking_lot", + "portable-atomic", + "pyo3-build-config", + "pyo3-ffi", + "pyo3-macros", + "unindent", +] + +[[package]] +name = "pyo3-build-config" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +dependencies = [ + "once_cell", + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "pyo3-macros" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +dependencies = [ + "proc-macro2", + "pyo3-macros-backend", + "quote", + "syn 2.0.68", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "pyo3-build-config", + "quote", + "syn 2.0.68", +] + [[package]] name = "quote" version = "1.0.36" @@ -473,6 +590,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.6.0", +] + [[package]] name = "regex" version = "1.10.5" @@ -531,6 +657,12 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.203" @@ -593,6 +725,19 @@ dependencies = [ "servicepoint_binding_c", ] +[[package]] +name = "servicepoint_binding_py" +version = "0.1.0" +dependencies = [ + "pyo3", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "strsim" version = "0.10.0" @@ -633,6 +778,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "target-lexicon" +version = "0.12.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" + [[package]] name = "tempfile" version = "3.10.1" @@ -675,6 +826,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unindent" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" + [[package]] name = "utf8parse" version = "0.2.2" 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(()) +}