impy-project / chromo

Hadronic Interaction Model interface in PYthon
Other
30 stars 7 forks source link

avoid linking to Python #126

Closed HDembinski closed 1 year ago

HDembinski commented 1 year ago

This seems to avoid the linking to Python, which is causing issues in #82

HDembinski commented 1 year ago

I removed the mold code here after realizing a) the mold linker flags were actually never set, because the if conditions never triggered, b) the linker flag -ld-path=<path to mold> does not work when you link with gfortran.

HDembinski commented 1 year ago

This should be merged into main and then into #82 to remove the need for fix_macos_installation and a couple of other workarounds.

afedynitch commented 1 year ago

This looks really elegant, thanks. I'm wondering how did you find this solution?

HDembinski commented 1 year ago

This looks really elegant, thanks. I'm wondering how did you find this solution?

You can follow my thoughts in the comments to #82 , but my general advice is: if you encounter a problem, study the code of scipy or numpy or pybind11, which deal with similar issues as we do and check what they are doing. These three software packages have expertly written build systems, commits are reviewed by experts with a lot of knowledge, so the solutions which end up in those packages tend to be very good. Code documentation is also often very good.

In this particular case, I checked what the macro pybind11_add_module is calling to build the Python module.

afedynitch commented 1 year ago

These three software packages have expertly written build systems, commits are reviewed by experts with a lot of knowledge, so the solutions which end up in those packages tend to be very good. Code documentation is also often very good.

I checked scipy and numpy but they all use meson for a while 😛

eli-schwartz commented 1 year ago

I checked scipy and numpy but they all use meson for a while stuck_out_tongue

The meson handling calls out to the meson "python" support module's py.dependency() method, which defaults to embed: false. This roughly corresponds to e.g. the python pkg-config file's split between python.pc and python-embed.pc (the latter is used for producing executables that load a python interpreter, the former for extension modules).

There's platform-specific handling here, it's not so simple as "don't link to libpython", but that's mostly a difference between Windows (do link) and everywhere else (don't link, starting with python 3.8).

HDembinski commented 1 year ago

We use the cmake command Python_add_library now, which is supposed to handle this in a platform independent way. Since you say it is complicated, I assume they (cmake) added this to abstract all these details away for us.