Skip to content

Commit 78e5588

Browse files
bpo-44009: Provide "python3.x-intel64" for Apple Silicon Macs (GH-25810)
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 <nad@python.org> Automerge-Triggered-By: GH:ned-deily Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
1 parent b29d0a5 commit 78e5588

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

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
@@ -182,6 +182,9 @@ STRIPFLAG=-s
182182
# Flags to lipo to produce a 32-bit-only universal executable
183183
LIPO_32BIT_FLAGS=@LIPO_32BIT_FLAGS@
184184

185+
# Flags to lipo to produce an intel-64-only universal executable
186+
LIPO_INTEL64_FLAGS=@LIPO_INTEL64_FLAGS@
187+
185188
# Options to enable prebinding (for fast startup prior to Mac OS X 10.3)
186189
OTHER_LIBTOOL_OPT=@OTHER_LIBTOOL_OPT@
187190

@@ -1267,6 +1270,12 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
12671270
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-32$(EXE) \
12681271
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
12691272
fi
1273+
if test "x$(LIPO_INTEL64_FLAGS)" != "x" ; then \
1274+
rm -f $(DESTDIR)$(BINDIR)python$(VERSION)-intel64$(EXE); \
1275+
lipo $(LIPO_INTEL64_FLAGS) \
1276+
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-intel64$(EXE) \
1277+
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
1278+
fi
12701279

12711280
bininstall: altbininstall
12721281
if test ! -d $(DESTDIR)$(LIBPC); then \
@@ -1302,6 +1311,10 @@ bininstall: altbininstall
13021311
rm -f $(DESTDIR)$(BINDIR)/python3-32$(EXE); \
13031312
(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-32$(EXE) python3-32$(EXE)) \
13041313
fi
1314+
if test "x$(LIPO_INTEL64_FLAGS)" != "x" ; then \
1315+
rm -f $(DESTDIR)$(BINDIR)/python3-intel64$(EXE); \
1316+
(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-intel64$(EXE) python3-intel64$(EXE)) \
1317+
fi
13051318

13061319
# Install the versioned manual page
13071320
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ PYTHONFRAMEWORKPREFIX
742742
PYTHONFRAMEWORKDIR
743743
PYTHONFRAMEWORKIDENTIFIER
744744
PYTHONFRAMEWORK
745+
LIPO_INTEL64_FLAGS
745746
LIPO_32BIT_FLAGS
746747
ARCH_RUN_32BIT
747748
UNIVERSALSDK
@@ -1490,9 +1491,12 @@ Optional Packages:
14901491
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
14911492
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
14921493
--with-universal-archs=ARCH
1493-
select architectures for universal build ("32-bit",
1494-
"64-bit", "3-way", "intel", "intel-32", "intel-64",
1495-
"universal2", or "all")
1494+
specify the kind of macOS universal binary that
1495+
should be created. This option is only valid when
1496+
--enable-universalsdk is set; options are:
1497+
("universal2", "intel-64", "intel-32", "intel",
1498+
"32-bit", "64-bit", "3-way", or "all") see
1499+
Mac/README.rst
14961500
--with-framework-name=FRAMEWORK
14971501
specify an alternate name of the framework built
14981502
with --enable-framework
@@ -3073,6 +3077,7 @@ then
30733077
fi
30743078

30753079

3080+
30763081
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-universal-archs" >&5
30773082
$as_echo_n "checking for --with-universal-archs... " >&6; }
30783083

@@ -7373,6 +7378,7 @@ $as_echo_n "checking which compiler should be used... " >&6; }
73737378
$as_echo "$CC" >&6; }
73747379
fi
73757380

7381+
LIPO_INTEL64_FLAGS=""
73767382
if test "${enable_universalsdk}"
73777383
then
73787384
case "$UNIVERSAL_ARCHS" in
@@ -7394,8 +7400,9 @@ $as_echo "$CC" >&6; }
73947400
universal2)
73957401
UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
73967402
LIPO_32BIT_FLAGS=""
7403+
LIPO_INTEL64_FLAGS="-extract x86_64"
73977404
ARCH_RUN_32BIT="true"
7398-
;;
7405+
;;
73997406
intel)
74007407
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
74017408
LIPO_32BIT_FLAGS="-extract i386"

configure.ac

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,15 @@ then
217217
fi
218218

219219
AC_SUBST(LIPO_32BIT_FLAGS)
220+
AC_SUBST(LIPO_INTEL64_FLAGS)
220221
AC_MSG_CHECKING(for --with-universal-archs)
221222
AC_ARG_WITH(universal-archs,
222-
AS_HELP_STRING([--with-universal-archs=ARCH], [select architectures for universal build ("32-bit", "64-bit", "3-way", "intel", "intel-32", "intel-64", "universal2", or "all")]),
223+
AS_HELP_STRING([--with-universal-archs=ARCH],
224+
[specify the kind of macOS universal binary that should be created.
225+
This option is only valid when --enable-universalsdk is set; options are:
226+
("universal2", "intel-64", "intel-32", "intel", "32-bit",
227+
"64-bit", "3-way", or "all")
228+
see Mac/README.rst]),
223229
[
224230
UNIVERSAL_ARCHS="$withval"
225231
],
@@ -1832,6 +1838,7 @@ yes)
18321838
AC_MSG_RESULT($CC)
18331839
fi
18341840

1841+
LIPO_INTEL64_FLAGS=""
18351842
if test "${enable_universalsdk}"
18361843
then
18371844
case "$UNIVERSAL_ARCHS" in
@@ -1853,8 +1860,9 @@ yes)
18531860
universal2)
18541861
UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
18551862
LIPO_32BIT_FLAGS=""
1863+
LIPO_INTEL64_FLAGS="-extract x86_64"
18561864
ARCH_RUN_32BIT="true"
1857-
;;
1865+
;;
18581866
intel)
18591867
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
18601868
LIPO_32BIT_FLAGS="-extract i386"

0 commit comments

Comments
 (0)