diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2021-11-11 21:33:54 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2021-12-10 14:26:06 +0100 |
commit | 217f4120cac06efed8c29e69b98127b7cb7887ae (patch) | |
tree | f6496f4c83e339ce35f7de460df19ce0ad50f1af | |
parent | 4d4d2bc444e858741a7d3f753e01cd0ae37425b7 (diff) | |
download | psycopg2-217f4120cac06efed8c29e69b98127b7cb7887ae.tar.gz |
Strip debug symbols from binary packages
The _psycopg.so library goes down from 1.6mb to 300k in Linux packages.
-rwxr-xr-x | scripts/build/build_manylinux2014.sh | 1 | ||||
-rwxr-xr-x | scripts/build/build_manylinux_2_24.sh | 1 | ||||
-rwxr-xr-x | scripts/build/strip_wheel.sh | 41 |
3 files changed, 43 insertions, 0 deletions
diff --git a/scripts/build/build_manylinux2014.sh b/scripts/build/build_manylinux2014.sh index 0e87bd5..ba32e47 100755 --- a/scripts/build/build_manylinux2014.sh +++ b/scripts/build/build_manylinux2014.sh @@ -41,6 +41,7 @@ done # Bundle external shared libraries into the wheels for whl in "${prjdir}"/dist/*.whl; do + "${dir}/strip_wheel.sh" "$whl" auditwheel repair "$whl" -w "$distdir" done diff --git a/scripts/build/build_manylinux_2_24.sh b/scripts/build/build_manylinux_2_24.sh index 6a9e992..742014a 100755 --- a/scripts/build/build_manylinux_2_24.sh +++ b/scripts/build/build_manylinux_2_24.sh @@ -41,6 +41,7 @@ done # Bundle external shared libraries into the wheels for whl in "${prjdir}"/dist/*.whl; do + "${dir}/strip_wheel.sh" "$whl" auditwheel repair "$whl" -w "$distdir" done diff --git a/scripts/build/strip_wheel.sh b/scripts/build/strip_wheel.sh new file mode 100755 index 0000000..0747f8c --- /dev/null +++ b/scripts/build/strip_wheel.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Strip symbols inplace from the libraries in a zip archive. +# +# Stripping symbols is beneficial (reduction of 30% of the final package, > +# %90% of the installed libraries. However just running `auditwheel repair +# --strip` breaks some of the libraries included from the system, which fail at +# import with errors such as "ELF load command address/offset not properly +# aligned". +# +# System libraries are already pretty stripped. _psycopg2.so goes around +# 1.6M -> 300K (python 3.8, x86_64) +# +# This script is designed to run on a wheel archive before auditwheel. + +set -euo pipefail +set -x + +wheel=$(realpath "$1") +shift + +# python or python3? +if which python > /dev/null; then + py=python +else + py=python3 +fi + +tmpdir=$(mktemp -d) +trap "rm -r ${tmpdir}" EXIT + +cd "${tmpdir}" +$py -m zipfile -e "${wheel}" . + +find . -name *.so -ls -exec strip "$@" {} \; +# Display the size after strip +find . -name *.so -ls + +$py -m zipfile -c "${wheel}" * + +cd - |