diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e2a9197 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include Cargo.toml +recursive-include crates *.rs +recursive-include src * diff --git a/crates/.gitignore b/crates/.gitignore new file mode 100644 index 0000000..6985cf1 --- /dev/null +++ b/crates/.gitignore @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb diff --git a/crates/Cargo.toml b/crates/Cargo.toml new file mode 100644 index 0000000..4f6e006 --- /dev/null +++ b/crates/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "crates" +version = "0.1.0" + +[lib] +name = "_lib" +crate-type = ["cdylib"] +path = "src/lib.rs" + +[dependencies] +pyo3 = { version = "0.21.0", features = ["extension-module"] } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +# See also PyO3 docs on writing Cargo.toml files at https://pyo3.rs diff --git a/crates/src/basic_functions/basic_math.rs b/crates/src/basic_functions/basic_math.rs new file mode 100644 index 0000000..75ae69e --- /dev/null +++ b/crates/src/basic_functions/basic_math.rs @@ -0,0 +1,13 @@ +use pyo3::prelude::*; + +#[pyfunction] +#[pyo3(text_signature = "(a, b, /)")] +pub fn add_in_rust(a: i32, b: i32) -> PyResult { + Ok(a + b) +} + +#[pyfunction] +#[pyo3(text_signature = "(a, b, /)")] +pub fn subtract_in_rust(a: i32, b: i32) -> PyResult { + Ok(a - b) +} diff --git a/crates/src/basic_functions/mod.rs b/crates/src/basic_functions/mod.rs new file mode 100644 index 0000000..c9b3972 --- /dev/null +++ b/crates/src/basic_functions/mod.rs @@ -0,0 +1,2 @@ +//mod.rs +pub mod basic_math; diff --git a/crates/src/lib.rs b/crates/src/lib.rs new file mode 100644 index 0000000..e8aa15a --- /dev/null +++ b/crates/src/lib.rs @@ -0,0 +1,14 @@ +//src/lib.rs + +pub mod basic_functions; +use crate::basic_functions::*; + +use pyo3::prelude::*; + +#[pymodule] +fn quippers(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(basic_math::add_in_rust, m)?)?; + m.add_function(wrap_pyfunction!(basic_math::subtract_in_rust, m)?)?; + + Ok(()) +} diff --git a/pyproject.toml b/pyproject.toml index 339cf01..2700e4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "wheel"] +requires = ["setuptools", "wheel", "setuptools_rust"] build-backend = "setuptools.build_meta" [project] @@ -36,3 +36,12 @@ fix = true [tool.isort] profile = "black" + + +[[tool.setuptools-rust.ext-modules]] +# Private Rust extension module to be nested into the Python package +# https://github.com/PyO3/setuptools-rust?tab=readme-ov-file +target = "{{project_name}}._lib" # The last part of the name (e.g. "_lib") has to match lib.name in Cargo.toml, +# but you can add a prefix to nest it inside of a Python package. +path = "Cargo.toml" # Default value, can be omitted +binding = "PyO3" # Default value, can be omitted