Skip to content

Commit 0cb33da

Browse files
authored
bpo-44009: Provide "python3.x-intel64" for Apple Silicon Macs (pythonGH-25804)
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.
1 parent 91554e4 commit 0cb33da

File tree

6 files changed

+62
-9
lines changed

6 files changed

+62
-9
lines changed

Mac/Makefile.in

+21
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

+6
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

+13
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ STRIPFLAG=-s
189189
# Flags to lipo to produce a 32-bit-only universal executable
190190
LIPO_32BIT_FLAGS=@LIPO_32BIT_FLAGS@
191191

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

@@ -1344,6 +1347,12 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
13441347
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-32$(EXE) \
13451348
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
13461349
fi
1350+
if test "x$(LIPO_INTEL64_FLAGS)" != "x" ; then \
1351+
rm -f $(DESTDIR)$(BINDIR)python$(VERSION)-intel64$(EXE); \
1352+
lipo $(LIPO_INTEL64_FLAGS) \
1353+
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-intel64$(EXE) \
1354+
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
1355+
fi
13471356

13481357
bininstall: altbininstall
13491358
if test ! -d $(DESTDIR)$(LIBPC); then \
@@ -1379,6 +1388,10 @@ bininstall: altbininstall
13791388
rm -f $(DESTDIR)$(BINDIR)/python3-32$(EXE); \
13801389
(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-32$(EXE) python3-32$(EXE)) \
13811390
fi
1391+
if test "x$(LIPO_INTEL64_FLAGS)" != "x" ; then \
1392+
rm -f $(DESTDIR)$(BINDIR)/python3-intel64$(EXE); \
1393+
(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-intel64$(EXE) python3-intel64$(EXE)) \
1394+
fi
13821395

13831396
# Install the versioned manual page
13841397
altmaninstall:
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

+10-5
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ PYTHONFRAMEWORKPREFIX
752752
PYTHONFRAMEWORKDIR
753753
PYTHONFRAMEWORKIDENTIFIER
754754
PYTHONFRAMEWORK
755+
LIPO_INTEL64_FLAGS
755756
LIPO_32BIT_FLAGS
756757
ARCH_RUN_32BIT
757758
UNIVERSALSDK
@@ -1519,11 +1520,12 @@ Optional Packages:
15191520
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
15201521
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
15211522
--with-universal-archs=ARCH
1522-
specify the kind of universal binary that should be
1523-
created. this option is only valid when
1523+
specify the kind of macOS universal binary that
1524+
should be created. This option is only valid when
15241525
--enable-universalsdk is set; options are:
1525-
("universal2", "32-bit", "64-bit", "3-way", "intel",
1526-
"intel-32", "intel-64", or "all") see Mac/README.rst
1526+
("universal2", "intel-64", "intel-32", "intel",
1527+
"32-bit", "64-bit", "3-way", or "all") see
1528+
Mac/README.rst
15271529
--with-framework-name=FRAMEWORK
15281530
specify the name for the python framework on macOS
15291531
only valid when --enable-framework is set. see
@@ -3139,6 +3141,7 @@ then
31393141
fi
31403142

31413143

3144+
31423145
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-universal-archs" >&5
31433146
$as_echo_n "checking for --with-universal-archs... " >&6; }
31443147

@@ -7522,6 +7525,7 @@ $as_echo_n "checking which compiler should be used... " >&6; }
75227525
$as_echo "$CC" >&6; }
75237526
fi
75247527

7528+
LIPO_INTEL64_FLAGS=""
75257529
if test "${enable_universalsdk}"
75267530
then
75277531
case "$UNIVERSAL_ARCHS" in
@@ -7543,8 +7547,9 @@ $as_echo "$CC" >&6; }
75437547
universal2)
75447548
UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
75457549
LIPO_32BIT_FLAGS=""
7550+
LIPO_INTEL64_FLAGS="-extract x86_64"
75467551
ARCH_RUN_32BIT="true"
7547-
;;
7552+
;;
75487553
intel)
75497554
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
75507555
LIPO_32BIT_FLAGS="-extract i386"

configure.ac

+8-4
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"
@@ -1874,6 +1876,7 @@ yes)
18741876
AC_MSG_RESULT($CC)
18751877
fi
18761878

1879+
LIPO_INTEL64_FLAGS=""
18771880
if test "${enable_universalsdk}"
18781881
then
18791882
case "$UNIVERSAL_ARCHS" in
@@ -1895,8 +1898,9 @@ yes)
18951898
universal2)
18961899
UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
18971900
LIPO_32BIT_FLAGS=""
1901+
LIPO_INTEL64_FLAGS="-extract x86_64"
18981902
ARCH_RUN_32BIT="true"
1899-
;;
1903+
;;
19001904
intel)
19011905
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
19021906
LIPO_32BIT_FLAGS="-extract i386"

0 commit comments

Comments
 (0)