I have a library written in C++ for which I would like to make a Python wrapper. The directory structure of my repository is similar to the following:
.
├── include # C++ library headers
│ └── …
├── Makefile
├── python # Python package
│ ├── wrapper-module # C++ and Python source files
│ │ └── …
│ ├── pyproject.toml
│ ├── setup.py
│ └── …
├── src # C++ library source files
│ └── …
└── tests # C++ library tests
└── …
I use GNU make for building the C++ library and use Python’s C API directly to implement the wrapper. (I.e. no Boost.Python, Cython etc.)
Building the Python package has been unsuccessful so far. Since I use the C API, I chose setuptools 80.9.0 for building the module. When running python -m build, the relevant files are copied to a separate location, even if I use --no-isolation. So far I have been unable to make the C++ library available in that location or determine their relative path with respect to that location. (I would like to avoid specifying its absolute path or installing it to e.g. /usr.) The source files for the wrapper module (or at least most of them) are copied as expected.
So far I have attempted to solve the issue as follows:
- Checking the documentation. What I have found so far has had to do with Python dependencies, not “local” ones.
- Copying the C++ library build products to the Python directory with a build phase in the Makefile. In this case the build products are not copied to the separate build location. I have not found a configuration option to specify the directory in question as a build dependency.
- Adding a custom build phase in
setup.py. In this case I have not found a function or property to retrieve the original path in order to copy the required files as part of the build process. - Writing a custom build backend based on
setuptools.build_meta. In this case I can determine the original path usingos.getcwd(). However, the module that contains the custom backend is not copied to the separate build location even though I have setbuild-backendandbackend-pathinpyproject.toml. (In any case I probably would need to store the original path somehow, to which I have not paid much attention.)
Any suggestions for making setuptools aware of the location of the built C++ library and the associated header files are appreciated.