I have a rust library which provides useful functionality for use in other rust programs. Additionally I would like to provide this functionality as a python extension (using pyo3 and setuptools-rust, although most of this is tool agnostic)
The documentation examples all show a single library. This means that anyone building the rust library and using it in the rust ecosystem needs the python headers and gets the exported python module as well.
How can I separate this as an independent rust library offering the functionality in rust and a python package offering the functionality in python?
After some experimentation I have arrived on the following setup which makes use of rust workspaces:
Directory structure:
Where:
fizzbuzzcontains the pure rust implementationfizzbuzzo3contains the pyo3 wrapped version for pythonfizzbuzzpycontains additional native python functionality and pytest testsConfig files:
fizzbuzz/Cargo.tomlfizzbuzzo3/Cargo.toml./Cargo.tomlpyproject.tomlHow To:
~/Fizzbuzz/fizzbuzz$ cargo test -v~/Fizzbuzz/fizzbuzzo3$ cargo test -v~/Fizzbuzz$ cargo test -v(.venv) ~/Fizzbuzz$ pip install -e .[dev] && pytestThe full codebase is at: MusicalNinjaDad/FizzBuzz if you want to look in more detail.