Skip to content

Commit d7c77f8

Browse files
committed
Strip debug symbols from binary packages
The _psycopg.so library goes down from 1.6mb to 300k in Linux packages.
1 parent 8ef195f commit d7c77f8

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

scripts/build/build_manylinux2014.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ done
4141

4242
# Bundle external shared libraries into the wheels
4343
for whl in "${prjdir}"/dist/*.whl; do
44+
"${dir}/strip_wheel.sh" "$whl"
4445
auditwheel repair "$whl" -w "$distdir"
4546
done
4647

scripts/build/build_manylinux_2_24.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ done
4141

4242
# Bundle external shared libraries into the wheels
4343
for whl in "${prjdir}"/dist/*.whl; do
44+
"${dir}/strip_wheel.sh" "$whl"
4445
auditwheel repair "$whl" -w "$distdir"
4546
done
4647

scripts/build/strip_wheel.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Strip symbols inplace from the libraries in a zip archive.
4+
#
5+
# Stripping symbols is beneficial (reduction of 30% of the final package, >
6+
# %90% of the installed libraries. However just running `auditwheel repair
7+
# --strip` breaks some of the libraries included from the system, which fail at
8+
# import with errors such as "ELF load command address/offset not properly
9+
# aligned".
10+
#
11+
# System libraries are already pretty stripped. _psycopg2.so goes around
12+
# 1.6M -> 300K (python 3.8, x86_64)
13+
#
14+
# This script is designed to run on a wheel archive before auditwheel.
15+
16+
set -euo pipefail
17+
set -x
18+
19+
wheel=$(realpath "$1")
20+
shift
21+
22+
# python or python3?
23+
if which python > /dev/null; then
24+
py=python
25+
else
26+
py=python3
27+
fi
28+
29+
tmpdir=$(mktemp -d)
30+
trap "rm -r ${tmpdir}" EXIT
31+
32+
cd "${tmpdir}"
33+
$py -m zipfile -e "${wheel}" .
34+
35+
find . -name *.so -ls -exec strip "$@" {} \;
36+
# Display the size after strip
37+
find . -name *.so -ls
38+
39+
$py -m zipfile -c "${wheel}" *
40+
41+
cd -

0 commit comments

Comments
 (0)