astral-sh / astral-sh/python-build-standalone
Consider using system libffi on macOS
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 314
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 27
Description
On macOS the system/SDK/Apple provides libffi.
Some CPython distributions use these system provided libraries. Homebrew and the Python.org installer link against both:
Homebrew:
```
❯ cd /opt/homebrew/Frameworks/Python.framework/Versions/3.14/lib/python3.14/lib-dynload
❯ otool -L _ctypes.cpython-314-darwin.so
_ctypes.cpython-314-darwin.so:
/usr/lib/libffi.dylib (compatibility version 1.0.0, current version 40.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
```
Python.org
```
❯ cd /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/lib-dynload
❯ otool -L _ctypes.cpython-314-darwin.so
_ctypes.cpython-314-darwin.so (architecture x86_64):
/usr/lib/libffi.dylib (compatibility version 1.0.0, current version 40.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
_ctypes.cpython-314-darwin.so (architecture arm64):
/usr/lib/libffi.dylib (compatibility version 1.0.0, current version 40.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
```
Currently python-build-standalone builds and bundles libffi statically in the `python` binary
```
❯ curl -SLO https://github.com/astral-sh/python-build-standalone/releases/download/20260814/cpython-3.14.7+20260814-aarch64-apple-darwin-install_only_stripped.tar.gz
❯ tar xf cpython-3.14.7+20260814-aarch64-apple-darwin-install_only_stripped.tar.gz
❯ otool -L python/bin/python
python/bin/python:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 3038.1.255)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/usr/lib/libpanel.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 1345.0.0)
/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.12)
```
Using the system libffi would be in-line with the usage of other system provided libaries on macOS (libz, libncurses, libedit) as well as follow the pattern other distributions use.
Contributor guide
Research direction
Start by reproducing the macOS linkage checks shown in the issue with otool -L for the built Python binary and _ctypes extension. Review the macOS build configuration and current libffi handling, then verify that the resulting build links against /usr/lib/libffi.dylib without regressing the other system-library checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100