nightlark / swig-pypi

pip install swig. SWIG Python wheel for PyPI.
Apache License 2.0
16 stars 5 forks source link

x86_64 binary in swig-4.1.1-py2.py3-none-macosx_11_0_arm64.whl #95

Closed julian-smith-artifex-com closed 1 year ago

julian-smith-artifex-com commented 1 year ago

Installing swig using pip on an ARM mac-mini seems to install an x86_64 binary, which fails at runtime.

My system is:

% uname -a
Darwin mac-mini 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 arm64
% 

Here's a reproducer:

% python3 -m venv pylocal
% . pylocal/bin/activate
(pylocal) % python -m pip install --upgrade pip
Requirement already satisfied: pip in ./pylocal/lib/python3.9/site-packages (21.2.4)
Collecting pip
  Using cached pip-23.2.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-23.2.1
(pylocal) % pip install swig
Collecting swig
  Using cached swig-4.1.1-py2.py3-none-macosx_11_0_arm64.whl (1.7 MB)
Installing collected packages: swig
Successfully installed swig-4.1.1
(pylocal) % swig --version
Traceback (most recent call last):
  File "/Users/jules/artifex-remote/pylocal/bin/swig", line 8, in <module>
    sys.exit(swig())
  File "/Users/jules/artifex-remote/pylocal/lib/python3.9/site-packages/swig/__init__.py", line 24, in swig
    raise SystemExit(_program("swig", sys.argv[1:]))
  File "/Users/jules/artifex-remote/pylocal/lib/python3.9/site-packages/swig/__init__.py", line 20, in _program
    return subprocess.call([os.path.join(BIN_DIR, name)] + args, env=SWIG_LIB_ENV)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/subprocess.py", line 349, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 86] Bad CPU type in executable: '/Users/jules/artifex-remote/pylocal/lib/python3.9/site-packages/swig/data/bin/swig'
(pylocal) % 
(pylocal) % file /Users/jules/artifex-remote/pylocal/lib/python3.9/site-packages/swig/data/bin/swig
/Users/jules/artifex-remote/pylocal/lib/python3.9/site-packages/swig/data/bin/swig: Mach-O 64-bit executable x86_64
(pylocal) % 

The same thing happens with pip install -vv --force-reinstall --no-cache-dir swig.

This can also be seen by looking at swig/data/bin/swig in: https://files.pythonhosted.org/packages/56/2e/094303ec29243111a81b26bb91d0d2692db05159451416490acc8b33fca1/swig-4.1.1-py2.py3-none-macosx_11_0_arm64.whl

Thanks in advance for any help.

julian-smith-artifex-com commented 1 year ago

Looks like things can be made to work by installing Rosetta with:

softwareupdate --install-rosetta --agree-to-license
nightlark commented 1 year ago

Thanks for the report and the Rosetta workaround. It's interesting that the compiled swig binary doesn't have an arm64 segment -- I'm kind of wondering if it's an issue with the cibuildwheel or the macOS GitHub Actions runner environment. There is a public beta of GitHub hosted Apple Silicon runners on the GitHub roadmap listed for this Oct-Dec (https://github.com/github/roadmap/issues/528), which could address the issues building native arm64 wheels for macOS.

nightlark commented 1 year ago

The underlying issue (CMAKE_OSX_ARCHITECTURES not getting propagated to the swig and pcre builds) has been fixed in #99. I'll make an updated 4.1.1 release with the updated swig binaries for macOS.

nightlark commented 1 year ago

4.1.1.post0 has been uploaded to PyPI -- no change to the version of swig, but now the universal2 and arm64 wheels for macOS actually have arm64 architectures in them instead of just x86_64. Hopefully that means installing Rosetta is no longer needed.