Skip to content

Commit 4cf9375

Browse files
authored
A more principled approach to SOs for python (#104)
Grab _all_ dependent SOs, not just the OpenSSL ones. Helps with finding ctypes, see compiler-explorer/infra#1530 and compiler-explorer/compiler-explorer#7405.
1 parent c451985 commit 4cf9375

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

python/build.sh

+11-9
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,20 @@ make -j$(nproc)
4949
make install
5050
popd
5151

52-
# copy SSL SOs to the same directory as the native python modules
53-
cp ${SSL_PREFIX}/lib64/*.so* /root/python/lib/python*/lib-dynload/
52+
# delete tests and static libraries to save disk space
53+
find ${DEST} -type d -name test -exec rm -rf {} +
54+
find ${DEST} -type f -name '*.a' -delete
55+
56+
PYTHON_SO_DIR=${DEST}/lib/python*/lib-dynload
57+
58+
# copy SSL and any other system dependencies like libffi etc
59+
DEPS=$(env LD_LIBRARY_PATH=${SSL_PREFIX}/lib64 ldd ${PYTHON_SO_DIR}/*.so | grep ' => /' | grep -Ev 'lib(pthread|c|dl|rt)\.so' | awk '{ print $3 }' | sort | uniq)
60+
cp ${DEPS} ${PYTHON_SO_DIR}/
5461

55-
# then patch the ssl and hashlib to look at $ORIGIN to find the crypto libs
56-
patchelf --set-rpath \$ORIGIN /root/python/lib/python*/lib-dynload/_ssl*.so
57-
patchelf --set-rpath \$ORIGIN /root/python/lib/python*/lib-dynload/_hashlib*.so
62+
# Patch all the SOs to look in their own directory.
63+
patchelf --set-rpath \$ORIGIN ${PYTHON_SO_DIR}/*.so
5864

5965
# strip executables
6066
find ${DEST} -type f -perm /u+x -exec strip -d {} \;
6167

62-
# delete tests and static libraries to save disk space
63-
find ${DEST} -type d -name test -exec rm -rf {} +
64-
find ${DEST} -type f -name '*.a' -delete
65-
6668
complete "${DEST}" "${FULLNAME}" "${OUTPUT}"

0 commit comments

Comments
 (0)