Skip to content

Commit 5b9e4f2

Browse files
committed
unix: overwrite _PYTHON_HOST_PLATFORM in macOS cross builds
See the inline comment in the patch. The environment variable as defined by configure out of the box is not sufficient for macOS because Python normalizes the value at run-time. This was resulting in incorrect platform values being used during cross builds.
1 parent a119466 commit 5b9e4f2

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

cpython-unix/build-cpython.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pushd Python-${PYTHON_VERSION}
8686
# configure doesn't support cross-compiling on Apple. Teach it.
8787
patch -p1 << "EOF"
8888
diff --git a/configure b/configure
89-
index 2d379feb4b..3eb8dbe9ea 100755
89+
index 1252335472..6665645839 100755
9090
--- a/configure
9191
+++ b/configure
9292
@@ -3301,6 +3301,15 @@ then
@@ -125,7 +125,31 @@ index 2d379feb4b..3eb8dbe9ea 100755
125125
*-*-vxworks*)
126126
_host_cpu=$host_cpu
127127
;;
128-
@@ -5968,7 +5996,7 @@ $as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h
128+
@@ -3359,7 +3381,22 @@ if test "$cross_compiling" = yes; then
129+
MACHDEP="unknown"
130+
as_fn_error $? "cross build not supported for $host" "$LINENO" 5
131+
esac
132+
- _PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
133+
+
134+
+ case "$host" in
135+
+ # The _PYTHON_HOST_PLATFORM environment variable is used to
136+
+ # override the platform name in distutils and sysconfig when
137+
+ # cross-compiling. On Apple, the platform name expansion logic
138+
+ # is non-trivial, including renaming MACHDEP=darwin to macosx
139+
+ # and including the deployment target (or current OS version if
140+
+ # not set). Our hack here is not generic, but gets the job done
141+
+ # for python-build-standalone's cross-compile use cases.
142+
+ aarch64-apple-darwin*)
143+
+ _PYTHON_HOST_PLATFORM="macosx-${MACOSX_DEPLOYMENT_TARGET}-arm64"
144+
+ ;;
145+
+ *)
146+
+ _PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
147+
+ esac
148+
+
149+
fi
150+
151+
# Some systems cannot stand _XOPEN_SOURCE being defined at all; they
152+
@@ -5968,7 +6005,7 @@ $as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h
129153
BLDLIBRARY='-Wl,+b,$(LIBDIR) -L. -lpython$(LDVERSION)'
130154
RUNSHARED=SHLIB_PATH=`pwd`${SHLIB_PATH:+:${SHLIB_PATH}}
131155
;;
@@ -134,7 +158,7 @@ index 2d379feb4b..3eb8dbe9ea 100755
134158
LDLIBRARY='libpython$(LDVERSION).dylib'
135159
BLDLIBRARY='-L. -lpython$(LDVERSION)'
136160
RUNSHARED=DYLD_LIBRARY_PATH=`pwd`${DYLD_LIBRARY_PATH:+:${DYLD_LIBRARY_PATH}}
137-
@@ -6205,16 +6233,6 @@ esac
161+
@@ -6205,16 +6242,6 @@ esac
138162
fi
139163
fi
140164
@@ -151,7 +175,7 @@ index 2d379feb4b..3eb8dbe9ea 100755
151175
case $MACHDEP in
152176
hp*|HP*)
153177
# install -d does not work on HP-UX
154-
@@ -9541,6 +9559,11 @@ then
178+
@@ -9541,6 +9568,11 @@ then
155179
BLDSHARED="$LDSHARED"
156180
fi
157181
;;

0 commit comments

Comments
 (0)