Skip to content

Commit

Permalink
gh-xxxx: expose _PYTHON_HOST_PLATFORM as a settable variable
Browse files Browse the repository at this point in the history
The generated sysconfig data during builds encodes a PEP-425
platform tag. During native (target=host) builds, the bootstrapped
compiler runs Python code in sysconfig to derive an appropriate value.

For cross compiles, we fall back to logic in configure (that code
lives around the changed lines) to derive an appropriate platform
tag, which is exported as an environment variable during builds.
And there is a "backdoor" in `sysconfig.py` that causes
`sysconfig.get_platform()` to return that value.

The logic in configure for deriving an appropriate platform tag
is a far cry from what's in `sysconfig.py`. Ideally that logic
would be fully (re)implemented in configure. But that's a
non-trivial amount of work.

Recognizing that configure makes inadequate platform tag decisions
during cross-compiles, this commit switches `_PYTHON_HOST_PLATFORM`
from a regular output variable to a "precious variable" (in autoconf
speak). This has the side-effect of allowing invokers to define the
variable, effectively allowing them to explicitly set the platform
tag during builds.
  • Loading branch information
indygreg committed Jan 17, 2023
1 parent 8622fd8 commit cc3f6f5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 53 deletions.
69 changes: 43 additions & 26 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 39 additions & 27 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -585,35 +585,47 @@ then
fi
AC_MSG_RESULT("$MACHDEP")

AC_SUBST(_PYTHON_HOST_PLATFORM)
if test "$cross_compiling" = yes; then
case "$host" in
*-*-linux*)
case "$host_cpu" in
arm*)
_host_cpu=arm
;;
*)
_host_cpu=$host_cpu
esac
;;
*-*-cygwin*)
_host_cpu=
;;
*-*-vxworks*)
_host_cpu=$host_cpu
;;
wasm32-*-* | wasm64-*-*)
_host_cpu=$host_cpu
;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
AC_MSG_ERROR([cross build not supported for $host])
esac
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
AC_ARG_VAR(_PYTHON_HOST_PLATFORM, [
Forces a platform tag value for use in sysconfig data. This will be calculated
automatically in non-cross builds by running sysconfig code in the
bootstrapped interpreter. In cross builds, an attempt will be made to
derive an appropriate value in configure. But some targets may derive
incorrect values. This variable can be set to force a value. Example
values: linux-x86_64, macosx-10.9-universal2, win-amd64])
AC_MSG_CHECKING(_PYTHON_HOST_PLATFORM)

if test -z "${_PYTHON_HOST_PLATFORM}"; then
if test "$cross_compiling" = yes; then
case "$host" in
*-*-linux*)
case "$host_cpu" in
arm*)
_host_cpu=arm
;;
*)
_host_cpu=$host_cpu
esac
;;
*-*-cygwin*)
_host_cpu=
;;
*-*-vxworks*)
_host_cpu=$host_cpu
;;
wasm32-*-* | wasm64-*-*)
_host_cpu=$host_cpu
;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
AC_MSG_ERROR([cross build not supported for $host])
esac
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
fi
fi

AC_MSG_RESULT([$_PYTHON_HOST_PLATFORM])

# Some systems cannot stand _XOPEN_SOURCE being defined at all; they
# disable features if it is defined, without any means to access these
# features as extensions. For these systems, we skip the definition of
Expand Down

0 comments on commit cc3f6f5

Please sign in to comment.