Skip to content

Commit 5f86fdf

Browse files
authored
Enable building Mac universal2 wheels for Python 3.7 (#18)
1 parent a6b7c49 commit 5f86fdf

File tree

4 files changed

+189
-11
lines changed

4 files changed

+189
-11
lines changed

.github/workflows/ci-build-release-wheels.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
fail-fast: false
102102
matrix:
103103
py:
104-
- {version: '3.7', version_long: '3.7.14'}
104+
- {version: '3.7', version_long: '3.7.15'}
105105
- {version: '3.8', version_long: '3.8.13'}
106106
- {version: '3.9', version_long: '3.9.14'}
107107
- {version: '3.10', version_long: '3.10.7'}

pkg/mac/build-dependencies.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,12 @@ if [ ! -f Python-${PYTHON_VERSION_LONG}/.done ]; then
7070

7171
pushd Python-${PYTHON_VERSION_LONG}
7272
if [ $PYTHON_VERSION = '3.7' ]; then
73-
UNIVERSAL_ARCHS='intel-64'
74-
PY_CFLAGS=" -arch x86_64"
75-
else
76-
UNIVERSAL_ARCHS='universal2'
73+
patch -p1 < ${ROOT_DIR}/pkg/mac/python-3.7.patch
7774
fi
7875

7976
CFLAGS="-fPIC -O3 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -I${PREFIX}/include ${PY_CFLAGS}" \
8077
LDFLAGS=" ${PY_CFLAGS} -L${PREFIX}/lib" \
81-
./configure --prefix=$PREFIX --enable-shared --enable-universalsdk --with-universal-archs=${UNIVERSAL_ARCHS}
78+
./configure --prefix=$PREFIX --enable-shared --enable-universalsdk --with-universal-archs=universal2
8279
make -j16
8380
make install
8481

pkg/mac/build-mac-wheels.sh

+1-5
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ PIP_EXE=$PREFIX/bin/pip3
4949

5050
ARCHS='arm64;x86_64'
5151
PIP_TAG='universal2'
52-
if [ $PYTHON_VERSION = '3.7' ]; then
53-
ARCHS='x86_64'
54-
PIP_TAG=$ARCHS
55-
fi
5652

5753
cmake . \
5854
-DCMAKE_OSX_ARCHITECTURES=${ARCHS} \
@@ -67,7 +63,7 @@ cmake . \
6763
-DBOOST_ROOT=${PREFIX}
6864

6965
make clean
70-
make -j16 VERBOSE=1
66+
make -j16
7167

7268
$PY_EXE setup.py bdist_wheel
7369

pkg/mac/python-3.7.patch

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
diff -r -u Python-3.7.15.orig/Lib/_osx_support.py Python-3.7.15/Lib/_osx_support.py
2+
--- Python-3.7.15.orig/Lib/_osx_support.py 2022-10-10 05:34:53.000000000 -0700
3+
+++ Python-3.7.15/Lib/_osx_support.py 2022-10-14 08:10:34.000000000 -0700
4+
@@ -491,6 +491,8 @@
5+
machine = 'fat64'
6+
elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'):
7+
machine = 'universal'
8+
+ elif archs == ('arm64', 'x86_64'):
9+
+ machine = 'universal2'
10+
else:
11+
raise ValueError(
12+
"Don't know machine value for archs=%r" % (archs,))
13+
diff -r -u Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/ffi.h Python-3.7.15/Modules/_ctypes/libffi_osx/include/ffi.h
14+
--- Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/ffi.h 2022-10-10 05:34:53.000000000 -0700
15+
+++ Python-3.7.15/Modules/_ctypes/libffi_osx/include/ffi.h 2022-10-14 08:54:33.000000000 -0700
16+
@@ -62,7 +62,8 @@
17+
# elif defined(__ppc__) || defined(__ppc64__)
18+
# define POWERPC_DARWIN
19+
# else
20+
-# error "Unsupported MacOS X CPU type"
21+
+/* Temp fix to allow for universal2 to build through */
22+
+# define X86_DARWIN
23+
# endif
24+
#else
25+
#error "Unsupported OS type"
26+
@@ -199,9 +200,9 @@
27+
28+
void
29+
ffi_raw_call(
30+
-/*@dependent@*/ ffi_cif* cif,
31+
- void (*fn)(void),
32+
-/*@out@*/ void* rvalue,
33+
+/*@dependent@*/ ffi_cif* cif,
34+
+ void (*fn)(void),
35+
+/*@out@*/ void* rvalue,
36+
/*@dependent@*/ ffi_raw* avalue);
37+
38+
void
39+
@@ -225,9 +226,9 @@
40+
longs and doubles are followed by an empty 64-bit word. */
41+
void
42+
ffi_java_raw_call(
43+
-/*@dependent@*/ ffi_cif* cif,
44+
- void (*fn)(void),
45+
-/*@out@*/ void* rvalue,
46+
+/*@dependent@*/ ffi_cif* cif,
47+
+ void (*fn)(void),
48+
+/*@out@*/ void* rvalue,
49+
/*@dependent@*/ ffi_raw* avalue);
50+
51+
void
52+
@@ -272,8 +273,8 @@
53+
ffi_cif* cif;
54+
55+
#if !FFI_NATIVE_RAW_API
56+
- /* if this is enabled, then a raw closure has the same layout
57+
- as a regular closure. We use this to install an intermediate
58+
+ /* if this is enabled, then a raw closure has the same layout
59+
+ as a regular closure. We use this to install an intermediate
60+
handler to do the transaltion, void** -> ffi_raw*. */
61+
void (*translate_args)(ffi_cif*,void*,void**,void*);
62+
void* this_closure;
63+
@@ -303,17 +304,17 @@
64+
65+
ffi_status
66+
ffi_prep_cif(
67+
-/*@out@*/ /*@partial@*/ ffi_cif* cif,
68+
+/*@out@*/ /*@partial@*/ ffi_cif* cif,
69+
ffi_abi abi,
70+
- unsigned int nargs,
71+
-/*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type* rtype,
72+
+ unsigned int nargs,
73+
+/*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type* rtype,
74+
/*@dependent@*/ ffi_type** atypes);
75+
76+
void
77+
ffi_call(
78+
-/*@dependent@*/ ffi_cif* cif,
79+
- void (*fn)(void),
80+
-/*@out@*/ void* rvalue,
81+
+/*@dependent@*/ ffi_cif* cif,
82+
+ void (*fn)(void),
83+
+/*@out@*/ void* rvalue,
84+
/*@dependent@*/ void** avalue);
85+
86+
/* Useful for eliminating compiler warnings */
87+
diff -r -u Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/fficonfig.h Python-3.7.15/Modules/_ctypes/libffi_osx/include/fficonfig.h
88+
--- Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/fficonfig.h 2022-10-10 05:34:53.000000000 -0700
89+
+++ Python-3.7.15/Modules/_ctypes/libffi_osx/include/fficonfig.h 2022-10-14 13:19:13.000000000 -0700
90+
@@ -1,4 +1,4 @@
91+
-/* Manually created fficonfig.h for Darwin on PowerPC or Intel
92+
+/* Manually created fficonfig.h for Darwin on PowerPC or Intel
93+
94+
This file is manually generated to do away with the need for autoconf and
95+
therefore make it easier to cross-compile and build fat binaries.
96+
@@ -18,7 +18,7 @@
97+
# define HAVE_LONG_DOUBLE 1
98+
# define SIZEOF_LONG_DOUBLE 16
99+
100+
-#elif defined(__x86_64__)
101+
+#elif defined(__x86_64__) || defined(__arm64__)
102+
# define BYTEORDER 1234
103+
# undef HOST_WORDS_BIG_ENDIAN
104+
# undef WORDS_BIGENDIAN
105+
@@ -33,10 +33,10 @@
106+
# define SIZEOF_DOUBLE 8
107+
# if __GNUC__ >= 4
108+
# define HAVE_LONG_DOUBLE 1
109+
-# define SIZEOF_LONG_DOUBLE 16
110+
+# define SIZEOF_LONG_DOUBLE 16
111+
# else
112+
# undef HAVE_LONG_DOUBLE
113+
-# define SIZEOF_LONG_DOUBLE 8
114+
+# define SIZEOF_LONG_DOUBLE 8
115+
# endif
116+
117+
#elif defined(__ppc64__)
118+
@@ -147,4 +147,4 @@
119+
# else
120+
# define FFI_HIDDEN
121+
# endif
122+
-#endif
123+
\ No newline at end of file
124+
+#endif
125+
diff -r -u Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/ffitarget.h Python-3.7.15/Modules/_ctypes/libffi_osx/include/ffitarget.h
126+
--- Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/ffitarget.h 2022-10-10 05:34:53.000000000 -0700
127+
+++ Python-3.7.15/Modules/_ctypes/libffi_osx/include/ffitarget.h 2022-10-14 09:35:48.000000000 -0700
128+
@@ -4,10 +4,10 @@
129+
make building fat binaries harder.
130+
*/
131+
132+
-#if defined(__i386__) || defined(__x86_64__)
133+
+#if defined(__i386__) || defined(__x86_64__) || defined(__arm64__)
134+
#include "x86-ffitarget.h"
135+
#elif defined(__ppc__) || defined(__ppc64__)
136+
#include "ppc-ffitarget.h"
137+
#else
138+
#error "Unsupported CPU type"
139+
-#endif
140+
\ No newline at end of file
141+
+#endif
142+
diff -r -u Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/x86-ffitarget.h Python-3.7.15/Modules/_ctypes/libffi_osx/include/x86-ffitarget.h
143+
--- Python-3.7.15.orig/Modules/_ctypes/libffi_osx/include/x86-ffitarget.h 2022-10-10 05:34:53.000000000 -0700
144+
+++ Python-3.7.15/Modules/_ctypes/libffi_osx/include/x86-ffitarget.h 2022-10-14 11:58:41.000000000 -0700
145+
@@ -33,7 +33,7 @@
146+
# define X86
147+
#endif
148+
149+
-#if defined(__x86_64__)
150+
+#if defined(__x86_64__) || defined(__arm64__)
151+
# ifndef X86_64
152+
# define X86_64
153+
# endif
154+
@@ -58,7 +58,7 @@
155+
#endif
156+
157+
/* ---- Intel x86 and AMD x86-64 - */
158+
-#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__))
159+
+#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__) || defined(__arm64__))
160+
FFI_SYSV,
161+
FFI_UNIX64, /* Unix variants all use the same ABI for x86-64 */
162+
# ifdef __i386__
163+
@@ -85,4 +85,4 @@
164+
# define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
165+
#endif
166+
167+
-#endif // #ifndef LIBFFI_TARGET_H
168+
\ No newline at end of file
169+
+#endif // #ifndef LIBFFI_TARGET_H
170+
Only in Python-3.7.15: config.log
171+
diff -r -u Python-3.7.15.orig/configure Python-3.7.15/configure
172+
--- Python-3.7.15.orig/configure 2022-10-10 05:34:53.000000000 -0700
173+
+++ Python-3.7.15/configure 2022-10-14 08:10:34.000000000 -0700
174+
@@ -7449,6 +7449,11 @@
175+
LIPO_32BIT_FLAGS="-extract ppc7400 -extract i386"
176+
ARCH_RUN_32BIT="/usr/bin/arch -i386 -ppc"
177+
;;
178+
+ universal2)
179+
+ UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
180+
+ LIPO_32BIT_FLAGS=""
181+
+ ARCH_RUN_32BIT=""
182+
+ ;;
183+
*)
184+
as_fn_error $? "proper usage is --with-universal-arch=32-bit|64-bit|all|intel|3-way" "$LINENO" 5
185+
;;

0 commit comments

Comments
 (0)