This is an experiment in combining PyO3 and
Hatch, instead of using
maturin
or
setuptools-rust. Cargo
gets called via a custom build
hook
implemented in cargo_build.py
. The hook is
configured in pyproject.toml
to run only for the
wheel
target, because there's no point in building the library for a
source distribution.
- The hook assumes that the working directory of
hatchling
is also where the Rust package exists (withCargo.toml
, etc.), and where the compiled module for Python should be placed. - Using custom build targets may need some extra care depending on whether the hook should or shouldn't run. The hook class itself doesn't check the target.