pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.49k stars 1.19k forks source link

[FR] Compile Shared Library #4435

Open gentlegiantJGC opened 3 months ago

gentlegiantJGC commented 3 months ago

What's the problem this feature will solve?

As discussed in #2806 and in this stack overflow post there is demand for compiling dynamic libraries as part of the setuptools build process and then linking against them in python extensions or using them with ctypes or other tools.

I believe currently people either pre-compile the shared library before or have a hacky extension to setuptools.

Describe the solution you'd like

I would like to propose that setuptools adds native support for compiling shared libraries as part of the build process.

I don't know exactly how this would be implemented but my though process was that another command would be added eg build_shared_clib to complement the existing build_clib and another argument would be added to setup() eg shared_libraries to compliment libraries

Alternative Solutions

Compile the shared library separately. Manual plugin like in the stack overflow post. https://github.com/mdavidsaver/setuptools_dso

Additional context

I would be interested in helping getting such a feature implemented. Is this something that setuptools would be interested in merging?

Code of Conduct

gentlegiantJGC commented 3 months ago

Reading around some more, there seem to be issues with import paths. Python extension modules will look for shared libraries next to them and in some other locations as discussed here That would raise some issues if the dependent python extensions were not all next to the shared library. dll directories can be manually extended but I assume setuptools wouldn't want to do that.

I also have the use case where I have one python package that depends on the C API of another package which I was planning on exposing through a shared library. This has the import path issue and also on Windows has the issue that the import library (.lib) is needed to compile against the shared library. To support that the lib file would need to be distributed with the package. If this was supported it would need to be an optional feature.

Extra reading: https://discuss.python.org/t/installation-of-shared-objects-into-separate-folder/8489 https://discuss.python.org/t/wheel-depending-on-shared-library-from-another-wheel/26456