Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de0e3f8

Browse files
[3.9] bpo-44009: Provide "python3.x-intel64" for Apple Silicon Macs (GH-25804) (GH-25807)
This allows reliably forcing macOS universal2 framework builds to run under Rosetta 2 Intel-64 emulation on Apple Silicon Macs if needed for testing or when universal2 wheels are not yet available. (cherry picked from commit 0cb33da) Co-authored-by: Ned Deily <[email protected]> Automerge-Triggered-By: GH:ned-deily
1 parent ee0df3d commit de0e3f8

6 files changed

Lines changed: 62 additions & 9 deletions

File tree

Mac/Makefile.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FRAMEWORKUNIXTOOLSPREFIX=@FRAMEWORKUNIXTOOLSPREFIX@
2020
PYTHONFRAMEWORK=@PYTHONFRAMEWORK@
2121
PYTHONFRAMEWORKIDENTIFIER=@PYTHONFRAMEWORKIDENTIFIER@
2222
LIPO_32BIT_FLAGS=@LIPO_32BIT_FLAGS@
23+
LIPO_INTEL64_FLAGS=@LIPO_INTEL64_FLAGS@
2324
CC=@CC@
2425
MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@
2526
export MACOSX_DEPLOYMENT_TARGET
@@ -92,6 +93,16 @@ installunixtools:
9293
$(LN) -s $(BINDIR)/$${fn} $${fn} ;\
9394
done ;\
9495
fi
96+
-if test "x$(LIPO_INTEL64_FLAGS)" != "x"; then \
97+
cd "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" && \
98+
for fn in \
99+
python3-intel64 \
100+
; \
101+
do \
102+
rm -f $${fn} ;\
103+
$(LN) -s $(BINDIR)/$${fn} $${fn} ;\
104+
done ;\
105+
fi
95106
-if test "x$(ENSUREPIP)" != "xno" ; then \
96107
cd "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" && \
97108
for fn in \
@@ -142,6 +153,16 @@ altinstallunixtools:
142153
$(LN) -s $(BINDIR)/$${fn} $${fn} ;\
143154
done ;\
144155
fi
156+
-if test "x$(LIPO_INTEL64_FLAGS)" != "x"; then \
157+
cd "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" && \
158+
for fn in \
159+
python$(VERSION)-intel64 \
160+
; \
161+
do \
162+
rm -f $${fn} ;\
163+
$(LN) -s $(BINDIR)/$${fn} $${fn} ;\
164+
done ;\
165+
fi
145166
-if test "x$(ENSUREPIP)" != "xno" ; then \
146167
cd "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" && \
147168
for fn in \

Mac/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ following combinations of SDKs and universal-archs flavors are available:
162162
The makefile for a framework build will also install ``python3.x-32``
163163
binaries when the universal architecture includes at least one 32-bit
164164
architecture (that is, for all flavors but ``64-bit`` and ``intel-64``).
165+
It will also install ``python3.x-intel64`` binaries in the ``universal2``
166+
case to allow easy execution with the Rosetta 2 Intel emulator on Apple
167+
Silicon Macs.
165168

166169
Running a specific architecture
167170
...............................
@@ -181,6 +184,9 @@ subprocesses also run in 32-bit-mode if the main interpreter does, use
181184
a ``python3.x-32`` binary and use the value of ``sys.executable`` as the
182185
``subprocess`` ``Popen`` executable value.
183186

187+
Likewise, use ``python3.x-intel64`` to force execution in ``x86_64`` mode
188+
with ``universal2`` binaries.
189+
184190
Building and using a framework-based Python on macOS
185191
====================================================
186192

Makefile.pre.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ STRIPFLAG=-s
187187
# Flags to lipo to produce a 32-bit-only universal executable
188188
LIPO_32BIT_FLAGS=@LIPO_32BIT_FLAGS@
189189

190+
# Flags to lipo to produce an intel-64-only universal executable
191+
LIPO_INTEL64_FLAGS=@LIPO_INTEL64_FLAGS@
192+
190193
# Options to enable prebinding (for fast startup prior to Mac OS X 10.3)
191194
OTHER_LIBTOOL_OPT=@OTHER_LIBTOOL_OPT@
192195

@@ -1334,6 +1337,12 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
13341337
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-32$(EXE) \
13351338
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
13361339
fi
1340+
if test "x$(LIPO_INTEL64_FLAGS)" != "x" ; then \
1341+
rm -f $(DESTDIR)$(BINDIR)python$(VERSION)-intel64$(EXE); \
1342+
lipo $(LIPO_INTEL64_FLAGS) \
1343+
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-intel64$(EXE) \
1344+
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
1345+
fi
13371346

13381347
bininstall: altbininstall
13391348
if test ! -d $(DESTDIR)$(LIBPC); then \
@@ -1369,6 +1378,10 @@ bininstall: altbininstall
13691378
rm -f $(DESTDIR)$(BINDIR)/python3-32$(EXE); \
13701379
(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-32$(EXE) python3-32$(EXE)) \
13711380
fi
1381+
if test "x$(LIPO_INTEL64_FLAGS)" != "x" ; then \
1382+
rm -f $(DESTDIR)$(BINDIR)/python3-intel64$(EXE); \
1383+
(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-intel64$(EXE) python3-intel64$(EXE)) \
1384+
fi
13721385

13731386
# Install the versioned manual page
13741387
altmaninstall:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Provide "python3.x-intel64" executable to allow reliably forcing macOS
2+
universal2 framework builds to run under Rosetta 2 Intel-64 emulation on
3+
Apple Silicon Macs. This can be useful for testing or when universal2
4+
wheels are not yet available.

configure

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ PYTHONFRAMEWORKPREFIX
747747
PYTHONFRAMEWORKDIR
748748
PYTHONFRAMEWORKIDENTIFIER
749749
PYTHONFRAMEWORK
750+
LIPO_INTEL64_FLAGS
750751
LIPO_32BIT_FLAGS
751752
ARCH_RUN_32BIT
752753
UNIVERSALSDK
@@ -1507,11 +1508,12 @@ Optional Packages:
15071508
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
15081509
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
15091510
--with-universal-archs=ARCH
1510-
specify the kind of universal binary that should be
1511-
created. this option is only valid when
1511+
specify the kind of macOS universal binary that
1512+
should be created. This option is only valid when
15121513
--enable-universalsdk is set; options are:
1513-
("universal2", "32-bit", "64-bit", "3-way", "intel",
1514-
"intel-32", "intel-64", or "all") see Mac/README.rst
1514+
("universal2", "intel-64", "intel-32", "intel",
1515+
"32-bit", "64-bit", "3-way", or "all") see
1516+
Mac/README.rst
15151517
--with-framework-name=FRAMEWORK
15161518
specify the name for the python framework on macOS
15171519
only valid when --enable-framework is set. see
@@ -3111,6 +3113,7 @@ then
31113113
fi
31123114

31133115

3116+
31143117
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-universal-archs" >&5
31153118
$as_echo_n "checking for --with-universal-archs... " >&6; }
31163119

@@ -7463,6 +7466,7 @@ $as_echo_n "checking which compiler should be used... " >&6; }
74637466
$as_echo "$CC" >&6; }
74647467
fi
74657468

7469+
LIPO_INTEL64_FLAGS=""
74667470
if test "${enable_universalsdk}"
74677471
then
74687472
case "$UNIVERSAL_ARCHS" in
@@ -7484,8 +7488,9 @@ $as_echo "$CC" >&6; }
74847488
universal2)
74857489
UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
74867490
LIPO_32BIT_FLAGS=""
7491+
LIPO_INTEL64_FLAGS="-extract x86_64"
74877492
ARCH_RUN_32BIT="true"
7488-
;;
7493+
;;
74897494
intel)
74907495
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
74917496
LIPO_32BIT_FLAGS="-extract i386"

configure.ac

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,14 @@ then
220220
fi
221221

222222
AC_SUBST(LIPO_32BIT_FLAGS)
223+
AC_SUBST(LIPO_INTEL64_FLAGS)
223224
AC_MSG_CHECKING(for --with-universal-archs)
224225
AC_ARG_WITH(universal-archs,
225226
AS_HELP_STRING([--with-universal-archs=ARCH],
226-
[specify the kind of universal binary that should be created. this option is
227-
only valid when --enable-universalsdk is set; options are:
228-
("universal2", "32-bit", "64-bit", "3-way", "intel", "intel-32", "intel-64", or "all")
227+
[specify the kind of macOS universal binary that should be created.
228+
This option is only valid when --enable-universalsdk is set; options are:
229+
("universal2", "intel-64", "intel-32", "intel", "32-bit",
230+
"64-bit", "3-way", or "all")
229231
see Mac/README.rst]),
230232
[
231233
UNIVERSAL_ARCHS="$withval"
@@ -1877,6 +1879,7 @@ yes)
18771879
AC_MSG_RESULT($CC)
18781880
fi
18791881

1882+
LIPO_INTEL64_FLAGS=""
18801883
if test "${enable_universalsdk}"
18811884
then
18821885
case "$UNIVERSAL_ARCHS" in
@@ -1898,8 +1901,9 @@ yes)
18981901
universal2)
18991902
UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
19001903
LIPO_32BIT_FLAGS=""
1904+
LIPO_INTEL64_FLAGS="-extract x86_64"
19011905
ARCH_RUN_32BIT="true"
1902-
;;
1906+
;;
19031907
intel)
19041908
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
19051909
LIPO_32BIT_FLAGS="-extract i386"

0 commit comments

Comments
 (0)