Skip to content

Commit 2e2ba00

Browse files
committed
gh-xxxx: expose _PYTHON_HOST_PLATFORM as a settable variable
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 to a correct value when configure otherwise wouldn't set one.
1 parent 8622fd8 commit 2e2ba00

File tree

2 files changed

+82
-53
lines changed

2 files changed

+82
-53
lines changed

configure

Lines changed: 43 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -585,35 +585,47 @@ then
585585
fi
586586
AC_MSG_RESULT("$MACHDEP")
587587

588-
AC_SUBST(_PYTHON_HOST_PLATFORM)
589-
if test "$cross_compiling" = yes; then
590-
case "$host" in
591-
*-*-linux*)
592-
case "$host_cpu" in
593-
arm*)
594-
_host_cpu=arm
595-
;;
596-
*)
597-
_host_cpu=$host_cpu
598-
esac
599-
;;
600-
*-*-cygwin*)
601-
_host_cpu=
602-
;;
603-
*-*-vxworks*)
604-
_host_cpu=$host_cpu
605-
;;
606-
wasm32-*-* | wasm64-*-*)
607-
_host_cpu=$host_cpu
608-
;;
609-
*)
610-
# for now, limit cross builds to known configurations
611-
MACHDEP="unknown"
612-
AC_MSG_ERROR([cross build not supported for $host])
613-
esac
614-
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
588+
AC_ARG_VAR(_PYTHON_HOST_PLATFORM, [
589+
Forces a platform tag value for use in sysconfig data. This will be calculated
590+
automatically in non-cross builds by running sysconfig code in the
591+
bootstrapped interpreter. In cross builds, an attempt will be made to
592+
derive an appropriate value in configure. But some targets may derive
593+
incorrect values. This variable can be set to force a value. Example
594+
values: linux-x86_64, macosx-10.9-universal2, win-amd64])
595+
AC_MSG_CHECKING(_PYTHON_HOST_PLATFORM)
596+
597+
if test -z "${_PYTHON_HOST_PLATFORM}"; then
598+
if test "$cross_compiling" = yes; then
599+
case "$host" in
600+
*-*-linux*)
601+
case "$host_cpu" in
602+
arm*)
603+
_host_cpu=arm
604+
;;
605+
*)
606+
_host_cpu=$host_cpu
607+
esac
608+
;;
609+
*-*-cygwin*)
610+
_host_cpu=
611+
;;
612+
*-*-vxworks*)
613+
_host_cpu=$host_cpu
614+
;;
615+
wasm32-*-* | wasm64-*-*)
616+
_host_cpu=$host_cpu
617+
;;
618+
*)
619+
# for now, limit cross builds to known configurations
620+
MACHDEP="unknown"
621+
AC_MSG_ERROR([cross build not supported for $host])
622+
esac
623+
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
624+
fi
615625
fi
616626

627+
AC_MSG_RESULT([$_PYTHON_HOST_PLATFORM])
628+
617629
# Some systems cannot stand _XOPEN_SOURCE being defined at all; they
618630
# disable features if it is defined, without any means to access these
619631
# features as extensions. For these systems, we skip the definition of

0 commit comments

Comments
 (0)