go-python / gopy

gopy generates a CPython extension module from a go package.
BSD 3-Clause "New" or "Revised" License
2.05k stars 113 forks source link

Enforce the extension module in setup.py #324

Closed vmarkovtsev closed 1 year ago

vmarkovtsev commented 1 year ago

Without this change, cibuildwheel cannot build a correct wheel from the generated project. The problem is that the native lib is added by MANIFEST.in and python3 -m pip wheel ignores it and thinks that the package is pure Python. Therefore it builds a pure wheel and the packaging pipeline crashes.

vmarkovtsev commented 1 year ago

btw I also needed the following:

patchelf --remove-needed libpython3.11.so.1.0 path/to/gopy/built/_library.cpython-*.so

this way auditwheel doesn't cry on missing libpython. Note that this dependency is indeed redundant in case the native extension is imported in an already running Python interpreter.

rcoreilly commented 1 year ago

this is something you do in cibuildwheel config? not something to add here, right? You could potentially add that somewhere in README.md if so.

vmarkovtsev commented 1 year ago

Well, it depends. Ideally, gopy wouldn't produce shared libraries linked to libpython*. Every time we import the wrapper, Python is already running by definition so the missing symbols resolve without having to link against libpython*. I can dive deeper into how gopy works and offer a patch.

On the other hand, I am only sure about Linux. macOS or Windows could theoretically have other runtime symbol resolution behavior.