[build2] Python Wrapper with Pybind11, Calling Python, and Renaming Libraries

Markus Pawellek markus.pawellek at mailbox.org
Mon Mar 22 15:53:38 UTC 2021


Hello,

a few weeks ago, I have created a Python wrapper in Pybind11
for a C++ test library built by the build2 build system.
The code and a small explanation can be found here:
https://github.com/lyrahgames/build2-pybind11-pip-test

Two problems had to be solved.
To be able to compile a shared library which can be used by Python,
one needs to access environment variables
of the currently used Python environment.
This can easily be done by calling the used Python executable
on the command line with certain parameters
and saving its output in appropriate configuration variables.
In build2 alone, this seemed not to be possible for me
and therefore I have introduced another layer of indirection by using a Makefile.
The Makefile then calls the Python executable
and bdep to set the configuration variables.
Afterwards the project can be built by build2 and installed by Pip.
Is there a way to call the Python executable from inside build2
and use its output directly to set some configuration variables?

Furthermore, shared libraries that can be called by Python
use a different naming scheme and extension than typical shared libraries.
There was no possibility of changing
the suffix or naming scheme of a library target.
Therefore I have defined a new file type with the appropriate requirements
and copied libraries to the new type by using inline build recipes with cp.
Is there a better way of renaming libraries?

Greetings
Markus



More information about the users mailing list