Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a regression in include paths when compiling ctypes in 3.6.15/3.7.12 #2209

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

chipx86
Copy link
Contributor

@chipx86 chipx86 commented Jan 7, 2022

Description

In my previous work on getting Python 3.6.15 and 3.7.12 to compile on Apple M1, I backported logic from newer 3.8.x releases to properly find libffi and related files on macOS.

This regressed compilation on Linux. The include search path was incomplete, and ffi.h could not be found, resulting in ctypes being disabled.

There was a key difference between the old logic and new logic that led to this regression:

  1. In 3.8 and newer, detect_ctypes() in setup.py took no arguments, and was expected to access instance variables for the include search path.
  2. In 3.7 and earlier, detect_ctypes() took the path as an argument, and was expected to make use of it.

The backport made use of the instance variables, overriding the provided include path. These were not equivalent. The one on the instance was not complete, lacking the necessary directories to find ffi.h. Since this could not be found, ctypes support was disabled.

The fix is to simply not overwrite the variables passed to the function, and resume using them as before.

Fixes #2207

Tests

Compiled 3.6.15 and 3.7.12 on macOS (M1).

Compiled 3.6.15 and 3.7.12 on Linux in a Docker image provided on #2207 that reproduced the failure case.

In all tested environments, ctypes compiled and could be imported successfully.

….12.

In my previous work on getting Python 3.6.15 and 3.7.12 to compile on
Apple M1, I backported logic from newer 3.8.x releases to properly find
libffi and related files on macOS.

This regressed compilation on Linux. The include search path was
incomplete, and `ffi.h` could not be found, resulting in `ctypes` being
disabled.

There was a key difference between the old logic and new logic that led
to this regression:

1. In 3.8 and newer, `detect_ctypes()` in `setup.py` took no arguments,
   and was expected to access instance variables for the include search
   path.
2. In 3.7 and earlier, `detect_ctypes()` took the path as an argument,
   and was expected to make use of it.

The backport made use of the instance variables, overriding the provided
include path. These were not equivalent. The one on the instance was not
complete, lacking the necessary directories to find `ffi.h`. Since this
could not be found, `ctypes` support was disabled.

The fix is to simply not overwrite the variables passed to the function,
and resume using them as before.

Fixes pyenv#2207
@native-api native-api merged commit 867909c into pyenv:master Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Latest version of pyenv on Linux fails to build _ctypes for python 3.7.12
2 participants