Skip to content

Commit c63a03d

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 b632a18 commit c63a03d

File tree

2 files changed

+82
-53
lines changed

2 files changed

+82
-53
lines changed

configure

+43-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+39-27
Original file line numberDiff line numberDiff line change
@@ -584,35 +584,47 @@ then
584584
fi
585585
AC_MSG_RESULT("$MACHDEP")
586586

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

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

0 commit comments

Comments
 (0)