libtorrent icon indicating copy to clipboard operation
libtorrent copied to clipboard

Replace deprecated distutils for building Python bindings

Open cas-- opened this issue 5 months ago • 0 comments

This issue is a continuation of a discussion in PR about building Python wheels and how we can reduce the current complexity.

Quote arvidn:

In my mind, the main friction for building wheels is the current (very complex) setup.py which uses the (very complicated) distutils to build the wheel. b2 builds the shared library that is the native python module just fine. I would think that creating the accompanying files and directories to turn that into a wheel is simple, but I haven't found any documentation for that. distutils makes it complicated because it also seems to want to actually trigger the build command now.

For Python build backends with extension modules there are two that stand out for libtorrent's use-case, setuptools.build_meta or scikit-build-core.

distutils -> setuptools.build_meta

Theoretically a straightforward swap from extending distutils in seutp.py for setuptools Extension and build_ext as outlined in setuptools Extension module documentation

Example: cmake_example/setup.py

scikit-build-core

The scikit-build-core build backend (a rewrite of scikit-build) makes uses of CMake so could reduce some of the complexity with building the bindings but require more work to get it setup and handle the nuances currently in setup.py. This backend is pretty well documented and maintained with lots of examples and projects using it.

Example: hello-cmake-package (older scikit-build but still relevant)

Would you consider consolidating build tooling around CMake? I found a recent article with good reasons for switching from b2 to CMake for boost users. Could even resolve boost dependency automatically with cpm-cmake since it's not always trivial to make the build aware of boost.

Replace boost-python

A slight tangent to topic at-hand but could we simplify the building of the bindings by replacing boost-python for a binding library such as nanobind, it could be an epic undertaking but worth it?!? e.g. ABI3 wheels :stuck_out_tongue:

cas-- avatar Jul 20 '25 18:07 cas--