python / python/cpython

macOS: configure does not support linking against a non-system libffi

Open
#155,813 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

build OS-mac type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

On macOS, the configure script does not provide a way to link _ctypes against a non-system libffi.

Although LIBFFI_CFLAGS and LIBFFI_LIBS are documented as configuration variables for libffi, configure first checks for the system libffi from Apple's SDK and if found overwrites these variables.
The pkg-config based check, which does preserve these variables, is never run when the system libffi is detected.

The confusing --with-system-ffi option, removed in Python 3.12 (#100544), provided a way to invoke the pkg-config based configuration on macOS, bypassing the detection of the SDK libffi.

I ran into this while updating python-build-standalone to use the standard extension configuration in 3.12+ (astral-sh/python-build-standalone#1180). Other than patching configure the best option seemed to be to use ac_cv_lib_ffi_ffi_call=no to force the check to fail.

I also found that conda-forge patches configure to get around this issue when building CPython.

Related issues
CPython versions tested on:

3.12, 3.13, 3.14, 3.15, CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-156486

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked configure.ac checks around lines 4363-4392 and compare them with the generated configure script. Trace how LIBFFI_CFLAGS, LIBFFI_LIBS, the macOS SDK libffi check, and the pkg-config check interact. Done means a macOS build can preserve user-supplied settings and link _ctypes against a non-system libffi.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.