@@ -60,6 +60,78 @@ diff --git a/Modules/makesetup b/Modules/makesetup
60
60
*) DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
61
61
EOF
62
62
63
+ # The default build rule for the macOS dylib doesn't pick up libraries
64
+ # from modules / makesetup. So patch it accordingly.
65
+ if [ " ${PYTHON_MAJMIN_VERSION} " = " 3.7" ]; then
66
+ patch -p1 << "EOF "
67
+ diff --git a/Makefile.pre.in b/Makefile.pre.in
68
+ --- a/Makefile.pre.in
69
+ +++ b/Makefile.pre.in
70
+ @@ -643,7 +643,7 @@ libpython3.so: libpython$(LDVERSION).so
71
+ $(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^
72
+
73
+ libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)
74
+ - $(CC) -dynamiclib -Wl,-single_module $(PY_CORE_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
75
+ + $(CC) -dynamiclib -Wl,-single_module $(PY_CORE_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
76
+
77
+
78
+ libpython$(VERSION).sl: $(LIBRARY_OBJS)
79
+ EOF
80
+ else
81
+ patch -p1 << "EOF "
82
+ diff --git a/Makefile.pre.in b/Makefile.pre.in
83
+ --- a/Makefile.pre.in
84
+ +++ b/Makefile.pre.in
85
+ @@ -628,7 +628,7 @@ libpython3.so: libpython$(LDVERSION).so
86
+ $(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^
87
+
88
+ libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)
89
+ - $(CC) -dynamiclib -Wl,-single_module $(PY_CORE_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(DTRACE_OBJS) $(SHLIBS) $(LIBC) $(LIBM); \
90
+ + $(CC) -dynamiclib -Wl,-single_module $(PY_CORE_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(DTRACE_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM); \
91
+
92
+
93
+ libpython$(VERSION).sl: $(LIBRARY_OBJS)
94
+ EOF
95
+ fi
96
+
97
+ # Also on macOS, the `python` executable is linked against libraries defined by statically
98
+ # linked modules. But those libraries should only get linked into libpython, not the
99
+ # executable. This behavior is kinda suspect on all platforms, as it could be adding
100
+ # library dependencies that shouldn't need to be there.
101
+ if [ " ${PYBUILD_PLATFORM} " = " macos" ]; then
102
+ if [ " ${PYTHON_MAJMIN_VERSION} " = " 3.7" ]; then
103
+ patch -p1 << "EOF "
104
+ diff --git a/Makefile.pre.in b/Makefile.pre.in
105
+ --- a/Makefile.pre.in
106
+ +++ b/Makefile.pre.in
107
+ @@ -578,7 +578,7 @@ clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
108
+
109
+ # Build the interpreter
110
+ $(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
111
+ - $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
112
+ + $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(SYSLIBS) $(LDLAST)
113
+
114
+ platform: $(BUILDPYTHON) pybuilddir.txt
115
+ $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
116
+ EOF
117
+ else
118
+ patch -p1 << "EOF "
119
+ diff --git a/Makefile.pre.in b/Makefile.pre.in
120
+ --- a/Makefile.pre.in
121
+ +++ b/Makefile.pre.in
122
+ @@ -563,7 +563,7 @@ clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
123
+
124
+ # Build the interpreter
125
+ $(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
126
+ - $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS)
127
+ + $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(SYSLIBS)
128
+
129
+ platform: $(BUILDPYTHON) pybuilddir.txt
130
+ $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
131
+ EOF
132
+ fi
133
+ fi
134
+
63
135
# Code that runs at ctypes module import time does not work with
64
136
# non-dynamic binaries. Patch Python to work around this.
65
137
# See https://bugs.python.org/issue37060.
152
224
CPPFLAGS=$CFLAGS
153
225
LDFLAGS=" -L${TOOLS_PATH} /deps/lib"
154
226
227
+ CONFIGURE_FLAGS=" --prefix=/install --with-openssl=${TOOLS_PATH} /deps --without-ensurepip"
228
+
155
229
if [ " ${CC} " = " musl-clang" ]; then
156
230
CFLAGS=" ${CFLAGS} -static"
157
231
CPPFLAGS=" ${CPPFLAGS} -static"
158
232
LDFLAGS=" ${LDFLAGS} -static"
233
+ PYBUILD_SHARED=0
234
+ else
235
+ CONFIGURE_FLAGS=" ${CONFIGURE_FLAGS} --enable-shared"
236
+ PYBUILD_SHARED=1
159
237
fi
160
238
161
- CONFIGURE_FLAGS=" --prefix=/install --with-openssl=${TOOLS_PATH} /deps --without-ensurepip"
162
-
163
239
if [ -n " ${CPYTHON_DEBUG} " ]; then
164
240
CONFIGURE_FLAGS=" ${CONFIGURE_FLAGS} --with-pydebug"
165
241
fi
@@ -188,6 +264,51 @@ cat ../Makefile.extra >> Makefile
188
264
make -j ${NUM_CPUS}
189
265
make -j ${NUM_CPUS} install DESTDIR=${ROOT} /out/python
190
266
267
+ if [ " ${PYTHON_MAJMIN_VERSION} " = " 3.7" ]; then
268
+ PYTHON_BINARY_SUFFIX=m
269
+ else
270
+ PYTHON_BINARY_SUFFIX=
271
+ fi
272
+
273
+ # If we're building a shared library hack some binaries so rpath is set.
274
+ # This ensures we can run the binary in any location without
275
+ # LD_LIBRARY_PATH pointing to the directory containing libpython.
276
+ if [ " ${PYBUILD_SHARED} " = " 1" ]; then
277
+ if [ " ${PYBUILD_PLATFORM} " = " macos" ]; then
278
+ # There's only 1 dylib produced on macOS and it has the binary suffix.
279
+ install_name_tool \
280
+ -change /install/lib/libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .dylib @executable_path/../lib/libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .dylib \
281
+ ${ROOT} /out/python/install/bin/python${PYTHON_MAJMIN_VERSION}
282
+
283
+ # Python 3.7's build system doesn't make this file writable.
284
+ chmod 755 ${ROOT} /out/python/install/lib/libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .dylib
285
+ install_name_tool \
286
+ -change /install/lib/libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .dylib @executable_path/libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .dylib \
287
+ ${ROOT} /out/python/install/lib/libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .dylib
288
+
289
+ # We also normalize /tools/deps/lib/libz.1.dylib to the system location.
290
+ install_name_tool \
291
+ -change /tools/deps/lib/libz.1.dylib /usr/lib/libz.1.dylib \
292
+ ${ROOT} /out/python/install/bin/python${PYTHON_MAJMIN_VERSION}
293
+ install_name_tool \
294
+ -change /tools/deps/lib/libz.1.dylib /usr/lib/libz.1.dylib \
295
+ ${ROOT} /out/python/install/lib/libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .dylib
296
+
297
+ if [ -n " ${PYTHON_BINARY_SUFFIX} " ]; then
298
+ install_name_tool \
299
+ -change /install/lib/libpython${PYTHON_MAJMIN_VERSION} .dylib @executable_path/../lib/libpython${PYTHON_MAJMIN_VERSION} .dylib \
300
+ ${ROOT} /out/python/install/bin/python${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX}
301
+ fi
302
+ else
303
+ patchelf --set-rpath ' $ORIGIN/../lib' ${ROOT} /out/python/install/bin/python${PYTHON_MAJMIN_VERSION}
304
+ patchelf --set-rpath ' $ORIGIN/../lib' ${ROOT} /out/python/install/lib/libpython3.so
305
+
306
+ if [ -n " ${PYTHON_BINARY_SUFFIX} " ]; then
307
+ patchelf --set-rpath ' $ORIGIN/../lib' ${ROOT} /out/python/install/bin/python${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX}
308
+ fi
309
+ fi
310
+ fi
311
+
191
312
# Install pip so we can patch it to work with non-dynamic executables
192
313
# and work around https://github.com/pypa/pip/issues/6543. But pip's bundled
193
314
# setuptools has the same bug! So we need to install a patched version.
316
437
# Symlink libpython so we don't have 2 copies. We only need to do
317
438
# this on Python 3.7, as 3.8 dropped the m ABI suffix from binary names.
318
439
319
- if [ " ${PYTHON_MAJMIN_VERSION} " = " 3.7 " ]; then
440
+ if [ -n " ${PYTHON_BINARY_SUFFIX} " ]; then
320
441
if [ " ${PYBUILD_PLATFORM} " = " macos" ]; then
321
442
PYTHON_ARCH=" darwin"
322
443
else
323
444
PYTHON_ARCH=" x86_64-linux-gnu"
324
445
fi
325
446
326
- LIBPYTHON=libpython${PYTHON_MAJMIN_VERSION} m .a
447
+ LIBPYTHON=libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} .a
327
448
ln -sf \
328
- python${PYTHON_MAJMIN_VERSION} /config-${PYTHON_MAJMIN_VERSION} m -${PYTHON_ARCH} /${LIBPYTHON} \
449
+ python${PYTHON_MAJMIN_VERSION} /config-${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} -${PYTHON_ARCH} /${LIBPYTHON} \
329
450
${ROOT} /out/python/install/lib/${LIBPYTHON}
330
451
331
452
# Ditto for Python executable.
332
453
ln -sf \
333
- python${PYTHON_MAJMIN_VERSION} m \
454
+ python${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX} \
334
455
${ROOT} /out/python/install/bin/python${PYTHON_MAJMIN_VERSION}
335
456
fi
336
457
0 commit comments