Closed DiamondHunters closed 1 year ago
I found binary files with incorrect architecture name in the .whl package
rock@rock-5b:~$ tree /usr/local/lib/python3.8/dist-packages/lief
/usr/local/lib/python3.8/dist-packages/lief
├── Android.pyi
├── ART.pyi
├── DEX.pyi
├── ELF.pyi
├── __init__.py
├── __init__.pyi
├── **_lief.cpython-38-x86_64-linux-gnu.so**
├── logging.pyi
├── MachO.pyi
├── OAT.pyi
├── PE.pyi
├── __pycache__
│ └── __init__.cpython-38.pyc
├── py.typed
└── VDEX.pyi
1 directory, 14 files
I unzipped the whl package and confirmed the issue lief-0.13.0-cp310-cp310-manylinux2014_aarch64.whl
rename _lief.cpython-38-x86_64-linux-gnu.so
to _lief.cpython-38-aarch64-linux-gnu.so
then python load this lib
At there: https://github.com/lief-project/LIEF/blob/f796720f633415d7f2051e082a47e1789e1fce9c/api/python/setup.py#L324 Used 'get_ext_filename' to obtain the compilation suffix name.
def get_ext_filename(self, fullname):
so_ext = os.getenv('SETUPTOOLS_EXT_SUFFIX')
if so_ext:
filename = os.path.join(*fullname.split('.')) + so_ext
else:
filename = _build_ext.get_ext_filename(self, fullname)
so_ext = get_config_var('EXT_SUFFIX')
if fullname in self.ext_map:
ext = self.ext_map[fullname]
use_abi3 = getattr(ext, 'py_limited_api') and get_abi3_suffix()
if use_abi3:
filename = filename[:-len(so_ext)]
so_ext = get_abi3_suffix()
filename = filename + so_ext
if isinstance(ext, Library):
fn, ext = os.path.splitext(filename)
return self.shlib_compiler.library_filename(fn, libtype)
elif use_stubs and ext._links_to_dynamic:
d, fn = os.path.split(filename)
return os.path.join(d, 'dl-' + fn)
return filename
It's only related to building machines. And for the correct suffix name, it can be configured using the 'SETUPTOOLS_EXT_SUFFIX' environment variable But we need to specify the py version, so I am looking for an elegant solution.
The root cause is _PYTHON_HOST_PLATFORM
in sh file not effective
Actually,after I read the source code of distutils,I found that the results of get_ext_filename
are only related to EXT_SUFFIX
.
_PYTHON_HOST_PLATFORM
only affects APIs such as get_host_platform
,get_platform
refer to https://github.com/pypa/setuptools/issues/2722
The solution is to set SETUPTOOLS_EXT_SUFFIX
environment variable
Thank you @DiamondHunters for your investigation and your PR. I'll do the review in the next couple of days
@romainthomas is a new release needed to 'distribute' the fix?
Yes I'll create a patch release in the next couple of weeks
Describe the bug
To Reproduce Steps to reproduce the behavior:
pip3 install lief==0.13.0
python3 -c "import lief"
Expected behavior like lief 0.12.3 works:
Environment (please complete the following information):
Additional context